Getting Sensor Data into Wolfram Alpha

As you may know, the Raspberry Pi comes with a free version of Wolfram Alpha. Wouldn’t it be great if you could work with sensor data within the Wolfram environment? Well, it couldn’t be simpler!

There is a handy way to call external commands in Wolfram Alpha using <<"! (For more information, check out the documentation here). From here, we can simply run the gpio command to query the sensors on the PiShield. For example,

<<"!gpio -x mcp3004:100:0 aread 100"

will call the first A2D channel.

and

<<"!gpio -x mcp3004:100:0 aread 101"

the second, and so forth… The last number, ranging from 100 to 107, will access the 8 ports on the PiShield.

 

Along the same vein, it would be possible to trigger the output pins as well. The following shows the setting and switching of the first header pin on the PiShield, which is indexed using wiringPi pin 2:

In[5]:= <<“!gpio mode 2 out”                                                    

In[6]:= <<“!gpio write 2 1”                                                     

In[7]:= <<“!gpio write 2 0” 

If you have an LED connected to that pin, issuing the above commands should turn it on and then off.

Leave a Reply