Computing stuff tied to the physical world

Resetting a JeeNode from a RPi

In Hardware, Software on Sep 21, 2012 at 00:01

Now that the JeeNode talks to the Raspberry Pi, it’d be interesting to be able to reset the JeeNode as well, because then we could upload new sketches to it.

It’s not hard. As it so happens, the next pin on the RPi connector we’re using is pin 12, called “GPIO 18″. Let’s use that as a reset pin – and because this setup is going to become a bit more permanent here, I’ve made a little converter board:

DSC 4149

This way, a standard JeeLabs Extension Cable can be used. All we need is a board with two 6-pin female headers, connected almost 1-to-1, except for GND and +5V, which need to be crossed over (the other wire runs on the back of the PCB to avoid shorts).

This takes care of the hardware side of resets. Now the software. This is an example of just how much things are exposed in Linux (once you know where to find all the info).

There’s a direct interface into the kernel drivers called /sys, and this is also where all the GPIO pins can be exposed for direct access via shell commands or programs you write. Let’s have a look at what’s available by default:

$ sudo ls /sys/class/gpio/
export  gpiochip0  unexport
$

The “export” entry lets us expose individual GPIO pins, so the first thing is to make pin 18 available in the /sys area:

sudo echo 18 >/sys/class/gpio/export

That will create a virtual directory called /sys/class/gpio/gpio18/, which has these entries:

$ sudo ls /sys/class/gpio/gpio18/
active_low  direction  edge  power  subsystem  uevent  value
$

All we’ll need is the direction and value of that pin. Let’s first make in an output pin:

sudo echo out >/sys/class/gpio/gpio18/direction

Now, we’re ready to reset the JeeNode. I found out that the pin needs a negative transition (from 1 to 0) to do this, so the following three commands will do the trick:

sudo echo 1 >/sys/class/gpio/gpio18/value
sudo echo 0 >/sys/class/gpio/gpio18/value
sudo echo 1 >/sys/class/gpio/gpio18/value

And sure enough, the JeeNode resets, and the terminal I have running in another window shows the RF12demo startup message again:

Screen Shot 2012 09 18 at 14 32 09

We’re in control – shell over sketch!

  1. Cool. That was going to be my next step, but my only raspberrypi is running my monitoring server for my jeenodes. Uptime is now 47 days ;-) So I need to get some more raspi’s

    To extend the commandline theme and not rely on the arduino ide I found ino looks interesting. http://inotool.org/ (I have never liked the arduino IDE/Editor so this is probably the direction I am going to go in.)

    • Thanks – great pointer!

      (get a 2nd RPi and swap SD cards – that’s what I do to keep things organised here)

  2. Thanks… that inotool looks to fit my bill exactly too for my Portux server, so I can upload sketches in my box. And yes, I have another set of Raspi’s on order (one is doing service as an excellent media player now)

  3. sudo [whatever]

    You don’t need the “sudo”. You’re already root.

  4. Wait – I edited the prompt, I’m actually running as non-superuser on the RPi.

    Is there an easy way to make these /sys/… devices writable by others?

    • I guess ‘chmod -R a+w /sys’ should work?

    • Yes, but that doesn’t persist across reboots. It feels like a kludge to do this at each startup (even if automated).

      (and more importantly: I don’t think it’ll fix on-the-fly created entries)

  5. Yeah, at the moment the only way is have an init script set permissions at boot time. I spent half a day trying to get udev rules to work, to no avail, and it appears no one else has managed it. The issue seems to be related to the way the GPIO driver is implemented.

    Oh by the way my raspi’s up time is now at 48 days, powering my master JeeNode and feeding cosm etc..

    pi@raspberrypi ~ $ uptime

    19:19:06 up 48 days, 2:20, 2 users, load average: 0.13, 0.06, 0.05

    Can anyone beat that ;-)

    • LOL… Not fair… I keep fiddling with mine… Maybe I should power up one of the others and just leave it sitting at the command prompt? ;-)

    • Heh, IMO if you have uptimes of over a few days, then you’re missing out on all the fun ;)

  6. Can you explain where gpio18 is connected to jeenode ?

Comments are closed.