Group Abstract Group Abstract

Message Boards Message Boards

Recording a time series of simple GPIO sensor data

GROUPS:
For this experiment you will need a bread board, a resistor (I used 820 ohm) and two jumper wires.

First start the wolfram language and configure the GPIO device. In this we will use GPIO pin 17 and use it for input:
DeviceConfigure["GPIO", 17 -> "Input"]

Next, connect one wire (red in the picture) to the 3.3V output and the other (green in the picture) to GPIO pin 17.

Connect the wires and the resistor on the bread board as shown:



We can check if pin 17 is reading this configuration as "high":
DeviceRead["GPIO", 17]
This should return {17->1}. If you disconnect either the red or green cable the DeviceRead command will return {17->0}.

Now let's run the same command, but record all data for 10 seconds in 0.1 second intervals and return this data as a time series:
ts = DeviceReadTimeSeries["GPIO", {10, .1}, 17]
While this command is running plug and unplug a cable a few times to get both "high" and "low" sensor readings.

At the end you can examine the data by plotting the data points:
ts["ValueList"][[1, All, 1, 2]] // ListLinePlot

POSTED BY: Arnoud Buzing
Answer
6 months ago
Arnoud,

  I can't seem to get at the documentation atm.  How does DeviceReadTimeSeries handle sampling rate and ensuring that the desired sampling rate is maintained?  
POSTED BY: BoB LeSuer
Answer
6 months ago
Documentation is here:

http://reference.wolfram.com/language/ref/DeviceReadTimeSeries.html

The syntax allows for a total time and a sampling interval: { total_time, sampling_interval }

I don't know how it ensures a particular sampling rate (I'll check with the developer).
POSTED BY: Arnoud Buzing
Answer
6 months ago
Not sure if this is a problem on my end (quite possibly, as our university internet is a bit quirky) but the link hangs on a "long script" error in IE and hangs indefinitely in Chrome.  
POSTED BY: BoB LeSuer
Answer
6 months ago