Message Boards Message Boards

0
|
14348 Views
|
7 Replies
|
0 Total Likes
View groups...
Share
Share this post:

Anyone driven the GPIO pins of the Raspberry Pi B+ model

Posted 10 years ago

The documentation for DeviceWrite["GPIO" .. still seems exclusively for the 26 pin header of the B version. Has anyone successfully driven the pins of the new 40-pin B+ header from Wolfram?

POSTED BY: David Keith
7 Replies

I wasn't familiar with that library; will have to check it out.

POSTED BY: BoB LeSuer
Posted 10 years ago

Thanks, Bob. I'm having no trouble driving the pins and the SPI using the C library at airspayce.com. (It's a really nice library.) Also OK with Python. I only have problems from Wolfram.

POSTED BY: David Keith

I've had luck compiling wiringPi libraries using WolframLink. Granted, this is with the model B; however, the WiringPi libraries have been updated for B+ and therefore this method should be viable.

POSTED BY: BoB LeSuer
Posted 10 years ago

Hello again, Arnoud. I have been trying to access the B+ GPIO with the code you suggest above, but without success. I can write to GPIO13 using c code found at http://guillermoamaral.com/read/rpi-gpio-c-sysfs/ and it works fine. I believe it is using the same OS calls as are being called from your code. With the c code, I can write to GPIO13 in a loop and see the waveform on a scope. With the Wofram code I get nothing.

I have tried the wolfram code both by typing it in, and by executing as a script using "sudo wolfram -script myscript.wl" -- nothing happens.

Any ideas?

Best, David

POSTED BY: David Keith
Posted 10 years ago

I can also toggle GPIO13 by echoing to the sysfs class files from the command line. But with the same setup, WL does not toggle the pin, either within "sudo wolfram" or withing wolfram executed under a "sudo -i" root user session.

POSTED BY: David Keith
Posted 10 years ago

Thank you, Arnoud. I'm looking forward to it.

I have a Pi B+ up and running. My interest it a bit of a misuse. I think the main motivation for both the Pi and Wolfram on the Pi is to advocate and enable basic learning. My interest is somewhat different, but still a fun interest. I have used Mathematica for many years, and also done quite a lot of embedded microcontroller programming, most programming Atmel AVR devices in C. This of course provides excellent access to hardware, but offers very little in high level functions. And the development environment is code-simulate-crosscompile-download.

On the other hand, a Pi running Unix/Wolfram has access to hardware, can be programmed within the OS of the target machine, and has access to a rich library of functions. It's only real limitations are: 1) Linux isn't really a real-time OS so can only make limited commitments, and 2) While it's nice to be able to talk directly to an OS on the target machine, the Pi doesn't really have the power to make that convenient during development.

So, what I want to construct is an environment which includes both the Pi as the hardware controller and the PC as the interface and development environment. So if others are interested, here's what I have so far:

1) A Raspberry Pi B+. I followed the instructions on the "Raspberry Pi.org" to install just Raspbian. Install Raspbian Although I found on-line instructions for doing this headless, I connected keyboard and monitor to the Pi, but worked in console mode (not GUI).

2) I installed Putty on my Windows 7 PC. This is a client that allows a remote shell logon over a network to a Unix device. I found good instructions for that here. Install Putty Now I can RLogin to the Pi over the net.

3) I installed Samba to enable file sharing with my Windows 7 PC on my home network. This was confusing with some on-line instructions not working for me. But the instructions at this web site worked: install samba Now the Pi file system shows up on my network.

With this set up, the Pi lives in my study plugged into the local net. I can log in from my PC and work directly on the Pi. (I only work in console mode on the Pi.) I can work on the Pi in both Wolfram and Python. I can also work in Wolfram or Python on my Windows PC. The files I am accessing when I do that can be on my PC, or on the Pi. I can develop and test code in the PC or Pi environment, save it to the Pi, and execute it there. For example, I could develop Mathematica code to acquire a waveform, process it using high level functions in Mathematica, like Fourier, and when I like the code, move it to the Pi where it will still have access to Fourier and can run there. The only annoyance so far is that I have not found a really convenient way to save Mathematica code in a notebook as raw Wolfram language. (There is a way to do this by controlling package generation, but it would be nice if this were straightforward.)

Best regards, David

POSTED BY: David Keith

We have not yet added support for this in the device functions (DeviceConfigure/DeviceRead/DeviceWrite), but this will be supported.

But it is possible to do this yourself as well, and it isn't very difficult.

Remember to launch the Wolfram Language as root (i.e.: sudo wolfram), because the GPIO modifications require root level access:

gpioExport[n_Integer] := Put[n, "/sys/class/gpio/export"]
gpioDirection[n_Integer, dir_] :=  Put[dir, "/sys/class/gpio/gpio" <> ToString[n] <> "/direction"]
gpioValue[n_Integer, val_] :=  Put[val, "/sys/class/gpio/gpio" <> ToString[n] <> "/value"]

And then, for example, this will turn on an LED if it is properly hooked up to GPIO13:

gpioExport[13]
gpioDirection[13,out]
gpioValue[13,1]
POSTED BY: Arnoud Buzing
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard

Group Abstract Group Abstract