Connecting microcontroller projects to the internet - the cheap way
There are a few options to connect an arduino to the internet. Unfortunately most of them are pretty expensive.
You can get an arduino board with built-in ethernet or attach an ethernet shield to a standard arduino board. These will cost about 40 euros and you’ll have ethernet cables lying around. There are also WiFi shields but these start at about 60 euros for the shield alone. Also these add significantly to the project’s power consumption
A cheap and easy solution for adding wireless communication to an arduino is the 868Mhz HopeRF RFM12 wireless radio module. These transceivers are about 4 euros and there are very nice arduino clones that have them built in from JeeLabs. The range is about 100 meters indoors and up to 300 meters outdoors.
I got one of these and some of the smaller JeeNode Micros that use a ATTiny 84 instead of the ATMega 328 - These are great for small battery powered sensor applications.
You can get USB modules with an RFM12 on them and attach them so a computer to create a bridge from them to the internet but that means that you’ll have to run a computer all the time just to forward things to the net.
I had a couple of old ‘La Fonera’ routers available. These were given away for free some years ago by a company called Fon and there was a box full of them at the local hackerspace. I decided to create a gateway from the RFM12 transceivers to the internet with these routers.
The main use case for this are battery powered sensors/actors that are in sleep mode most of the time and wake up in certein intervals to either send some sensor values to the net (e.g. Twitter) or get some setting from the net and switch something on/off. Initially I wanted to send information about the humidity of my plants on the balcony to a website.
The Fonera routers have 5 gpio pins that can be accessed on the board and used to create a bitbanged SPI port to talk to the RFM12. They also run Openwrt - a highly customizable embedded linux for routers.
With the added RFM12 chip you can just put one in WiFi client mode and have it sitting on a shelf. Up to 30 arduinos/JeeNodes can send data to it and the little device routes them to the internet.
The gpio pins are described on the openwrt fonera page. Four of them are in a row next to the ethernet port:
And the fifth is on the back of the board on TP3:
In order to use these pins you have to remove the four capacitors for these pins. Then I put a pin header on the board and soldered a wire to TP3
and connected the pins to the rfm12 module in the following way:
Fonera || rfm12
GPIO1 -> sck
GPIO3 -> sdi
GPIO4 -> sdo
GPIO7 -> sel
GPIO0 -> irq
I had to patch the openwrt linux kernel so it creates an spi port on these pins and uses the spidev driver to make the port available to userspace programs. The patch is on my github repository.
Then I ported the C++ jeelabs RFM12 driver for atmel to C and made it use spidev. Everything is available on gitub: https://github.com/RickP/rfm12_gateway - There is also a ready to use openwrt image for fonera in the Fonera folder - so as long as you don’t want to do this with a different router you don’t have to compile it yourself.
The server daemon on the openwrt device waits for messages in a certain format from the RFM12 nodes and then calls a lua script in /etc/rfm12.d. The scriptname is given to it by the arduino. So you can add your own lua script (the length of the name has a maximum of 5 letters) with a function ‘process’. That function gets passed the message from the arduino. It can then route the request to the internet.
When the router receives a message it sends back an ACK signal to the sender so it can retry until it knows the message gets through. The return value of the lua process function is also returned to the sender so you can fetch data from the net.
There’s a sample script for posting sensor values to cosm (formerly pachube) included. Just edit it to add your api key and feed id to it. You’ll find an arduino sketch for sending values to the cosm script in the arduino folder.
On the arduino side you need a slightly changed JeeLabs rfm12 library that uses a lower bitrate due to the bitbanged spi on the Fonera. Get it here: https://github.com/RickP/jeelib
I’ll try to port this to raspberry pi as soon as I get one, so this can be done with hardware that is still available. Also the faster processor would allow me to exchange the lua scripts for nodejs or ruby/eventmachine scripts.
Also a kind of web interface where you can control ports or add scripts with a kind of wizard would be nice.