Getting Started with the Prototype (Part 2)

Getting Started with the Prototype (Part 2)

Building the Software Stack

This is the continuation from Part 1 located here.

Hopefully if you’re reading up to this point, you’ve now followed the instructions in part 1, and have a newly installed image on your Pi, or you’re already familiar with the Raspberry Pi, and you want to add the software stack to an existing pi. – If the latter is the case, then be aware that by this point I assume you already have SPI enabled. If you don’t it’d be wise to enable it before continuing.

If all is good, follow me after the jump.

Developer or User?

The first think I’d like you to think about is do you want to contribute back to the project? – I don’t have a huge amount of time to dedicate to the software side, and everything we’re about to do is built on string and duct-tape. It works for me, and I find it really useful. It comes with no guarantees or warranties of any sort!

If you’ve an idea, an improvement then please, I’d urge you instead of just downloading the source, fork it on git hub, and when you’ve something that works better than my implementation, submit a pull request! – I’m a huge fan of open source software, and would love the support to make this tiny little project something really interesting!

However, I know that there’s going to be some people playing with this that either don’t want to, or can’t and that’s okay; I’ll provide instructions on how to get this up and running regardless!

Pi HAT Modules

This tutorial assumes you’re working with the first production prototype.

There are 3 distinct modules on board and covered here, with an optional fourth, however I’ve left that there for future use only at this point.

  1. IR Receiver and Transistor switched breakout to drive 5v worth of IR LEDs
  2. 433MHz transmitter and receiver pair (either basic receiver or the more stable superhetrodyne receiver)
  3. Pin header for the nordic nRF24L01+ 2.4Ghz Radio.
  4. [Unused so far] pin header for a XBee® or XBee-PRO®

The easiest of these to get setup is the IR Receiver and Blaster, so lets start there:

Good old IR / LIRC on the Raspberry Pi

A lot of the devices around my home still use IR for remote interfaces, and it’s a good cheap option for everything from LED light strips to the TV / Projector / Theatre Amp etc. So for me, any home automation system had to be able to at least turn on and turn off the TV!


A huge amount of thanks, and all the credit here goes out to the Linux Infrared Remote Control project and to Alex Bain who’s Open Source Universal Remote Control project kinda started this whole thing off. If you’ve interest in the back story, I’d recommend reading through his site! – While for my purposes I didn’t end up using the node.js side of the project it might well prove useful to you!

A note on hardware

If you’re using one of my boards, or you’ve built your own to the schematics, then the output of the TSOP38238 IR Receiver is wired to GPIO pin 23, and the output going to the transistor is wired to GPIO pin 22.

As the HAT design I’ve gone with intercepts power before delivering it to the Pi, and provides switched and smoothed 3.3V and ~5V rails separate to the Pi, I’m not worried about drawing too much current through the Pi’s GPIO bus. This means in my design I stepped up the transistor switching the LED’s from Alex’s P2N2222AG 600mA NPN to a 5A TIP 120 NPN. Functionally in this design they’re nearly identical, however the additional current switching capability lets me run 2x 940nm 3W 120 Degree LEDs (~1.4A @ 5v for two) instead of the more directional standard IR led’s that I found had to be pointed within 15 Degrees of the TV’s receiver.

All that said, let’s get LIRC setup.

First thing you’re going to want to do is update any outstanding packages on the Pi, to do this, from either the attached keyboard, or through your putty connection type:

Wait for that to finish and then run upgrade:

The last command may take a little time depending on the speed of your internet connection, now is a really good time to go grab a coffee!

At the time of writing, the LIRC package is available via apt, so we can install it with the following:


Once that’s in place and installed, we need to get LIRC configured with the correct GPIO pins for our board.

Again, all my work with LIRC comes from  Alex Bain and I’d recommend checking it out if you’re interested. His writ-up is far more complete than mine, and I’m only mirroring his steps here for completeness.

As a quick reminder, the pin-out for the schematic I’m publishing and the board layout has:

GPIO for input is: 23
GPIO for output is: 22

Start an editor and modify /etc/modules by adding the three lines below to the end of the file.

I’m using the exact same hardware conf as Alex – If it ain’t broken, don’t fix it!

So replace everything in /etc/lirc/hardware.conf with this:

And finally edit /boot/config.txt and add the following to the end of the file:

Restart the pi, and you’re good to try it out:

Again, copying the the instructions from Alex for completeness:

And if all has worked, pointing a IR Remote Control at the Pi and pressing buttons should yield output similar to this:

To check it’s sending IR:

Alex suggests getting familiar with the irrecord application, and while I’ve no doubt this will be useful for those of you needing to copy existing remotes, it’s a little long winded here for a test and is something I’ll come back too.

For now, we can grab pre-built config files, and test either with a matching device, or a smartphone camera to ensure it’s sending.

Firstly I’d suggest looking here:

I Have a Sony TV and remote in front of me to test with, so I’m using the file here:

Backup the current lircmd.conf file (not technically necessary as right now it’s likely blank, but it’s a good habit)

sudo cp /etc/lirc/lircmd.conf /etc/lirc/lircmd.conf.orig

Open the config file to edit it

Then paste the content of the remote file into the end of /etc/lirc/lircmd.conf:

Then restart lirc and check that the remote is setup:

If everything’s working you should see irsend reply with

Finally, either try out the control, or check that the IR led’s are flashing with a mobile phone camera!