Build a Smart Lamp Using an Analog Discovery Pro ADP3450 – Part 4

In this last installment of our four-part blog series about creating a smart lamp, we will bring everything together. The HAL for the WaveForms SDK we developed in the Part 1, the software functions for controlling our two Pmods, the Pmod BLE and the Pmod ALS, we wrote in Part 2, and the Android app we designed in the Part 3.

Now we are going to create the main script containing the application running on the Analog Discovery Pro ADP3450 from Digilent, working in Linux Mode. Once everything is complete, you will be able to adjust luminosity and color of the LED through your phone’s app.

Bringing the Software Together

As before, you can either write the application from scratch following the guidelines below, or you can download it from here.

First, import all the modules you created during the previous parts of this blog series. Then define the constants needed and develop some helper functions like one for decoding the incoming Bluetooth data. These functions make your life easier later on.

Once done, write the body of your program. For our solution, we used a “try-except structure”, but how you implement it is really up to you. Start with the initialization of the WaveForms instruments and the Pmods. Then move on and create an endless loop through a “while True” statement. Inside the loop, look for data packets received by the Pmod BLE and decode them. Query the ambient light brightness measured by the Pmod ALS as well. Eventually, you might want to read the voltage level of the battery and transmit it via Bluetooth to your smartphone.

At the end, you will need to provide code which allows you to exit your program gracefully. Define an event you want to react to, e.g., pressing “Ctrl+C”, and include statements that turn off the lamp, and close and reset the WaveForms instruments.

Putting the ADP3450 in Linux Mode

Before you can run your script, you will need to put the Analog Discovery Pro ADP3450 in Linux Mode. For this, follow the steps detailed in the guide “Getting Started in Linux Mode with the Analog Discovery Pro (ADP3450/ADP3250)”. When finished, follow the instructions in the guide “Connecting the Analog Discovery Pro (ADP3450/ADP3250) to the Internet”. This will allow you to install the Python package installer (pip) directly on the mixed signal oscilloscope (MSO) using the command below:

sudo apt install python3-pip

Next, copy the HAL files you created for the WaveForms instruments in Part 1 to your directory on the ADP3450. Before you can run the script, you have to execute the commands below from your terminal:

sudo su

cd /etc/systemd/system

echo -n “” > lamp.service

nano lamp.service

Now type the following text in your editor but change the path according to your setup. Then save the file.

[Unit]

Description=Smart Lamp Controller

[Service]

ExecStart=nohup python3 /home/digilent/Smart-Lamp-Controller/Python/Lamp_Controller.py &

[Install]

WantedBy=multi-user.target

And finally, enable the new service and reboot the MSO:

systemctl start lamp

systemctl enable lamp

reboot

Running the Script

Once the ADP3450 has booted, start the script and as well as the app you created on your smartphone. Wait until the phone detects the Pmod BLE, connect to it and start playing with your sliders and switches in your app.

If you want to make any changes to your script, you will need to stop it by pressing your key combination, make your changes, and restart it. Enjoy your smart lamp!

A more detailed description of this project is available here.

Be the 1st to vote.

Leave a Reply

Your email address will not be published.