Writing an Application in Order to Visualize and Measure Distance
I wanted to read a sensor. Unfortunately, my input device board was still broken. I couldn’t anymore initialize the ATtiny44 microcontroller. So, I could make a new board or repair the old one.
I designed a new board which I could use for this week’s assignment and as a new I²C bridge with a LED onboard. Designing and milling worked well. I got a shiny and nice PCB. A copper + and a – indicate microcontroller's VCC and GND, M indicates that this is a I²C master device. I was happy and looked forward to solder all components. Then I discovered that a trace was missing. I ran Eagle’s DRC (design rules check) before but this missing trace wasn’t indicated as an error. I didn't continue working on this new board. Instead, I repaired my old input device board. I replaced the ATtiny44 microcontroller, enhanced some traces with some more solder and checked all traces using a multimeter. My input device board came back to life.
In Input Devices, I didn’t use the HC-SR04 Ultrasonic Ranging Module as intended. I was able to read a phototransistor and use it together with a LED to measure proximity but I couldn’t work with a sonar. So, this week I wanted to read a sonar and measure distance.
First I had to write an Arduino script in order to read a sonar— a HC-SR04 Ultrasonic Ranging Module. I did some research on it. The relevant sources were:
- Juan Fernandez, Fab Academy 2014
- Simple Arduino and HC-SR04 Example, instructables.com
- Arduino and HC-SR04 ultrasonic sensor, trollmaker.com
- Hello Sonar (ultrasonido), Fab Academy 2015
I read the datasheet which helped me to understand the sonar. It says I would have to send a 10 uS (microseconds) long trigger signal and read the echo of it. The duration of the echo would give information about the distance. The incoming value would have to be divided by 58 in order to get cm. I successfully wrote a very simple and short script which outputs an object’s distance towards the sonar in cm.
I watched some Processing tutorials. The language is very similar to Arduino. I did some further research on how to read a serial port with Processing. Reading a serial port, I would get all data which I would like to visualize in an application. Based on Emma’s script, I created my first application.
Using my card board based pedestal press fit construction kit, I build a proper set up. A sonar needs a fix and clean installation to work well. By the way, I could hear the sonar’s sound.