Message Boards Message Boards

Changing the GPIO value with DeviceWrite[] ?


Hello all. I have opened up the "GPIO" device on a Raspberry Pi 3 using DeviceOpen. I've been following the instructions in this guide's section 4 (GPIO), but with no luck. I am unable to change the values on the pins. Here is what I get:

In[1]: DeviceRead["GPIO", 27]

Out[1]: {27->0}

In[2]: DeviceWrite["GPIO", 27 -> 1]

Out[2]: {27->1}

In[3]: DeviceRead["GPIO", 27]

Out[3]: {27->0}

I have tried running the above both from a notebook and from the terminal (after typing sudo wolfram), but GPIO pin 27 just will not change value.

Not sure what to try next. Thanks in advance for any ideas!

POSTED BY: Jakub Kabala
1 year ago

Two possible problems here. First, you may be using the WiringPi numbering scheme and Mathematica expects the BCM number. Second, the documentation does not state that GPIO 27 is accessible (it was not available in the early Pi versions and I do not believe the driver has been updated).

A workaround is to avoid the Device* commands all together and to use RunProcess with the gpio utility, which is probably available on your RPi but can be found at Gordon's WiringPi website, for example:


Faster performance can be obtained by executing a shell and writing/reading to the stream. See the RunProcess documentation for further help on that approach.

1 year ago

Thank you, BoB. The RunProcess is very useful trick. This turned out to be a hardware problem, and I am up and running.

POSTED BY: Jakub Kabala
1 year ago

Group Abstract Group Abstract