In this article, we will use Odysseus to process measurements from two light dependent resistors (LDR). To do so, we use the Arduino open-source electronics prototyping platform.
Requirements
- RS232 wrapper bundle
- Arduino IDE or dfu-programmer
- Arduino Board
- 2x Light dependent resistor
- 2x Resistor (10kΩ)
- Soldering iron and solder
- Wires
- USB Cable to connect the Arduino to your computer
The Hardware
For this example we will use an Arduino Mega 2560. To measure the voltage at the LDR we simple build a voltage divider as shown the following image.
Next, we solder all the parts together. We use three pins to connect the wires later. However, you can also just solder the wires on the parts.
After that, the three wires of both LDRs are connected to the Arduino (red: 5V, black: GND, and green on A0). In the image we used the ScrewShield to connect the wires.
When all wires are connected you can plugin the USB-cable and start writing the software for the Arduino.
The Software
To measure the voltage at the LDR we simple use the analogRead method with the pin id as parameter. The output is done by the Serial.println method that puts the readings on the serial connection as a CSV string.
Code Block | ||||||||
---|---|---|---|---|---|---|---|---|
| ||||||||
#include <stdio.h> const int analogInPin1 = A0; const int analogInPin2 = A1; int sensorValue1 = 0; int sensorValue2 = 0; void setup() { Serial.begin(9600); } void loop() { sensorValue1 = analogRead(analogInPin1); Serial.print(sensorValue1); Serial.print(","); Serial.println(sensorValue2); delay(500); } |
The Query
The query reads the sensor measurements from the serial connection on device ttyACM0. To do so, the Access operator uses the RS232 Transport Handler and the CSV Protocol Handler. Further, we set our stream schema to light1 as Double and light2 respectively.
Code Block | ||||||
---|---|---|---|---|---|---|
| ||||||
arduino= ACCESS({source='arduino', wrapper='GenericPush', transport='RS232', protocol='CSV', dataHandler='Tuple', options=[['port', '/dev/ttyACM0'],['delimiter', ',']], schema=[['light1', 'Double'],['light2', 'Double']] }) |
After writing down the query you can start it and open the operator graph to see the measurements in the List View.