# Remote sensing with the Raspberry Pi and Wolfram

I wanted to see if it would be possible to create a makeshift remote sensing device using Wolfram on the Raspberry Pi. Toss in VNC and some earlier code that I’ve written and here’s what I came up with.

It seems like the Internet of Things and remote sensing are all the rage right now, and there exists a healthy number of products to make web-based remote sensing devices. Since the new version of the Raspberry Pi makes it actually possible to use Mathematica’s GUI interface, I thought this would be an interesting little project to test how Mathematica could be used in a remote sensing IOT type environment.

## Sensor

First, the sensor is a simple photoresistor connected to an MCP3008. As is true with most of my projects, I rely heavily on the instructional pages at learning.adafruit.com . Additionally, I am using my wiringPiLink code, which is available at Github, to call the WiringPi functions from within Mathematica.

## The interface

Wolfram introduced gauges in version 10 of Mathematica, so I thought I’d start there with the interface. AngularGauge accepts a value and a range. Since the MCP3008 is a 10-bit ADC, the range is 0 to 1023. We can make the gauge dynamic by applying Dynamic to the value inside the AngularGauge function:

AngularGauge[Dynamic@goutput,{0,1023}]

Now, to update the gauge value goutput I use a scheduled task, which reads the value of the MCP3008 every 50 ms.

gtask = CreateScheduledTask[goutput = wiringPiAnalogRead[1],0.05];];
StartScheduledTask@gtask;

In the interface, I’ve attached these operations to buttons, but I’ll ignore that point in this post for the sake of simplicity.

Next, we have the source tab. There’s nothing overly special here. The on/off buttons turn the LED on and off (I have the LED connected to wiringPi pin 1) and the sliders set the parameters that can be sent to wiringPiFlicker to make a candle-light-like LED response.

I had to spend a little bit of time on the Collect tab in order to deal with some responsivity issues. Attempting to put a dynamic plot within a Manipulate resulted in some serious lag, so I created my own interface with a Slider and appropriate dynamic symbols. I also decided not to update the plot in “real time” since plot updating was too slow for my taste. It is nice to see that the ProgressBar feature works relatively smoothly. In a future version of this project I’d like to fix this bar so that it becomes greyed out if the user changes the slider. I also have some x-axis tick-mark overlap that needs tweaking.

The last part of the interface is the Analyze tab. This part of the interace is inspired by another project (currently on the back burner) dealing with simulation of candle light flicker. A histogram of the light intensities read by the sensor is plotted and these data are fit to a normal distribtuion. The p-value of the result is displayed along with a visualization of the result.

The various parts of the interface are tied together using TabView and CreatePalette.