Adventures with Arduino part 2

    04 February 2015

    In my last post Adventures with Arduino part 1 I discussed some of the options of wiring up and getting metrics with Arduino. Here is the work in progress

    Arduino Wiring image

    It includes a DHT11 humidity temperature sensor, water sensor and a reid switch. The way things are set up is that it polls the sensors periodically e.g.

    • Reid switch (to see if door is open or closed) every 2-10 seconds
    • Humidity and temperature every minute

    It then sends those values as a simple comma separated file. Data format I’m using is

    device uptime,device name,metric_name=value

    with multiple metric values possibly sent in the same packet. On the receiving side I have a Raspberry Pi that follows this work flow.

    • Uses a modified raspberryfriends daemon from nrf24pihub
    • Daemon receives and parses the payload and ships it off to Statsd - using a gauge data type
    • Statsd rolls up any metrics and sends them over to Ganglia. Ganglia is used for trending and data collection e.g. this shows temperature and humidity in one of my bedrooms. You can notice the effect of a room humidifer on humidity in the room :-)

    Arduino metrics

    • I can also see if I left my garage door open :-)

    Arduino metrics

    Arduino metrics

    • In this particular instance that alert has dual meaning since this particular Arduino is driven by one of those “lip-stick” USB battery packs and Ganglia will expire a particular metric if it hasn’t been reported for a defined amount of time (in my case 1 minute). In this particular case alert state UNKNOWN tells me that most likely battery is out I need to recharge it.

    Raspberry Pi Revision B+ NRF24L01 wiring

    31 January 2015

    Raspberry Pi Revision B+ has 40 pins unlike the original Raspberry Pi. To connect NRF24L01 module to it you need to connect it as follows. This is how NRF24L01 looks like. Pins start with 1 in bottom right.

    NRF24L01 Pinout

    NRF Pin Raspberry Pi
    1 Ground PIN 4
    2 3.3 V PIN 1
    3 PIN 22
    4 PIN 24
    5 PIN 23
    6 PIN 19
    7 PIN 21

    Adventures with Arduino part 1

    01 January 2015

    Few months ago I got myself an Arduino Uno board from Adafruit. I have had couple use cases I was going to try to use them for in order of importance

    1. Water leak detection e.g. put a sensor in crawl space or attic for early detection of water leaks
    2. Garage door open/close state - find out if the garage door has been left open
    3. Humidity and temperature monitoring around the house

    One nice thing about Arduino is that some of the small boards are really inexpensive. For example Arduino Nano board or Adafruit Trinket can run you anywhere between $3.50-$7.

    After receiving the board and playing with some of the basic examples I figured it was time to resolve how to push sensor data to a central location. Some of the options I discovered were as follows

    1. XBee modules. Approx cost per module ~ $20
    2. Bluetooth - Approx cost per module $7
    3. 315/433 Mhz remote control - Approx cost per module ~ $1
    4. Nordic Semiconductor nRF24L01+ modules - Approx cost per module ~ $1

    XBee and Bluetooth are really nice options however I considered them too overpriced for this particular use case so I went ahead and bought a pair of 433 Mhz and nRF24L01+ modules.

    315/433MHz modules

    First thing I tried was 433 MHz modules. They were easy to wire and configure since e.g. transmitter has only 3 pins and receiver 4 pins (although you only use 3) and using the rc-switch project libraries I was able to communicate between my Arduino and a Raspberry Pi. The drawback is that it’s fairly low bandwidth and payload size maxes out at 24 bit so pretty limiting.

    That said an interesting side benefit of these modules is that large number of remote controlled power outlets out there use either 315/433 Mhz bands e.g. Etekcity outlets. If you have a remote controlled device in your house you can look up what frequency it uses with FCC ID search. There is also the 303 Mhz frequency however I have not been able to find the modules for it yet.

    As a result of this tinkering I know am able to turn outlets around my house with my phone :-).

    Nordic Semiconductor nRF24L01+

    These are a lot more tricky to get going as they have total of 8 pins with one unused and it is easy to mis-wire things. It took me a lot of trying to get these going however I finally got it going and was able to pass data between the Arduino and a Raspberry Pi. Max payload on this is 32 bytes which should be enough for shipping out metric data and you can ship them at a pretty rapid rate. Libraries I ended up using were these

    RF24 library and NRF24PiHub

    Do note that these may not work with Adafruit’s Trinket.

    Next steps

    I have ordered some temperature and humidity sensors, water sensors and some Arduino Nanos and will be wiring it up :-), shiping metrics to Ganglia and alerting on it.

    Bosnia and Serbia Floods aid

    18 May 2014

    As you may have heard Bosnia, Serbia and in smaller part Croatia are facing worst floods ever in recorded history

    There are a number of ways to donate. Here are few that are being posted on Twitter from

    I have not seen an easy way on those sites for people in the US to make donation. However Croatian Red Cross allows on-line donations with proceeds being transferred to Bosnian and Serbian Red Cross. You can read about it here

    The only drawback is donation page is in Croatian :-( so here is a quick guide.

    On this page you will need to pick who you are donating to

    • Pomoć za poplavljena područja u Bosni i Hercegovini - Aid for flooded regions of Bosnia

    • Pomoć za poplavljena područja u Srbiji - Aid for flooded regions of Serbia

    • Pomoć za poplavljena područja u Hrvatskoj - Aid for flooded regions of Croatia

    Pick the amount and currency e.g. 25 USD.

    Click on Autorizacija Kreditne kartice. Next screen will include your confirmation as well as currency exchange into Croatian Kunas e.g.

    10 CAD (50.90 KN)

    1 Canadian Dollar is about 5 Kunas so don’t despair :-).

    Payment info will look like this


    • Ime is name

    • Prezime Last Name

    • Adresa - Address

    • Grad - City

    • Poštanski Broj - Postal Code

    • Država - Country

    • Telefonski broj - telephone number

    Click Doniraj and that should be it.

    Building your own binary packages for Cumulus Linux (PowerPC)

    07 February 2014

    Cumulus Networks  is a new entrant in the network gear space. What separates them from other players is that they are not selling hardware but their own network focused Linux distribution called Cumulus Linux. Basically you buy a switch from one of their resellers or ODMs then pay Cumulus a yearly support license. There are a number of interesting things you can do like run your own code on the switch as well as use common Linux commands to configure the switch e.g. brctl, ports are exposed as Linux network interfaces etc.

    One of the first things we ended up doing is installing Ganglia agent so that we can monitor what’s going on on the switch. Cumulus switch we had was running a PowerPC based control plane so that made things a bit tricky since we couldn’t use any of the amd64 built packages. One way to build PowerPC packages would be to get an old PowerPC based Mac and install Linux on it. Unfortunately that seemed like a lot of work and overkill. I realized we could just use Qemu which is an Open Source machine emulator so I could run PowerPC machine on my own laptop :-). Quickest way to get up and running is as follows.

    On Ubuntu you will need to install following packages

    apt-get install qemu-system-ppc openbios-ppc qemu-utils

    Warning: Under at least Ubuntu 13.10 openbios-ppc doesn’t seem to work well. If you get a blank yellow screen after you start the install you will need to get openbios from other places e.g.

    Once you get those you will need to download Debian Squeeze for PowerPC. You will need to download

    • vmlinux

    • initrd.gz


    as well as the netboot image e.g.

    Reason why you need initrd.gz and vmlinux is that if you try to do an install straight off the CD-ROM your install will hang here

    Power PC install QEMU

    Once you have those pieces initiate the install with

    qemu-img create -f qcow2 squeeze-powerpc.img 10G
    sudo qemu-system-ppc -m 256 -kernel vmlinux \
     -cdrom debian-6.0.8-powerpc-netinst.iso \
              -initrd initrd.gz -hda squeeze-powerpc.img -boot d -append "root=/dev/ram" \
              -net nic,macaddr=00:16:3e:00:00:02 -net tap

    Now follow the installation process as you would if you were installing Debian or Ubuntu from scratch. When you are done with the install shut down the emulator. Now to invoke your PowerPC emulator execute

    sudo qemu-system-ppc -m 256 -hda squeeze-powerpc.img  \
               -net nic,macaddr=00:16:3e:00:00:02 -net tap

    Congratulations you are done. What you end up with is this

    root@debian:~# cat /proc/cpuinfo 
    processor    : 0
    cpu        : 740/750
    temperature     : 62-64 C (uncalibrated)
    revision    : 3.1 (pvr 0008 0301)
    bogomips    : 33.14
    timebase    : 16570400
    platform    : PowerMac
    model        : Power Macintosh
    machine        : Power Macintosh
    motherboard    : AAPL,PowerMac G3 MacRISC
    detected as    : 49 (PowerMac G3 (Silk))
    pmac flags    : 00000000
    pmac-generation    : OldWorld
    Memory        : 256 MB