Flashing the USB IR Toy v2

I finally had some time to work on my temperature project and the first step was to make sure my 2 USB IR Toys worked (they finally arrived about 2 weeks ago).

One seemed to work fine (meaning my Raspberry Pi recognised it and enabled the device /dev/ttyACM0), but the other wasn’t being recognised. (In fact the LED was constantly on). I thought I got a faulty one.

I decided to try reflashing it.

Dangerous Prototypes had a howto on how to flash it, but I found it slightly confusing, so here are my instructions (that are for flashing the v2 board with a v22 firmware) on the Raspberry Pi:

Short pins PGC and PGD

First, need to short the PGC and PGD pins. This is simple enough – I just used simple jumper wire.

Get latest Firmware

Downloaded from http://code.google.com/p/dangerous-prototypes-open-hardware/downloads/detail?name=USBIRToy.package.v22.zip

unzip USBIRToy.package.v22.zip

Get latest IRToy-specific Firmware Update Utility

wget http://jesshaas.com/software/IRToy-fw_update.tar.gz

This apparently is a patched utility from the board maker at Diolan.


Note, I had to do all of us sudo – kept getting errors while running these as user pi.
export LIBS=-lusb
sudo apt-get install libusb-dev
sudo ./configure (I got g++ errors if I run as pi)
sudo make
cd ..


sudo IRToy-fw_update/fw_update -e -w -v -m all -vid 0x04D8 -pid 0xFD0B -ix USBIRToy.package.v22/firmware/USBIRToy.v22.hex

Make sure your paths are correct in the above command. 
The successful output should look like:
U2IO flash erasing: DONE.
U2IO id programming: DONE.
U2IO eeprom programming: DONE.
U2IO flash programming: DONE.
U2IO id programming: DONE.
U2IO eeprom programming: DONE.
U2IO flash verifying: DONE.
U2IO id verifying: DONE.
U2IO eeprom verifying: DONE.
RESET Device
Operation successfully completed.
I was lucky. The IR Toy I thought was bad now seems to work fine!

Hacked Door Open Remote with RedBee RFID and Raspberry Pi

On 2 Fridays ago, we had a “hackathon” at work where we stayed back and worked on personal hacks/projects. The entry door to our office is controlled by a 4-number code. We have a remote control to open (unlock) it when someone rings the bell. We had a bunch of RFID equipment sitting around for the past year and a half, and I really wanted to make use of it.

We got a few of these back in 2011 when we were looking at options for an RFID solution. We chose this because we liked the openness of the hardware APIs, however, we ultimately chose a different solution (the pcProx USB reader).

We purchased a bunch of these as they fit directly in the RedBee RFID reader – making it a good solution for deploying RFID at on-ground activations. Again, we ultimately chose a different technology, but this wireless module (2 of them actually) would make this hack even better.

Sparkfun XBee Explorer USB

This plugged into a computer, with the XBee module plugged in allows the “base station” to communicate with multiple devices through the plug-and-play mesh network created hassle free with the XBee modules.

Finally, we needed another door remote to hack.

We figured we could hack this and mimic a button press with one of the Raspberry Pi’s GPIO pins by bypassing the button, controlled by the GPIO pin. I did my homework earlier in the week and found that I needed a solid state relay to bypass the button pressing. I found one at Element 14 (my new favorite online store).
This I figured would work just nice. The GPIO pins of the Raspberry Pi are powered by 3.3V, and the Door remote control is powered by a 12V battery (whether or not that’s the voltage that gets sent through the push-to-make buttons or not, no idea) – this SSR allows for a 0V to 48VDC range on the load pins, and a 3V to 12V on the control pins – perfect for this project.
I worked on this with my colleague Yasin. I would take care of the remote hacking and the Raspberry Pi set up – he would take care of the RFID Reader interface and simple DB/logic coding.
The Equipment

Off To Work
I found the correct pins to use for my soldering. 

Soldered the ends to the control pins of the SSR, and then added wires to plug into the Raspberry pi.

And here it is. Simple.

Yes, you can order Domino’s using Midori on the Raspberry Pi, as I did for much needed fuel. On top of that window, you can see the terminal testing out the RFID scanning. We were lucky to note that we only needed to monitor a device (by cating in the simplest form) for the scans.

My colleague Yasin handled the coding on the Raspberry Pi, using Python and SQLite to manage the RFID device monitoring and scan checking. We managed to get a prototype working only after about two hours or so. Here are some videos. Bare with me, had a few beers.

First night monitoring temperature

Last night, I configured RRD graphs to record the changes of temperature.

Before bed I set the aircon on pretty much full blast. Before going to sleep it was readying at around 26.7 C.

Now as you can see with the graph, the temperature changes way too slowly. Too gradual. This will prove troublesome when calibrating as I get deeper into my next project. (I was hoping for more obvious changes).

The sudden reversal at around 4am is when my wife woke up and reduced the intensity of the air conditioning. This is certainly an area of focus in my project. (adjust it before she wakes up to do it herself).

First Temperature Readings with the Raspberry Pi and DS18B20 Chip

I got my Raspberry Pi reading temperatures with the DS18B20 chip.

I followed some of the guidance at the following two URLs (although I had to flip the chip as the instructions are a bit confusing – basically, look at the diagram on the 1st link below, and swap (pin 1 is 3, pin 3 is 1)):

  1. http://www.cl.cam.ac.uk/freshers/raspberrypi/tutorials/temperature/
  2. http://webshed.org/wiki/RaspberryPI_DS1820

My wiring:

Originally, according to the first URL above, I had the sensor chip the other way around, which caused it to heat way up seconds after turning on the Raspberry Pi. Thanks to the second link above which has an actual photo of his set up, I managed to get it going.
I refer to the pins on the DS18B20 chip as follows:
  1. Blue jumper is plugged into pin 7 (BCM GPIO 4) on the Raspberry Pi, and pin 2 on the DS18B20 chip
  2. White jumper is plugged into pin 6, which is a ground pin on the Raspberry Pi, and pin 3 on the DS18B20 chip
  3. Yellow jumper is plugged into pin 1, which is powered at 3.3V, and pin 1 on the DB18B20 chip
  4. The 4.7k ohms resister is connected to chips’ 1 and 2 of the DB18B20 chip

Kernel Modules

sudo modprobe w1-gpio
sudo modprobe w1-therm

Cating the device

The device files are located in /sys/bus/w1/devices/* where * = the serial number of the chip. In my case, the serial number is 28-0000032837ea. The file in that folder (the folder name is the S/N) that we need to cat is w1_slave:

$ cat /sys/bus/w1/devices/28-0000032837ea/w1_slave
a7 01 4b 46 7f ff 09 10 e0 : crc=e0 YES
a7 01 4b 46 7f ff 09 10 e0 t=26437

The line we’re interested is the 2nd, the value after the t=. Just pull this, divide by 1000, and we determine my room is a horribly hot 26.437 degrees Celsius!

Initial Code
The first link above has code written in Python. I am lame and prefer PHP, so I wrote the following:


if (!defined(“THERMOMETER_SENSOR_PATH”)) define(“THERMOMETER_SENSOR_PATH”, “/sys/bus/w1/devices/28-0000032837ea/w1_slave”); 

// Open resource file for thermometer
$thermometer = fopen(THERMOMETER_SENSOR_PATH, “r”); 

// Get the contents of the resource
$thermometerReadings = fread($thermometer, filesize(THERMOMETER_SENSOR_PATH)); 

// Close resource file for thermometer

// We’re only interested in the 2nd line, and the value after the t= on the 2nd line
preg_match(“/t=(.+)/”, preg_split(“/n/”, $thermometerReadings)[1], $matches);
$temperature = $matches[1] / 1000; 

// Output the temperature
print $temperature;


And there we are! Now it’s time to start plotting this info using RRD. More on that later.

Preparing for ThermostatPi – a Raspberry Pi controlled thermostat

I am starting to prepare for my next Raspberry Pi project – I’m giving it the very unoriginal name of “ThermostatPi” – essentially it will be a Raspberry Pi Thermostat.

There are many of these types of projects I’ve found on the net, but I haven’t yet found one that will do exactly what I want. You see, many of the projects out there use simple SSR (solid state relays) to turn on/off a central boiler. This obviously isn’t going to work for me since we have a wall-mounted aircon.

So I want a device that has a built-in thermometer and an IR transmitter so I can adjust incrementally the temperature.

I got some inspiration from the following sources:

Controlling a heat pump with Raspberry Pi and USB IR Toy

This guy is using a Raspberry Pi and a IR transmitter to control a heat pump. He uses a Google Calendar for the scheduling and operation. However, it doesn’t have a thermometer (and I am not interested in using Google Calendar, but email). But, the essential component, the IR Toy (module with infrared receiver AND transmitter) built in, controlled over USB. And he got it working on a Raspberry Pi.

Raspberry Pi Thermostat

This guy uses a DS18B20-compliant single wire thermometer sensor to communicate temperature readings to the Raspberry Pi. But, he uses SSRs to control the actual airconditioning units.

I did some shopping last night. I found this great website, Seeed Studio which is actually a Shenzhen-based “open hardware facilitation company”, and they have all kinds of great toys that they build in house, including the IR module. So, I bought the following:

USB Infrared Toy v2

The product is described as “Assembled USB infrared remote control receiver/transmitter v2 designed by DangerousPrototypes.com. Use a remote control with your computer, view infrared signals on a logic analyzer, capture and replay remote control buttons, and play TV POWER codes.”(The emphasis is mine – the ability to capture IR signals will be essential so I will be able to theoretically operate any IR unit.)

One Wire Temperature Sensor

This is just a simple DS18B20 digital thermometer sensor. I chose to get one on a wire so I can position the thermometer sensor away from the actual Raspberry Pi/IR transmitter if need be.

Here’s a good resource from the University of Cambridge on how to interface with a thermometer with a Raspberry Pi: http://www.cl.cam.ac.uk/freshers/raspberrypi/tutorials/temperature/. And later on, in case I want to integrate an analog light sensor (for controlling temperature differently during the day from the night): http://www.raspberrypi-spy.co.uk/2012/08/reading-analogue-sensors-with-one-gpio-pin/  – but this is a phase 2 I guess.

So now, the wait game begins. I’ll need to wait for it to be shipped. And no doubt it will arrive at my office early in the week so I’ll probably need to wait a few days before I can really get started. I suppose I can get a head start on the code…

Photo Credits: http://www.seeedstudio.com