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
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
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.
uname -r should say something like
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
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!!
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).