I spent Thanksgiving weekend playing with Mathematica on my Raspberry Pi. There’s some examples in this forum on writing to the GPIO interface and I wanted to explore reading pins. I couldn’t get the same read/write rates as others have, but I did get a proof-of-concept interface using Manipulate to control an LED turning on/off and watching the response of a photoresistor pointed at the LED. Details are in my latest blog post and below is the end result
pinHi and pinLo in the Manipulate used to create the output are calls to c-functions that I wrote, integrating MathLink. LightMeasure[] is simply a wrapper to read the photoresistor response and is based on the analogous python code.
You should be able to get a little bit better switching performance by using BinaryWrite directly (using 49 for “1” and 48 for “0”).
I get about 3.7kHz:
pi@raspberry-wri2 ~ $ sudo wolfram
Wolfram Language (Raspberry Pi Pilot Release)
Copyright 1988-2013 Wolfram Research
Information & help: wolfram.com/raspi
In[1]:= stream = OpenWrite["/sys/class/gpio/gpio4/value", BinaryFormat-> True];
In[2]:= Do[ BinaryWrite[stream,49]; BinaryWrite[stream,48], {1000} ] // AbsoluteTiming // First
Out[2]= 0.276416
In[3]:= 1000/%
Out[3]= 3617.7
In[4]:= Do[ BinaryWrite[stream,49]; BinaryWrite[stream,48], {1000} ] // AbsoluteTiming // First
Out[4]= 0.269015
In[5]:= 1000/%
Out[5]= 3717.3