RFM12B linking a JeeNode Micro with a Raspberry Pi

I’m going to try to use my new RFM12B based JeeNode Micro from JeeLabs to talk to a Raspberry Pi equipped with another RFM12B. Although the radio module (and JeeNode) are from JeeLabs, I’m going to connect it to a raspberry pi using an Eve-alpha board I got via the Ciseco kickstarter a while back. The eve board just makes the connections, it doesn’t have any circuitry involved in the path.

Posts on the Eve-alpha wiki led me to an image of the modifications I needed to make:  Now I have the radio connected to CE1 to enable it and GPIO 24 (#5 in WiringPi convention) as the IRQ line. Potentially this could allow us to be polled when messages arrive. (Actually I needed to change this later on – stay tuned!)

I found a raspberry pi driver that exposes the RFM12B as a device in /dev/ Fantastic!! It’s here. So we can download it and then edit the config with a
git clone https://github.com/gkaindl/rfm12b-linux.git
cd rfm12b-linux
nano rfm12b_config.h

The following values needed to be changed for my situation, one to enable use with the raspberry pi and the other seemed like a good idea, as I’ll be planning to interoperate with JeeLib code shortly:

#define RFM12B_BOARD 1
#define RFM12B_DEFAULT_JEE_ID 1

Then make moaned about not having the kernel sources. So I installed the 3.10-3-rpi kernel (was 3.6) and rebooted as detailed here.

EDIT – responding to issues raised on Github – boiled down method of installing a recent kernel complete with headers on bare 2014-01-07-wheezy-raspbian is:
sudo aptitude update && sudo aptitude upgrade -y
sudo aptitude install -y linux-image-rpi-rpfv linux-headers-rpi-rpfv
echo -e "kernel=vmlinuz-3.10-3-rpi\ninitramfs initrd.img-3.10-3-rpi followkernel" | sudo tee -a /boot/config.txt

EDIT – Raspberry Pi 2 ISN’T WORKING YET! see here. 

On reboot, uname -r should say something like

3.10-3-rpi

rather than

3.10.25+

Now the code will compile! Back in the rfm12b directory, we can proceed to load the spi module (if not blacklisted in /etc/modprobe.d/raspi-blacklist.conf) and the radio driver:

sudo modprobe spi-bcm2708
sudo insmod rfm12b.ko

If this works you probably want it loaded on boot automagically like this

sudo cp rfm12b.ko /lib/modules/3.10-3-rpi/
echo -e "rfm12b" | sudo tee -a /etc/modules
sudo depmod -a

On the JeeNode Micro, code from JeeLabs seemed a good place to start, but I also need a way to get code onto the Jeenode micro. Unlike many larger arduino compatible/inspired devices, it doesn’t provide a USB interface. Instructions at JeeLabs suggested I could use the Arduino IDE, and a diagram.

The latest beta of Arduino is more friendly with other hardware, so I downloaded that with a
wget http://downloads.arduino.cc/arduino-1.5.4-linux32.tgz
tar xzf arduino-1.5.4-linux32.tgz

Next the hardware description of the JeeNode board from Jean Claude’s repository is needed, so I downloaded and extracted that:
git clone https://github.com/jcw/ide-hardware.git
mv ide-hardware arduino-1.5.4/hardware/jeelabs
.

Now when I start the arduino IDE I get an extra option in the board menu!!

The latest Arduino IDE with the addition of JeeLabs JeeNode Micro board.
The latest Arduino IDE with the addition of JeeLabs JeeNode Micro board.

Using my cheapy clone USBasp device (but ensuring that I didn’t connect the 5v to the JeeNode Micro) I managed to set the fuses:

avrdude -v -p t84 -c usbasp -U lfuse:w:0xc2:m -U hfuse:w:0xd7:m -U efuse:w:0xff:m

and then I could use the ‘Upload Using Programmer’ in the arduino IDE to program the JeeNode. I uploaded the rfm12b_echo_client example to the JeeNode and fixed it up so that the baud rate was one of the permitted ones for TinySerial (it only supports a few baud rates so setting it to other values supported by the regular serial library gives an error on compilation). I also added the lines from the JeeLabs site to turn the radio on just before the rfm_initialise command:

bitSet(DDRB, 0);
bitClear(PORTB, 0);

After a bit of faffing I was able to see the send LED pinging away every second, but nothing on the raspberry pi side where I was running rfm12b_jeenode and rfm12b_echo alternately. After many false starts I finally re-read the kernel driver instructions again and remembered that the interrupt line is specified as going to pin 22 on the pi’s GPIO, not the one I’d used following the Eve Alpha guide.

Once I soldered the wire to that line instead, the raspberry pi started echoing ‘hello’ from the radio! I moved all round the house and couldn’t get it to drop a packet, even from the kitchen to the bedroom (it’s not a big house, to be fair).

12 Comments

 Add your comment
  1. Hello,

    I’m getting a great reading about IoT arround here.
    If I understood well you are only using the Eve-alpha board as a way to interface the JeeNode Micro with the Raspberry Pi.
    Can you please tell me (or point me somewhere) on how can I connect the JeeNode Micro to the RPi GPIO? Is that possible?
    Thank you for any help and keep the exelent work!

    • Hello Mico

      I tried the Eve-alpha board as a multi-radio platform, but got frustrated by their closed source nature and therefore not much of an active support community surrounding it. In contrast, when I had trouble with the JeeNode I could post onto their forum and got answers within minutes. Because it’s open source, there are many people involved who are happy to help out, but if you are trying to sell stuff, you have to do all the support yourself.

      I don’t quite understand why you want to connect a JeeNode Micro directly to the Pi – is it for initial programming only or for some other reason?

      I am now using a JeeLink to plug into the Pi and interface the raspberry pi with the 868MHz radio. I am sure I could use a JeeNode instead if needed.

      At the other end of the radio link is a JeeNode Micro, sending temperature data or whatever.

      However the JeeNode Micro is rather limited and so to interface this to the Pi you would need to program a software serial or some such functionality, then program the JeeNode Micro, then connect it up to the pi running some sort of picocom.

      So unless you absolutely need to cut down every mm and/or save every watt/penny, use a JeeNode v6 and/or JeeLink.

      But if you do choose the high road, then let us know how you did it!!

      G

  2. Hi Gareth,

    Sorry if I wasn’t clear enough.
    My principal intention is to be able to receive data sent from RFM12b sensors on a RPi. For this I would like to attach an RFM12b directly to the RPi. (and process it with Node-RED)
    Do you know if this is feasible using the linux driver and only the RFM12b? (this was the idea I got after reading your post, but I don’t know if the EVE board also adds some kind of logic to the interface)
    Thanks

  3. Sorry for the delay Mico, I understand what you’re trying to do now!

    I’ve just ordered one of these RFM12B modules from ebay: http://www.ebay.co.uk/itm/Raspberrypi-RFM12B-module-SPI-interface-868Mhz-/141193688562.

    This looks to be about the cheapest way to use the RFM12b directly on the Pi – without having to pay for the usb interface and memory that the jeelink provides.

    The Alpha board doesn’t supply any logic, and neither does this board much, a couple of caps perhaps for decoupling as the RFM12b module speaks SPI as does the Pi (on the GPIO pins.

    I’ll post a page here once it has arrived and I either can or can’t get it working – and the new wireless system is ready to be released.

    Let me know if this helps and good luck with your projects!

  4. Hi,
    has the board arrived ?
    Have you done something with it ?

    Thanx
    Mauro

    • Yes, the board arrived and worked perfectly! I would recommend them to those who want a bare-bones cheap and simple solution to interfacing with the rfm12b. However I’m also interested int the rfm69 which is compatible but increases the range and adds some more modes.

  5. does not work with the new Raspberry Pi 2 version 🙁

    after
    echo -e “kernel=vmlinuz-3.10-3-rpi\ninitramfs initrd.img-3.10-3-rpi followkernel” | sudo tee -a /boot/config.txt

    the board hangs and does not boot up again.

    with windows i edited the config.txt and the rpi working up again.

    can anybody help me plz? I need the rfm12 driver.

    • Yes – I’ve been trying to get it working on the pi 2 myself over the last couple of days. See this post for how to get kernel headers installed – but I get errors in dmesg after the module loads and nothing in /dev/rfm12b*. Still working on it – I’ll let you know if and when I find a solution!

      • Hi Gareth,

        first of all… nice work. I have now successfully compile the module but the same issue.

        The module loads but nothin in /dev/rfm12b*. 🙁

  6. Hi Gareth,

    I found this website… http://www.qdh.org.uk/wordpress/2015/04/21/rfm12b-linux-on-the-raspberry-pi-b2-gpio_base/

    But repository from https://github.com/klattimer/rfm12b-linux not working
    Now i using this https://github.com/gkaindl/rfm12b-linux an change:

    in this file /platform/plat_raspberrypi.h line 81

    u32* gpio = ioremap(0x20200000, SZ_16K);
    to:
    u32* gpio = ioremap(0x3f200000, SZ_16K);

    and now i can receive data from my node´s with the raspberry pi 2

    sorry for my english, best regards from austria 😉

    • Hey – that’s really good work and very useful – thanks so much!

      The power of open source – other people help fix your bugs – love it!!

      G

  7. pi@raspberrypi:~/rfm12b-linux $ make
    make -C /lib/modules/4.1.19+/build M=/home/pi/rfm12b-linux modules
    make[1]: *** /lib/modules/4.1.19+/build: No such file or directory. Stop.
    Makefile:30: recipe for target ‘all’ failed
    make: *** [all] Error 2

    I did everything like it was supposed to be! i compiled even the hello world example, but I can not still compile the driver! please help!!!

Leave a Comment Cancel reply

Your email address will not be published.

64 + = 70

1 Trackback

  1. Reading multiple sensors with rfm12b_linux and node-red | layer zero labs (Pingback)