Mk2 Low Cost Home Automation

time2A While ago I setup a Pi to control some quite cheap 433Mhz RC mains switches I got from Maplin [ code N78KA]. The controllers were connected to Lamps to automatically light up various rooms in the house after dark.

The RC switch comes with a simple 4 way hand controller and initially I was just planning to hack this. However looking on the internet I found a few examples where people had used Arduino’s and Pi’s with cheap RC transmitters to ‘mimic’ the signals rc-switchgenerated by the hand controllers, to operate the remote units. I could not find any examples of people who had used the exact Maplin RC switches I had, but reading around it looked like the rc-txcodes were relatively common between products. After a very frustrating day of trial and error I decided to apply a bit intelligence and got the oscilloscope out and started comparing the serial data coming from the Pi and that produced by the hand controller. Quite quickly I realised that the data from the Pi was correct but back to front, having correcting this I was able to activate the remote switches at will !

From here I wrote some simple Python code to control light positioned around the house, planning to tidy it up. Well that was over a year ago ……

The main drive to produce a mk2 version was to avoid me having to manually alter the timings as the length the day changed. It had always been a plan to sort this out with a light dependent resistor (LDR) but I just never got around to it.

Having decided that I could not face another autumn with the family moaning about the house being dark I decided now was a time to get this updated. In addition to auto correcting for the daylight I also wanted to improve the status feedback. The mk1 version simply had a single LED which flashed every few seconds to show the Python code was still running.
img_2439For the display I landed on a miniature OLED display I had picked up from a JAM earlier in the year. You can see the details for this on my last blog posting. As part of the ‘upgrade’ I decided to start from a clean installation of the latest Rasbian . This necessitated trying to re-learn how to get the RC serial libraries working again as I had not written it down the first time around [there is a lesson here], somehow in this process I ended up with different library [] which turned out to be a whole lot easier to work with than the one I used first time around.

The next thing to sort out was adjusting for the changing daylight hours. Using an LDR to detect darkness was fine until my daughter left the light on in the room where the Pi was….. I wanted a self-contained control unit so running wires from a remotely mounted LDR attached to a window was not any option. The solution I landed was to use sun rise and set times, initially I looked at getting these from the web, but that assumes a good long terms stable wifi link, which is a little unrealistic in my experience. After a bit of searching I found an quite old [2004] bit of s/w called sunwait. I think it was originally developed to be used with cron, but can be run from the command line to give sun rise / set times for any given latitude and longitude. The the output is a fixed format so it is possible to reliably grab the target information without too much difficulty. I have written a page in the ‘random Pi notes’ section of my site which describes how to install and basic usage of sunwait.

rc-testHaving tested the individual bits of code I pulled them all together. The resulting application and a number of the test programmed I used to figure out how bits worked can be found on my git-hub. I have tried to comment the code so it is understandable – not least as I struggle to otherwise. Currently the code allows for each controller channel to define an on time relative to sun-set, an off time and a random element. The timings are adjusted daily, in-line with changes to sun rise and set times. In addition, when the code is first run it does a basic check to see if it has missed any comments so it will recover straight away from power cuts which are quite comment where we live. The code is still a little work in progress although stable it needs a tidy up and a cleaner way to setup the timings.time1

Hardware wise I have manged to get everything into an old Pimoroni Pibow case. Pi wise it
is running on an early [no mounting holes] Pi B. I find applications like this a great way to use older hardware which is bit slow to experiment with but still more than fast enough for an application like this. It also helps to keep the costs down as I had all the bits already.

Links to Instructions / help

Setting up an OLED

Install instructions for sunwait

Setting up the RC433 switch library

Link to my Git-Hub  – you can find my controller Python code here

Maplin RC controller product codes – N78KA  [ 1 off] N38HN [ 5 off]

Posted in Uncategorized | Tagged , ,

Tiny OLED displays

img_2439At the recent CAMJAM I got lots of questions about a small OLED display I was using as part of a home lighting control project.

If you are looking to include a small inexpensive status display on your next project, one of these may be just what you need. Prices range from around £16 from the UK Adafruit distributors to £6 on a UK Ebay site – if you are happy to take a bit of chance you can find them even cheaper from sites in the Far East.  img_2435

The picture to the right gives you an idea of how much you can display – this is a single colour 132 * 64 pixels module. The great thing about these displays is being OLED, they don’t have a backlight avoiding the separate drive circuit often needed for ‘traditional’ LCDs.

The modules generally seem to come  with either and I2C or SPI interface.  I have only used I2C varients but the driver software from Adafruit can be configured for either type.

It is worth highlighting that all the small displays of this type that I have seen run on 3.3V not 5V – I have not had any problems running them directly from the Pi 3.3v supply.

Configuring a Pi to drive them was quick and simple – follow this link to see some detailed instructions that work for me.

Posted in Uncategorized | Tagged , ,

Tempus Fugit WordClock Section Goes Live

IMG_2096With the first TF WordClock kits shipping yesterday the TF area on the blog is now  fully live. In addition to information about the TF there is a new instruction page where you can find links to the instruction / operation manual and github for software downloads. I am happy that the cloIMG_2102ning process for SD cards is good so will be working on these from tomorrow. Just under half the early bird kits have now been shipped covering destinations from Australia to Swindon the rest should all go out over the next few days.

Posted in Uncategorized | Tagged , ,

Happy Arduino Day 2016

ard_day2016Happy Ardunio Day 2016 from the Meandering IMG_1868Pi.
We will be at the Peterborough Raspberry Jam on the 9th of April  showing off the latest work on the Tempus Fugit WordClock in both Pi Zero and Arduino Nano Versions, together with other Pi projects old and new.



Posted in Uncategorized | Tagged , , , ,

WordClock Prototype PCB Tested

IMG_1814The prototype Tempus Fugit PCB arrived as promised last week from Ragworm, leaving me just enough time to get it built up our Show & Tell at the Pi Party on Sunday. We had lots of positive feedback particularly with demonstrating the ability to swop from a PiZero to a Arduino Nano without having to make any changes to board. With 13 days to go on the Kickstarter we are just £250 short of the stretch target – adding automatic brightness control to the design.bigb

I really enjoyed the Pi Party meeting people new and old. A particular shout out to the Marshal who helped get omxplayer to loop for me and putting my wife in-touch with with someone to talk about Bluetooth.

Posted in Uncategorized

Tempus Fugit WordClock Kickstarter for your Pi or Arduino

IMG_1764aAs trailed in an earlier blog posting I have spent a bit of time over the last couple of weeks working up my Word Clock to run as a Kickstarter. The result is the Tempus Fugit WordClock. you can see in the picture  what the PCB will look like, I will update this with an actual photo in  a couple of weeks when I have got a prototype PCB build. pcb rev4The big development as you might have guessed from the blog title is that the Tempus Fugit will work with an Arduino Nano as an alternative to a Pi Zero so hopefully will still be attractive to people struggling to get hold of the Zero.

Check out the Kickstarter by clicking here.


Posted in Uncategorized | Tagged , , , , , ,

BBC Micro:Bit Hands-On

microbitWe Attended a great STEM BBC Micro:bit networking event earlier this week at Reading University, I had seen the Micro:bit at BETT but had not been able to get ‘hands-on’. The first thing to be clear is that while there is some level of overlap between the Raspberry Pi and Micro:bit they are different, both have good and bad points when you consider their target markets. Having not looked too closely at the Micro:bit before I was pleasantly surprised with the in built hardware which includes accelerometer, compass, I2C and Bluetooth, see the following link to the dedicated BBC media site to see a more complete spec. On the down side the only direct ‘display’ capability is a 5 x 5 matrix of LED.FullSizeRender1

Programming is via a browser web interface (Explorer and Chrome both seemed to work), connected via a micro USB ( I am assuming you will also be able to connect via Bluetooth in the future but this was not demo’ed at our session ). One of the key design elements is that nothing ‘special’ should need to be installed on the PC / Tablet / Smartphone to control / program the Micro:bit. A number of programming options will be available, we used the Microsoft “Block Editor” which is very Scratch like in terms of operation. Having tested your program (which you do within the programming environment), hit the compile icon and the an executable is created on a remote server application and automatically downloaded to via the your browser. You then drag this file onto the Micro:bit (which appears as a mass storage device / drive on your PC) and it is again automatically downloaded to the Micro:bit and the application runs. An option to program in Python is also shown on the website, this is not available yet but my wife did a bit of digging and found this  article  which gives a lot more info. As I understand it the only potential option for local programming on the Micro:bit will be Python, other options all seem to need good web access.

In terms of interfacing to the outside world it has 3 digital / analogue  input / outputs which come out as ‘rings’ you can connect to with small crocodile clips, there are additional functions including I2C available via the edge connector, but it is worth noting that other than the 3 ‘ring’ connections you will need a suitable socket connector to connect with.

Technical detail is currently quite limited but we were told that the stated BBC plan is that everything associated with the Micro:bit hardware will be open sourced following the launch, which I certainly support.

The question everyone who sees the Micro:bit asks is ‘where can FullSizeRender2I get one’ ? The project has been delayed but there seems to be a level of confidence that the Micro:bit card will start being sent out to schools this spring, which I take to mean April.

So my thoughts, generally positive it is certainly great fun and has enough built in capability to allow some really creative applications – there were some interesting Hacks on show at BETT.  In that it does not need a dedicated screen or keyboard / leads it does address some of the concerns leveled at Raspberry Pi in the classroom. Against this you will need Internet access to use the programming tools including the emulator. I know from running STEM sessions in schools this can still be a challenge.

I do also see some problems with the ‘ownership model’ – one is being given to every UK year 7 pupil in this school year. The hope being that school’s and / or parents will buy them in the future. The problem I can see is that on one hand schools with tight budgets will try to hang on to them to use for the future years – depriving children say of the opportunity to code at home over the holidays. While on the other side given that there will no doubt be an initial supply and demand issue some children / parents are going to want to get their hands on them simply to sell on eBay -the initial production run is for 1 million parts so hopefully stop this in time.

To finish the Micro:bit should certainly make a positive contribution to getting more young people ‘into’ programming and computers, particularly given the work that has gone to reduce any barriers to access the programming tools. Compared to the Raspberry Pi it is less suited to building more complex and / or to ‘permanent’ projects. The big unknown is if the Micro:bit will build up the sort of the user community the Raspberry Pi has.

If you want to have a play, the website including an emulator is available now.


Posted in Uncategorized | Tagged , , ,

Meandering Pi @ BETT2016 RaspberryPi JAM

We will be at thlogo_bette RaspberryPi Jam @ BETT 2016 in London this Saturday,
running a show & tell table. In addition to showing how you can use the PiMuxClock and Pi_LCD boards to support Key Stage 3 & 4 computing activities we will also have the WordClock prototype board, some sense hat stuff and anything else I can fit into a suitcase !

Posted in Uncategorized | Tagged ,

PiZero Christmas Project Complete


Update If you don’t want to go down the full DIY route you can purchase a PCB and kit of parts to make your own wordclock kit but clicking on the following link Order your Tempus Fugit Wordclock kits here


Back to work tomorrow, but happy as I have managed to finish my Christmas Pi IMG_1639project – a ‘word clock’ using a single a 8×8 matrix display and a PiZero.

I used a MAX7219 to simplify driving the LED matrix, this connects to the PiZero via the SPI port and uses a library developed by  Richard Hull to program it in Python. The character layout came from an article in the Guardian.

I used a smaller matrix kit from the internet to test the concept IMG_1632with a blog post from RasPi.TV providing some additional help !

The biggest pain was trying to get my head around the concept of a ‘common anode’ and ‘common cathode’ matrix display. The MAX7219 is nominally designed to drive common cathode 7 segment displays, which is fine but with an LED matrix life is a bit more confusing as by swapping the columns and rows around you can drive either sort of IMG_1642display with the 7219. To make matters worse matrix displays often do not have a clear marker for pin 1. Having wired everything back to front on the first attempt I found the following article on an Arduino website which was a great help  – Identifying pin 1 on 8×8 displays .

The final hardware elements are an RTC and some push buttons so the time can be set without the need for an internet connection. This proved harder IMG_1641than expected as there seems to be a problem with the latest Kernel overwriting the RTC during the boot process, I think I have found a workaround but this does need a bit more work.

The character overlay is simply printed from a table in MS Word with the letter colour set to white with a black fill.  I experimented with a  number of different fonts, the ones which work best are non-proportional ones like Courier and Monaco.IMG_1644

All in all great fun

[If you just want some more detail together with the Python code and Templates have a look at my WordClock GitHub]

Posted in Uncategorized | Tagged , , | 8 Comments

Pi Zero and the Pi-LCD

IMG_1563Got a Pi Zero working with a Pi-LCD board this evening for a bit of fun, worked fine but not well balanced !IMG_1566


Posted in Uncategorized | Tagged , ,