Raspberry Pi – RGPIO

RGPIO is a Raspberry Pi installable module that provides a device driver interface GPIO (General Purpose Input/Output).

Installing RGPIO

Put rgpio.ko in /lib/modules/3.6.11+/kernel/drivers/rgpio
Add rgpio to the list of modules to load at startup in /etc/modules
Run depmod to update modprobe’s list of module dependencies.

What RGPIO looks like

RGPIO creates a device: /dev/rgpio

This device is a character mode device that you can write text strings to and read text strings from. These strings tell RGPIO what to do, and tell you what RGPIO has found.

For testing, it is useful to set up a small script – I call it p containing:

[ -c /dev/rgpio ] && echo $@ > /dev/rgpio && cat - < /dev/rgpio

([ -c /dev/rgpio ] stops anything being written to a non-existent device.)

Then you can use rgpio by entering commands as follows, and the output will be shown immediately:

user@rpi:/home/me# ./p P14R
RGPIO 14:on

Help is built in:

user@rpi:/home/me# ./p H
{P|O|I|W|L}     set mode: PIN,One-wire,I2C,PWM,LCD
?               show Help
pidS            Sending SIGIO to process when new output is added (pid=0 to cancel)
{P|O|I|W|L}?    show Help for each mode
                #,% can be decimal, 0x Hex or 0b Binary

RGPIO Modes

P mode: control the individual GPIO pins. This includes reading from and writing (Lo or Hi) to the pin, watching for changes in the read-state, and setting the internal pull-ups for each pin.

W mode: PWM control – hardware (on Raspberry Pi, this is only on pin 18) or software modes.

L mode: control a parallel character LCD device

I mode: seek, query and control I2C devices

O mode: seek, query and control 1-Wire devices

Here are some Python examples using RGPIO on the PiBoard

Comments

Leave a Reply

Your email address will not be published. Required fields are marked *