I started exploring GPIO operations on the RPi with MathematicaMathematica by following this brief tutorial which describes how to use DeviceWrite
to cycle an LED on and off. A natural extension is to use DeviceRead
to find the current value of the pin, and this seems to work as well.
def RCtime (RCpin): reading = 0 GPIO.setup(RCpin, GPIO.OUT) GPIO.output(RCpin, GPIO.LOW) time.sleep(0.1) GPIO.setup(RCpin, GPIO.IN) # This takes about 1 millisecond per loop cycle while (GPIO.input(RCpin) == GPIO.LOW): reading += 1 return reading
def RCtime (RCpin):
reading = 0
GPIO.setup(RCpin, GPIO.OUT)
GPIO.output(RCpin, GPIO.LOW)
time.sleep(0.1)
GPIO.setup(RCpin, GPIO.IN)
# This takes about 1 millisecond per loop cycle
while (GPIO.input(RCpin) == GPIO.LOW):
reading += 1
return reading
lightMeasure[] := Module[{r = 0, pin = 23},
DeviceWrite["GPIO", pin -> 0];
While[(pin /. DeviceRead["GPIO", pin]) == 0, r++];
r
r
]
Looking at the python code, I think that the GPIO.setupGPIO.setup
/GPIO.outputGPIO.output
/time.sleeptime.sleep
commands force the pin low for 100 ms, allowing the capacitor to discharge. It does not look like the analogous MathematicaMathematica command, DeviceWrite
is able to do the same thing.