Standalone Video display with a Raspberry Pi

IMG_0785A couple of weeks ago my wife arrived back from Lindengate a local mental health gardening charity she volunteers at with an old PC monitor and asked if I could set it up to continuously display a series of videos, she had created to highlight the charities work. Typically the when was the following week and the where was a local doctors surgery. The when meant I was limited to ‘in stock’ parts and the where meant untended operation in a public place. I knew there were various existing instructions for doing this sort of thing with a Raspberry Pi and after a bit of internet searching found an article for a video looper on the Adafruit website which simply automatically plays video files from memory stick  inserted into one of the Pi’s USB sockets. I tried this out on a Pi3 and it ticked all the boxes in terms of play back and ease of use, so that was the s/w sorted.IMG_0782

Looking at where display was going  it needed not only to start-up without the user having to do anything but also not look too much like a DIY project built out of parts from my garage one night !  To get the size down I moved to a Pi Zero, with a VGA converter dongle [VGA being the only input available on the monitor] and a short micro USB to ‘type A’ converter lead. This all worked fine but did leave the perennial problem of how to safely turn the Pi off. Given a keyboard or VNC connection was out of the question I opted to fit a on/off switch to the Reset / run connector on the Pi. This way we could include a clear instruction to set this switch before removing the power. Now on paper I know this is not the best way to power down a Pi but in practice I have found it does seem to avoid corrupting the SD card.

IMG_0700Once tested this was all packaged in a small box  left over from another project. This I was able to mount on to the back of the monitor using one of the VESA mounting points on the back of the screen. The end result looked really quite professional with no unnecessary bits of wire hanging out !




So far the display has been put to good use in the doctors surgery and at the charities Autumn fair. The total parts cost excluding the monitor was around £32 using a Zero 1.3

Link to the Lindengate Facebook page

Posted in Uncategorized | Tagged , ,

BBC micro:bit Scrolling display

IMG_0682(1)Looking at my distributed BBC micro:bit clock I got to thinking, could I make a display screen using a number of micro:bits, using the radio functionality to update the screens ?To see if the basic timing would work I created some very rudimentary code on 4 micro:bits. Initially I tried to use the ‘display.scroll’ function. After much fiddling I did get this to work after a fashion, but in truth it looked rubbish. On the point of giving up I thought I would see what it would look like using the ‘’ function. This produced a much more readable result so I decided IMG_0694to go on and develop some ‘proper code’. I had previously looked at with David Whale’s python ‘microbit’ module and this seemed a great way to get the text strings ‘into’ the micro:bit. which solved the problem of how to front end the display. The remaining s/w built used in my distributed micro:bit clock.


The software for the scrolling display has 3 elements;
[the pink x in the names indicates the rev number where I plan to develop the s/w further]

1) The micro:bit display node application []

This is a simple python app you need to download on to each of the micro:bits that form the message display. The s/w for each micro:bit is identical. The software listens using using the radio function for any messages addressed to it coming from the gateway micro:bit displaying any valid character using the function. It will keep displaying this until it receives a new valid message. The address of each display node is set the first time the s/w is run (normally this would be directly after download). The micro:bit will display a ‘?’, to show the address needs to be configured. The address is set using button ‘a’ and once correct store it using button ‘b’ – the address is stored in non volatile memory. On subsequent restarts it will be automatically selected, but you can change it by holding down button ‘a’ and resetting the micro:bit.

2) the micro:bit scroll display gateway application []

This is a somewhat more complex python app, performing 4 functions receiving messages from the Pi, creating the scroll effect, segmenting the message and finally transmitting the individual character information to the display node micro:bits.

Information is received from the Pi via a USB connection, this is described further in the RPi gateway application section.

Message format

The basic message format is <type><message>. ‘type’ is either ‘1’ to display a static message or ‘2’ for a scrolling message. So for examples if the gateway micro:bit receives the following message ‘2HELLO WORLD’ you would see ‘HELLO WORLD’ scrolled across the display node micro:bits. This would be repeated until the next message is received.
Static messages are automatically truncated to the number of characters in the display. If you want to see how the scroll process works the best way is to look at the python code but in simple terms I create a shift register in s/w and simply cycle it.

Setting the number of nodes

The gateway micro:bit needs to know how many display nodes it is talking to, this is set the first time the s/w is run (normally this would be directly after download). The gateway micro:bit will display a ‘D’, to show the number of nodes needs to be configured. This is set using button ‘a’ and once correct stored using button ‘b’ – the number is stored in non volatile memory. On subsequent restarts it will be automatically selected, but you and change it by holding down button ‘a’ and resetting the micro:bit.

3) The RPi gateway applications

The gateway application running on the RaspberryPi communicates with the micro:bit gateway via a USB connection, using a python module called ‘microbit’ (thanks to David Whale) for telling me about this – here is a link to his github. To date I have just written a few demo applications using the microbit module. When you first run an application using the microbit module it will take you through a setup process to allow the s/w to identify USB connection name. It will attempt to use this name for future connections. If this fails you will need to go through the identification process again, you may also need to restart the Raspberry Pi. The 4 apps I have currently uploaded on to GitHub are;

  • A simple program to display a user inputted string,  []
  • A clock demo []
  • A Tweepy application which will scroll any messages with a specific prefix. []
  • A basic GUI that allows you to scroll / show strings or display time in a range of formats [scroll_GUIx.pyw]

The GUI app is my first real attempt to use Tkinter and I am sure I have broken a number of, but it seems to work and was interesting to code


One of my goals in developing the scrolling display was to avoid any extra hardware or the need for expensive sockets etc. To get the best effect the node micro:bits need to be mounted in a straight line as close together as possible. The mounting board I used is just a bit of fibre board I had spare. Having worked out the required spacing I drilled a series of 3mm hole, then used 2.5mm stand-offs and screws to mount using just the 0v and 3v ‘holes’. Using 3mm img_0697-e1505571864514.jpgholes with 2.5mm screws gave a bit of ‘slop’ to get everything aligned neatly. You can find a copy of the dimensions I drilled to at the end of this post.

Initially I just used individual batteries to power each micro:bit. Once I was happy the with the mechanical arrangement I found a suitably rated 3.3v supply and changed to power the node micro:bits via the GND and 3v pins – if you go down this route you need to be very careful as an error here could end up destroying all the node micro:bits. Also most importantly you have to include a diode on the 3V line.IMG_0671(1)

This stops a micro:bit ‘back powering’ all the others when you are downloading code to it via the USB line – I am guessing the USB supply on the micro:bit is not rated to drive 10 micro:bits ! You can see how it is wired up in the picture below



Rear wiring detail


Front face of 10 digit display


The dimensions I used for drilling the mounting board


You can have a look at some short videos of the scroll display working on my YouTube channel

Initial demo

10 digit display demo

Tweet display demo


Posted in Uncategorized | 1 Comment

Distributed BBC micro:bit Clock

IMG_0619The idea for this project came from a tweet by David Whale [@whaleygeek] showing a font he had come up with for the micro:bit that managed to squeeze 2 digits on to the 5×5 led display. I have taken initial clock code he wrote and added functionality to read a Real Time Clock module connected via the I2C port together together with some other bits.

The time display is spread over 3 microbits [ 2 if you don’t want seconds ], these communicate using the radio function in micropython . You can also have a single micro:bit with a scrolling display. There is no limit to the number of slave micro:bits, but do only connect the RTC to a single micro:bit.IMG_0581

The clever bit, [well I think it it is !] is that all the micro:bit’s all run exactly the same code. You configure the display to hours / minutes / seconds or scrolling by connecting the P0-3 lines high. The software automatically identifies if it has the RTC connected to it and if so makes it’self the master synchronizing the other micro:bits every minute.

The whole thing is written in micro-python programmed using MU running on a Raspberry Pi. You can find instructions on how to install the latest version of MU in the micro:bit section of my site.  The code listing is commented so you can sort out which bit does what. If you want to change to code it is worth noting that it basically maxes out the available micro:bit memory as it stands.

IMG_0620Hardware, it is really up to you, I have used small ‘maker’ interface boards I got made to up allow me to mount the micro:bits vertically on a bit 0.1″ matrix board, but you can easily use one of the commercially available breakout boards. The RTC is a DS3231 RTC module. The only other bit I added was a simple 3.3volt PSU using a 78L33 and microUSB adapter board.IMG_0587(1)

if you don’t want to build the power supply you can simply power one of the micro:bits from it’s battery or micro:USB connection and it will feed the others and RTC.

You can download the micropython code and also a basic schematic showing how I connected all the bits from my GitHub .  (Do make sure you download the latest version of the code)

There is also a short YouTube video of the clock here


Posted in Uncategorized | 1 Comment

Cheap DIY Weatherproof Pi Camera

IMG_2453Always thinking about useful things I could do with a Raspberry Pi my wife asked me about making a time-lapse camera to record some building work at Lindengate, a local mental health gardening charity she volunteers at. While there are a number of Pi camera weatherproof products in the market the challenge here was to spend as little money as possible. You can see one of the short films my wife created using the camera by following this link to Lindergate’s facebook page.

The detail of the build is follows….


From a practical perspective the camera needed to be left unattended for at least 3-4 days at a time, not a problem from a storage perspective but it was an issue in terms of power the site is quite spread out and there was no practical way to get power to the place she wanted to film from.


The obvious logical choice of electronics was a Pi Zero and Pi camera, then looking around the garage a realised that if I stripped out the internals from a spare security light I could easily attach the pi to the glass window using a ‘zeroview’ I already had – effectively for free. This setup also have the advantage of not looking very interesting as people are used to seeing this sort of security light around.


Rather than try and fit batteries inside the enclosure I opted for taking out a lead  long enough to get to a separate waterproof box with the power supply in. As you can see in the picture I have soldered the power lines onto the Pi, this was simply because I did not have a long USB to micro-USB cable.

The only other change I made was to include a light dependent resistor [LDR] this is attached between GPIO pins 39 [0V] and 50 [GPIO 21] and is mounted through the zeroview board by cutting a small slot with a needle file. The GPIO 21 line is configured as an input with the weak internal pull up resistor enabled. This creates a potential divider so a low on this pin indicates daytime, a high darkness. This allows me to keep power usage to a minimum by not taking pictures after dark. This setup also avoided the need for any extra components other than the LDR.



There is no accessible wifi on the site so to download the captured pictures I simply plug in a USB wifi dongle to a short micro-USB to socket lead I brought out of the enclosure. Then connect via a laptop running VNC and locally a ‘created’  temporary network using a HooToo Wireless Travel Router.  Again this kept the power down as I could disconnect the dongle when not needed – protecting the USB connection with a plastic bag !


IMG_0563I tried a number of different power solutions the simplest being USB battery packs, with a large one I could get about 6 days, but main difficulty I had was that newer ones include a sensing circuit that shut the outputs down if the power drain is below a certain level. So they are fine to run a normal pi 3 but with the zero I found that periodically they would turn off which was not not much use. So going back to the garage I found a car battery, 12V to 5 volt converter and a solar panel from previous ‘projects’. With this combination I have kept the camera powered for over 2 weeks in good weather without a problem. I am doing a bit more work on monitoring the power usage so  I can understand how long it is safe to leave the camera for, a bit better – that will be the subject of later blog I hope.

I kept the s/w really quite simple – you can download a copy of the code from my github.  It is set up to take a picture every 10 minutes, but you can change this. The resulting pictures then stored in a single folder. The software is actually a cut down version of program I use to capture and upload pictures of our chicken run to the net !  It is setup to auto run on power up – you can see how I do this here on my site.

The actual video was created using iMovie on a mac portable but there are a variety of other free and paid for editing packages that will allow you to stitch still photos together to make a film. You can see the results here on Lindergate’s facebook page.


The new cabin mid build





Posted in Uncategorized | Tagged

micro:bit Analog Inputs

IMG_0541(1)For the last few days I have been playing with the micro:bits builtin capability to measure analog voltages on P0, P1 & P2 (you can set up some of the other IO lines as analog inputs but this is a bit of an involved process and best avoided if possible).




By default the analog converter in the micro:bit is referenced to the micro:bit supply rail and is configured for 10 bit operation. Hence the following code;

from microbit import *
a = pin0.read_analog()

will return 1023 if you connect the 3V & P0 pads together, irrespective of battery condition of if you power via the micro USB connector. For many applications this is fine and using the micro:bits 3V supply as the source voltage for any analog experiments is the best way to minimize risk of damage the the micro:bit.

However if you want to measure a voltage not derived from the micro:bits supply things can become a bit more problematic. It’s fine if you can power the micro:bit from a constant source – for instance a phone mains power adapter, but not so good if you are running from a battery. This because as the ADC (analog to digit converter) reference voltage will drop as the battery discharges resulting in a change to the count value returned. For instance assuming a new set of batteries provides 3V, a 1.5V source on P0 would return 512, but if the battery voltage drops to 2.5V the reading would change to 614 counts. To get around this the ADC in the micro:bit can be configured to reference an internal fixed 1.2V voltage reference. This means the count value will not vary with a changing supply voltage.IMG_0547(1)

In it’s basic setup this would mean a voltage of 1.2V on P0 would give a result of 1023. However 0-1.2V is quite a small range so the ADC circuit includes a configurable ‘pre-scaler’ to help us. Configuring this to 3:1 we get full scale ADC range of 0-3.6V. It is important to note however that the rule of keeping the maximum voltage applied to a micor:bit input pin at or below the supply rail still applies. 

The following code will setup the ADC to use the internal reference on P0 together with a 3:1 pre-scaler.

Code to demo using the micro:bit internal ADC reference 
# based on material and help from Carlos Pereira Atencio
# David Saul 2017. Released to the public domain.

from microbit import *

NRF_ADC_BASE = 0x40007000

# functions used to modify ADC setup
def reg_read(r0):
 ldr(r0, [r0, 0])

def reg_bit_clear(r0, r1):
 ldr(r2, [r0, 0])
 bic(r2, r1)
 str(r2, [r0, 0])
# change ADC config for pin0

# mbed configured: 10bit, input 1/3, ref 1/3 vdd, enable ADC in AIN4-P0.03-pin0
#Set ref voltage to internal ref 1.2V (band gap), set bits 5-6 to 0x00
reg_bit_clear(NRF_ADC_CONFIG, 0x60)
print("ADC config should be 0x100A: {:#010x}".format(reg_read(NRF_ADC_CONFIG)))

#variable definition
vt = 0 # raw / scaled analog value
vf = "0000" # measured voltage as a formatted string 
cal = 352 # calibration variable
# cal is calculated as (Vin / raw count)*10000
while True
 vt = pin0.read_analog()
 print ('raw count = ',vt)
 # the following lines of code scale the measured value and derive a
 # string (vf) that equates to it - there are simpler ways to do this
 # but this method avoids the use of floating variables which are very
 # inefficient on cards like the micro:bit
 vt = int((vt * cal)/1000) 
 vs = str(vt)
 if vt > 1000:
  vf = vs[0:2]+'.'+vs[2:3] 
 elif vt > 100 :
  vf = vs[0:1]+'.'+vs[1:3]
 elif vt > 10 :
  vf = '0.'+vs
 elif vt > 1 :
  vf = '0.0'+vs
 else :
  vf = '0.000' 
 vf = vf+"V"
 print ('Scaled', vf)


link to code on GitHub

The ‘keep to the rail voltage’ is a generally safe but slight simplification of the ADC operating rules. If you are looking to work with source voltages not limited to the micro:bit supply rail there are specific rules you need to be aware of to avoid damaging your micro:bit. A number of discussion threads have been written on these [ probably because it’s not very understandable in the NORDIC chip datasheet ] one example which is ‘relatively’ clear is




Posted in Uncategorized

Meandering Pi and Friends

IMG_0406(1)Over the last couple of months I have spent quite a lot of time experimenting with the BBC micro:bit developing various things including a model train speed controller.  This uses 2 micro:bits one acting as a remote control the other providing a PWM drive to the track. They communicate using a simple 2.4Ghz radio connection builtin to the micro:bit [you sort of get it free with the Bluetooth] .

You can get more details on it’s dedicated project page .

One thing which has been great to discover is that the Raspberry Pi works really well as a desktop environment – to program the micro:bit, either using one of the online tools such as the C/C++ mbed environment or standalone with the micropython ‘mu‘ application.

If you want more information I have created page focused on using the raspberry Pi to program the micro:bit.


If you haven’t had a play with the micro:bit I really recommend you get one and have a go. They are not a raspberry pi and never will be, but in terms of getting the ‘barrier to programming’ as low possible it is difficult to beat – not least you can be up and doing something in seconds from unwrapping it.

In recognition that I am now talking about more than just Raspberrry Pi’s on this site I am changing the name of the blog to  Meandering Pi and Friends . Hopefully I will be posting to my blog a bit more regularly as well …..


Posted in Uncategorized | Tagged ,

RGBtree Working on an Ardunio – Yay

img_2610Having got the Pi variant of Andrew Gale’s RGBtree working nicely I thought I would use some spare time over the last couple of days to setup the alternative Micro:bit/codebug  version on a Arduino Uno clone, for a bit of fun. Cobbling various bits of Ardunio code together I now have an RGBtree that can will play one of  5 different Christmas songs, when the switch is activated – while running through a random series of colour changes in time with the music. Once the tune has finished playing the Neopixels will continue to change randomly. You can download the code from my Github here. I have also uploaded a quick video to YouTube if you want to see and hear it in action !   .

The music uses quite a lot of the Arduino’s ‘variable’ resources, so Iimg_2610 have kept the Neopixel effects simple here. I did not have to make any changes to the RGBtree to get it working with the Arduino, but do be careful if you change from the default brightness settings as the Neopixels can get very bright. The RGB tree is supported on two pins that I was able to position spaced correctly to pickup 5V and GND on the Arduino board. [The Neopixels seem fine working at 5V rather than the labeled 3V.]

I think it is relatively obvious from the code if you want to adapt the code to play different tunes – the size and number of tunes is limited by the ‘variable’ memory size of the Arduino. I guess you could change it to store the tune data in program memory which would greatly extend the storage as an option.

Posted in Uncategorized

An RGB Tree Happy Christmas

img_2581A big thanks to Andrew Gale for getting a missing RGB  tree to me in time for Christmas. To celebrate (and avoid the wrapping),  I’ve cobbled together a quick Python App that gently runs through the spectrum on each of the LEDs in a random order. You can down load it from my git hub here (The colours look a lot better in real life).

Now the next question do I get on with wrapping or see if I can get it working with an Arduino …..


Posted in Uncategorized | Tagged , ,

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 , ,