First Full Embedded System Project - Distance, Daylight, Data Acquisition (D3A)
- karnveerg94
- Feb 3, 2019
- 4 min read
This project is my first real dive into the world of embedded systems engineering, and it has been one of the most enjoyable experience I've ever had with engineering. I enjoyed being forced to employ my knowledge of electronics and software to solve fun and challenging problems. I loved getting stuck and diving into a problems that taught me new skills as well as learning the value of the knowledge I've been able to gather throughout my college career.
To view my code please visit my github here: https://github.com/karnveergill/Distance_Daylight_Data_Acquisition
Objective/Introduction:
The goal of this project was to implement a real time system, that uses multiple interrupt routines, involves setting up a UART, uses multiple sensors for data acquisition, and displays the acquired data on a GUI. This is all implemented on a Tiva TM4C123G launchpad microcontroller.
To achieve the goals above I created the Daylight Distance Data acquisition system or the D3A. The D3A uses a ultrasonic distance sensor, a Bluetooth module, a photo resistor and LEDs. The D3A collects timing data from the ultrasonic sensor to gather distance and uses the photo-resistor along with the on board ADC to figure out whether it is daytime or not outside. Upon powering up the D3A you can connect it wirelessly to your laptop via Bluetooth and use a serial monitor to stop and start acquisition. The serial terminal we used was Tera Term and it would display either “Day” or “Night” and the distance of any object from the device, you could also send commands to change the units the distance we being displayed in between inches or centimeters.
Below you can see a software flow chart of the main() function and the interrupt service routines. As you can see I did not implement polling in main and instead used interrupts to perform all the task.


Below you can see an image of the full put together project. Inside the box we have the TI Launchpad connected to a portable battery pack, the ultrasonic sensor, the photo resistor which is taped into the lid of the box and the bluetooth module. Next to the D3A you can see data being displayed on the serial terminal of my laptop, this data is being received by the bluetooth on the computer.

Challenges:
I think the first real challenge I encountered was debugging the code I had written to operate the ultrasonic sensor. This process involved a lot of reading and understanding the data sheet, which was thankfully quite light, and really learning to look for the more useful bits of information in the document. This information consisted of the operating frequency of the sensor, the max distance, the general operation of the sensor and how we are suppose to generate useful information from the sensor. A big issue I encountered while programming the ultrasonic sensor was getting the correct timing for the 10 microsecond trigger that the sensor needed to start measuring. To get this signals timing perfect, it was an absolute must for me to have a scope and actually measure the trigger signal being generated, which can be seen in the image below as the blue signal and our distance pulse is the yellow signal.

Once the trigger was settled, it just became a matter of measuring the generated pulse width which could have been done using interrupts, however for simplicity I ended up polling the echo pin in my Timer0A interrupt service routine. This is only possible because of how fast the speed of sound is.
The next challenge I faced was setting up, programming, and understanding the UARTS. I think conceptually UARTs are not exceedingly difficult, however once I introduced communication mediums like Bluetooth and started setting up the receiving data interrupt handler I really started to encounter challenges. Setting up the receive data interrupt handler was how I where able to achieve the ability to send specific commands from the serial terminal on my computer through the computer Bluetooth to the projects Bluetooth and into the Tiva board. This process is something I would like to play with more in the future because while setting up the receive interrupt for the Bluetooth module I did not ever deal with using a while loop to buffer the data collection from the receive Fifo, however when communication between two boards in a earlier lab with wires I had to use a while loop checking for chars available on the Fifo in the RX (receiver) ISR (interrupt service routine) in order to obtain clean data. This took a lot of trial and error to realize and I still do not entirely understand why one method works for one set up and not the other.
If Time Machines Existed:
One thing I did not think of doing that would have been simple to implement was using the on board temperature sensor and displaying that data as well. Another sensor we would like to add is a moisture sensor to help detect whether it is humid, foggy, raining or any other state of moisture. Then by combining these three pieces of data I could have made a useful means of predicting what type of clothes you should wear outside. For example, if it is warm outside, but also high moisture, and sunny, then it is humid and sunny out so wear shorts, a t-shirt, and a hat for the sun. That would have been a very fun and achievable direction to take the project in.
In addition to adding the clothing functionality, I would also remove the Bluetooth link between the D3A and the computer. Although using the computer was a convenient way to visualize the data being gathered from the device, it was not practical. Instead, I should have a phone application that allows you to do all the same functions we had on the computer (unit changing, Data acquisition stop and start) as well as adding the ability to increase or decrease the rate at which we are receiving data and having the ability to set alerts. An alert could be set by telling the device to notify you about specific changes in the environment surrounding the device.
Comments