Page tree
Skip to end of metadata
Go to start of metadata

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

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.

Arduino
#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.

Odysseus Query
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.

  • No labels

6 Comments

  1. Anonymous

    Hi, I hope someone could help me with my problem.

     

    I tried to write a program for arduino to get data into the computer.

     

    this is what i wrote / copied (wink)

    ///source

    #PARSER CQL

    #TRANSCFG Standard

    #QUERY

    CREATE STREAM source (windspd float, winddrctn integer)

        WRAPPER 'GenericPush'

        PROTOCOL 'CSV'

        TRANSPORT 'RS232'

        DATAHANDLER 'Tuple'

        OPTIONS ( 'port' '/dev/ttyACM2', 'baud' '9600') ///oder auch jedem anderen Port

     

     

     this Query i can run without any errors.

     

     

    ///query

    #PARSER CQL

    #TRANSCFG Standard

    #ADDQUERY

    SELECT * FROM source;

     

    Error:

    Script Execution Error

    de.uniol.inf.is.odysseus.core.server.planmanagement.optimization.exception.QueryOptimizationException: Exeception while initialize query.

    Additional info:

    Transformation Failed in rule Transform View (de.uniol.inf.is.odysseus.transform.rules.TAccessAOViewRule) - 8970561 Transformation Failed in rule AccessAO (generic) --> AccessPO (de.uniol.inf.is.odysseus.transform.rules.TAccessAOGenericRule) - 6099092 transformation failed ; No transport handler RS232 found.

     

    I also tried the folloing

     

    ///source

    #PARSER PQL

    #TRANSCFG Standard

    #QUERY

    arduino= ACCESS({source='arduino',

    wrapper='GenericPush',

    transport='RS232',

    protocol='CSV',

    dataHandler='Tuple',

    options=[['port', ‘/dev/ttyACM2'],['delimiter', ',']],

    schema=[['windspeed', 'float'],['winddirection', 'integer']]

    })

     

    I get the following error already while starting the script

    Script Execution Error

    Lexical error at line 6, column 19.  Encountered: "\u2018" (8216), after : ""

     

     

    Thanks for your Help

    Jonas Franz

    1. Looks like the Transport Handler for RS232 is missing. You can list all loaded bundles in the OSGi Console using "ss". Please check if the required bundle "de.uniol.inf.is.odysseus.wrapper.rs232" is installed.

    2. If you use Odysseus Studio (the GUI-Version) you may also check, if you have installed the "Wrapper Feature" that provides the RS232 adapter. Look here for further details: How to install new features

  2. Anonymous

    Hey, Thanks for the fast answer. I checked both. I installed the Wrapper feature and checked weather its installed and YES it is (wink). Do you have any other advice?

     

    Thanks in advance.

     

    Jonas Franz

    1. hmmm...

      first: your second query (the PQL-Version) has a wrong character at the beginning of ‘/dev/ttyACM2' --> this must be an apostrophe ' and not a single quotation mark ` or other single quotes...

      second: If the bundle is installed, you may check, if the bundle is running...
      use: "ss rs232" in the osgi-console and you should see one line where the bundle's state should be "ACTIVE". If the bundle is not started (e.g. in lazy-mode), you may start the bundle by hand using "start <id>" where you replace <id> with the id of the bundle that is shown by the "ss rs232" command before.

      1. I just saw that the rs232 adapter was set to lazy-loading, which invokes that the bundle is not certainly started (smile) so I hope, that's it. The new build at midnight will contain the fix and you can update your version!