BeagleBone and GPIO pin mux’ing

On my last BeagleBone post I have a relay driven through a transistor, the base of which is connected through a 1k0 resister to the pin 24 on the P8 pin header.  So how do we drive this pin?

The AM335x ARM Cortex™-A8 Processor can do a load more than the BGA package has connectors for, so to get around this “hardware limitation”, the pins can be set up for different functions.. enter pin muxing.

First we need to make sure the pin we want to use is in the correct mode! For this you’ll need to manual for your BeagleBone (its the SRM or System Reference Manual your looking for.. for latest rev, you’ll find it here). On the A6 rev manual head to page 48 and on.

The names for the pins (signal names) are shown beside the pin outs for the header connectors P8 (table 8, page 48) and P9 (table 11, page 53). If you login to your BeagleBone (as root, sudo, su -l or what ever you need to do!), you will see all these signal names (for mode 0) in the folder /sys/kernel/debug/omap_mux.

For my relay pin I need to set this to mode 7 (from table 10, page 51) can see the mode 7 signal name is “gpio1[1]“.  To find out the current mode, type:

cat /sys/kernel/debug/omap_mux/gpmc_ad1

That should return three lines:

name: gpmc_ad1.gpio1_1 (0x44e10804/0x804 = 0x0007), b NA, t NA
mode: OMAP_PIN_OUTPUT | OMAP_MUX_MODE7
signals: gpmc_ad1 | mmc1_dat1 | NA | NA | NA | NA | NA | gpio1_1

From this we know that the pin is in the correct mode (7).  If it was not in the correct mode or a change of mode is required then it’s easy:

echo <mode> > /sys/kernel/debug/omap_mux/gpmc_ad1

There is a little more that can be done with the mode number, internal pull up resistors can be enabled or disabled.  The mode is made up from the following byte:

Bit 0 \
Bit 1 |- Mode
Bit 2 /
Bit 3: 1 - Pull disabled, 0 - Pull enabled
Bit 4: 1 - Pull up, 0 - Pull down
Bit 5: 1 - Input, 0 - Output

There are 66 GPIO pins between the two headers. These are 4 controllers driving these pins GPIO0, GPIO1, GPIO2 and GPIO3. To configure a pin we need to use a simple formula to find out the software GPIO reference for it or the GPIO pin number.

The pins GPIO number is made up of two parts: 1) The chips base number, 2) the pin number itself.  It’s all in the pin label: GPIO<base>_<pin_no>.

GPIO pin number = <base> x 32 + <pin_no>

For the physical pin GPIO1_1 [P8, pin 24] the GPIO pin number is found via this formula:

GPIO pin number = 1 x 32 + 1 = 33

Now we need get this pin ready to do something..  All IO ports on the BeagleBone are mapped to the file system (such in the Unix model for IO).  The file system location for this action is here: /sys/class/gpio. Getting a GPIO pin ready is done by “exporting” it.

echo 33 > /sys/class/gpio/export

This will cause a new folder to exist in the gpio directory…

gpio33 -> ../../devices/virtual/gpio/gpio33

We can go in and have a look inside this folder:

-rw-r--r-- 1 root root 4096 Nov  7 15:43 active_low
-rw-r--r-- 1 root root 4096 Nov  7 15:43 direction
-rw-r--r-- 1 root root 4096 Nov  7 15:43 edge
drwxr-xr-x 2 root root    0 Nov  7 15:43 power
lrwxrwxrwx 1 root root    0 Nov  7 15:42 subsystem -> ../../../../class/gpio
-rw-r--r-- 1 root root 4096 Nov  7 15:42 uevent
-rw-r--r-- 1 root root 4096 Nov  7 15:51 value

Set up the direction of the pin:

echo out > direction

Want to turn the port on/high…? easy:

echo 1 > value

Off again…

echo 0 > value

See what state it’s in?

cat value

Cool… I can hear my relay clicking on and off in the lab!

Some more info on this can be found here:

1) elinux.org/EBC_Exercise_10_Flashing_an_LED
2) beaglebone.cameon.net/home/pin-muxing
3) akademii.blogspot.ie/2012/02/beaglebone-gpio-testing.html

 

TI LaunchPad MSP430 board

More MCU’s… Time to take a look at the TI LaunchPad MSP430 board. These things are so cheap, under a fiver from RS.

While not quite as simple to set up in Linux as say Adruino, the process to get ‘em working is fairly simple with a great starting point at HackADay.

Heater control project (hardware prototyping)

So I have got the DS18B20 hooked up to the BeagleBone’s 1-wire interface, it’s time to look at the over all design of this little project.  I’m not sure there is a simpler circuit!? Started up KiCad and took a while to track down the libraries for the BeagleBone headers and the DS18B20. [Look here for the BeagleBone and here the DS18B20]

It took a little hacking with a text editor to extract the parts from the two projects and get them into a KiCad library.. Got to love open source design tools, you can use a text editor to work on a library… Very cool!  In practice this took way longer than drawing up the circuit.  But a learning curve worth going on.

The simple schematic of the heater control.

Really nice of KiCad to allow you to insert a graphic into your schematic.. very handy when moving to the prototype stage, everything can be noted on the drawing.  On my schematic I have the BC547 and the DS18B20 pin-outs as a reference.

My Beaglebone heater control breadboarded..

So there it is.. a first draft on the breadboard.  Time to move to the software domain and see if we can get the BeagleBone to drive the relay. The wonderful world of the BeagleBone and GPIO pin mux’ing.

BeagleBone vs Arduino (heating control)

I’m just toying around with a little project I want to get off the ground.  Quite simple: I have an office at the end of the garden and now the weather is getting a little colder, I’d like to be able to remotely start a little heater I have there over our home network.  I would also like the controller to monitor the room temperature and turn the heater on and off as required.

The famous Arduino Uno!

I’ve tried giving this a go using an Arduino and an Arduino ethernet shield, but have had a load of trouble keeping the TCP/IP stack stable.. My code would work for an hour or two and then the system would crash. This is a really tricky problem to debug, once reset the system is stable and works fine, then all of a sudden it all crashes and requires a reset to start back up.  I’ve tried tracing the stack to see if it overflows, etc.. but finally given up on the Adruino solution.

BeagleBone… Wooof Woooof

Enter the BeagleBone.. From a cost point of view its on the money, an Arduino and Ethernet shield come in at around €64, the BeagleBone can be got from RS for €75.. I know the Raspberry Pi is the ticket here, but I can’t get a hold of one any time soon..

I’ve got my BeagleBone hooked up to a Dallas DS18B20 1-wire temperature sensor… So easy to do it’s not funny! The version of Ubuntu I’m using has 1-wire bus ready to go on the P8_6 header pin. Think I’m ready finally start this project!