Third party cookies may be stored when visiting this site. Please see the cookie information.

Home Family Days Out Raspberry Pi & Electronics Blog

Stewart's Blog

Stewart Watkiss website to the world ...

(Children, computing, first aid and other ramblings ...)

New Book – Beginning Game Programming with Pygame Zero

February 14th, 2020

Beginning Game Programming with Pygame Zero book
This is my second professionally published book, published by Apress.
Beginning Game Programming with Pygame Zero.

The is a fun way to learn computer programming by creating computer games. This is designed as a book to give you all the skills you need to start programming your own games, from designing the game, creating the graphics, designing sound effects and programming using Pygame Zero. It’s designed for use on a Raspberry Pi, but you can also code on any other computer which has Pygame Zero installed.

You can see my introductory video below.

More information for Beginning Game Programming with Pygame Zero

NexDock 2 – Laptop style screen and keyboard for Raspberry Pi or mobile phones

January 7th, 2020

A few years ago I backed a Kickstarter project for the original NexDock for use with the Raspberry Pi. Last year they created an updated version called the NexDock 2. A new improved version.

NexDock - laptop style dock without a processor

You can see my NexDock 2 unboxing and review video here, or read on for more information.

What is a NexDock?

A NexDock looks like a laptop, but it’s missing one thing, a processor. It has a screen, keyboard (with touchpad) and battery in a laptop style shell. It cannot work as a laptop until you connect it to a computer.

So what’s it used for? Well most people now carry a fairly powerful computer in our pocket, it’s a mobile phone and the two things that stop it being used as a computer are a decent sized screen and a keyboard. Put the two together and you have what is effectively a full computer. That is one way that I’ve used the NexDock but for more I found it particularly useful when used in combination with a Raspberry Pi. It provides a quick and easy way to connect to a Raspberry Pi which may be embedded in a Robot, inside a model house, or even in a wearable snowman badge.

NexDock 2 with a mobile phone – Samsung S8 Dex

Firstly I tried by connecting it to a mobile phone. It works with a number of Android phones with a USB-C connector, in my case a Samsung G8. The Samsung phone includes Dex which provides a full laptop like environment which works well with the phone. Many apps can expand to use the full screen, although not all Android apps support that. The main thing for me is that it allows you to send emails or write documents using a keyboard instead of the on-screen keyboard.

NexDock 2 - using a Samsung Phone (G8 or later) as a computer using Dex (USB-C)

NexDock 2 with a Raspberry Pi

The NexDock 2 appears to work with all versions of the Raspberry Pi. This is an improvement over the earlier NexDock which struggled with the Raspberry Pi Zero. Also the NexDock 2 no longer uses Bluetooth so you don’t need to find a temporary keyboard whenever the bluetooth fails to connect. This does mean that you have to connect a physical cable for the keyboard to work, but then you have to use a HDMI cable anyway. This is a big improvement on the older NexDock.

NexDock 2 - using a NexDock as the screen and keyboard for a Raspberry Pi laptop style

Supplied cables and accessories

There is a good selection of supplied cables and adapters as shown in the photo below:

Cables and accesssories supplied with the NexDock 2

The NexDock 2 is powered from a USB-C charger which is included along with different adapters for different country sockets (a big improvement on the travel adapter supplied with the previous version). It also includes all the cables that you will need to connect to a USB-C smartphone, Raspberry Pi (1 to 3) and Raspberry Pi 4. If using a Raspberry Pi Zero then you will need to source your own mini-HDMI to HDMI adapter (or cable) and a micro-USB OTG adapter, however most people with a Pi Zero will likely have these already. The cables are all fairly short, which should work with it’s designed use, but it’s easy enough to provide your own longer cables if you need anything extra.

Any issues?

So far I haven’t come across any major issues. It appears to work with my mobile phone and different versions of the Raspberry Pi.
If there was one thing I would change it would be to include a UK keyboard layout. I accept this is difficult to do on a Kickstarter project, but it would be a big improvement. The reason being that when using a Raspberry Pi then you may need to make use of some of the special characters that need different key combinations. Changing the keyboard layout each time you connect a NexDock versus a UK keyboard is a bit of a pain. For me the main thing is some of the keys used on the Linux command line which I had to find through trial and error.

Other than that any other things are very minor.


I don’t use the mobile phone Dex very often, but that is a useful thing to have. For me the main reason for the NexDock 2 is to connect to a Raspberry Pi either during initial setup or when it’s connected as part of a project. For that the NexDock 2 is great. It provides a reliable keyboard and screen which is much easier than lugging a standard monitor around. It also includes a built-in battery which can even power the Raspberry Pi.

If you regularly need to connect to a Raspberry Pi when you don’t have a screen to hand then I highly recommend getting a NexDock 2.

Missed the Kickstarter? You can pre-order using the link below.

Using a gamepad or joystick on a Raspberry Pi with Pygame Zero QJoyPad

December 10th, 2019

Pygame Zero is an easy way to get started in game programming. It used Python Pygame, but makes getting started easier by reducing the amount of code required.

I’ve previously created a tutorial getting started with Pygame Zero programming.

One feature that is missing from Pygame Zero is support for joysticks or gamepads. It is listed as a feature they want to add in future but it hasn’t been implemented yet (see Pgzero issue 70).

In the meantime here is a workaround that I have found useful for playing games using a gamepad, joystick other other game controller. It works by having the gamepad emulate the keyboard. The example I show here is for Linux (including the Raspberry Pi), but there alternatives for other operating systems such as Antimicro for Windows and enjoyable for MacOS. The software used here is for Linux and is called QJoyPad

Wireless USB Controller for the Raspberry Pi

You can watch a video of how to configure QJoyPad below, or keep reading for more information.

First install qjoypad. This can be installed from the command line using:

sudo apt install qjoypad

You then need to launch QJoyPad from the games menu. This adds a small icon on the right of the task bar. You then need to configure the keys. Click on the gamepad and it will detect any connected gamepads or joysticks and allow you to configure them. In the screenshot below this is a Raspberry Pi Wireless USB Game controller from ThePiHut. If your gamepad / joystick is not shown then you need to make sure it is supported by the operating system and that it’s connected. Most USB game controllers should work. In my case a quick look at dmesg shows that it is recognised as a X-Box controller

[1278236.150562] usb 1-1.4: new full-speed USB device number 5 using dwc_otg
[1278236.290054] usb 1-1.4: New USB device found, idVendor=045e, idProduct=028e, bcdDevice= 1.10
[1278236.290080] usb 1-1.4: New USB device strings: Mfr=1, Product=2, SerialNumber=0
[1278236.290093] usb 1-1.4: Product: XBOX 360 For Windows
[1278236.290104] usb 1-1.4: Manufacturer: ShanWan
[1278236.371547] input: Microsoft X-Box 360 pad as /devices/platform/soc/3f980000.usb/usb1/1-1/1-1.4/1-1.4:1.0/input/input7
[1278236.372634] usbcore: registered new interface driver xpad

Clicking on the controller icon gives the option to configure each of the buttons as shown in the screenshot below. The number of buttons and controls shown will depend upon the number of buttons and joysticks your game controller has.

Gamepad configuration screen for QJoyPad keyboard emulator for Linux Raspberry Pi

You can then configure each of the controls by clicking on the relevant item. You can see which each axis or button is on the controller by pressing those controls.
The table below shows some common buttons:

QJoyPad reference Raspberry Pi Wireless USB Raspberry Pi Wired Gamepad XBox wired controller PS4 controller*
  Wireless USB controller on Raspberry Pi Wired USB controller on Raspberry Pi Xbox controller used on Raspberry Pi PS4 Controller controlling games on a Raspberry Pi
Axis 1: Left analog joystick – left right Direction buttons – left right Left analog joystick – left right Left analog joystick – left right
Axis 2: Left analog joystick – up down Direction buttons – up down Left analog joystick – up down Left analog joystick – up down
Axis 3: L2 button   Left trigger L2 trigger
Axis 4: Right analog joystick – left right   Right analog joystick – left right Right analog joystick – left right
Axis 5: Right analog joystick – up down   Right analog joystick – up down Right analog joystick – up down
Axis 6: R2 button   Right trigger R2 trigger
Axis 7: Direction buttons – left right   Direction buttons – left right Direction buttons – left right
Axis 8: Direction buttons – up down   Direction buttons – up down Direction buttons – up down
Button 1: Blue cross Blue X Green A Blue cross
Button 2: Red circle Red A Red B Red circle
Button 3: Pink square Yellow B Blue X Green triangle
Button 4: Green triangle Green Y Yellow Y Pink square
Button 5: L1 button Left trigger Left bumper L1 button
Button 6: R1 button Right trigger Right bumper R1 button
Button 7: Select   View button L2 Button
Button 8: Start   Menu button R2 Button
Button 9: Analog button Select XBox button Share
Button 10: Press left joystick Start Press left joystick Options
Button 11: Press right joystick   Press right joystick PS4
Button 12:       Press left joystick
Button 13:       Press right joystick

*PS4 was tested cabled via a USB cable

You can then map these to the appropriate buttons for your game. The following are the ones I have mapped for the USB wireless controller which is similar to the keys used in the Picade Arcade Machine.

Axis 7 and 8 – Direction Arrows
Button 1 – Z
Button 2 – Left Alt
Button 3 – Left Ctrl
Button 4 – Left Shift
Button 5 – X
Button 6 – Space
Button 7 – Return
Button 8 – O
Button 9 – Escape
Button 10 – h
Button 11 – l

The other buttons are not mapped.

You can test the keys using which is a simple Pygame Zero program that I created.

WIDTH = 800
HEIGHT = 600

last_key_type = 0
last_key_press = ""

def draw():
    screen.draw.text("Last key press: "+last_key_press+" key: "+str(last_key_type), (20, 100))

def on_key_down(key, mod, unicode):
    global last_key_press, last_key_type
    # Double press q to quit
    if (last_key_type == keys.Q and key == keys.Q):
    last_key_type = key
    last_key_press = unicode

You can map the keys differently depending upon the keys required by your particular game or your preference for the particular keys. Note that the analog joysticks will be mapped to key presses rather than having an accurate position of how far over the joystick is held.

When you are happy with your layout you can save it using the Add button and giving it an appropriate name. You can then close the dialog and QJoyPad will continue to run in the background.

The config is saved in ~/.qjoypad3 with the layout name followed by .lyt.

You can see the Wireless controller in use with the SnowPi badge with built-in game.

Fixing 3D printer first layer problems – sticking to the bed

August 29th, 2019

I have had a 3D printer for about two and half years now and I’m still learning. One of the biggest problems I have had is problems with getting the first layer to stick to the print bed. This is a common problem, but not one that I’ve been able to find a simple solution. Until now!

The Printer – Wanhao i3 Plus

The printer I have is a Wanhao i3 Plus 3D printer.

Wanhao i3 Plus 3D printer

It’s a reasonably priced printer which has a simple setup procedure. I am happy with the quality of the prints, but since day one I’ve been having problems with getting the prints to stick to the printer bed. I now believe that the printer bed is at least partly to be blame, but there are a number of things that I tried. These are all valid things to try and in fact all these need to be correct before the final solution. Before I came up with the final solution my success rate appeared to be getting better. I had thought that it was because I was getting better at adjusting the settings (which would have had some effect), but in reality I found that it was because the print bed covering was getting worn and that meant the prints were sticking better. When I replaced the print bed the problem with it sticking was almost as unreliable as when I first got the printer.

It’s still important to get the basics right so all the suggestions are worth looking at.

Height of the print head and leveling the printer

I’ve covered these two together as they are both carried out together.

The height of the print-head is the distance between the print bed and the print head (actually the hotend which is part of the extruder assembly). This gap should be 0.1mm, which is approximately the same thickness as a sheet of printer paper. If the gap is too big then the filament is being dropped over the bed and will not stick to the bed. If the gap is too small then the filament will be pressed down too much or may not come out of the print head.

The printer base also needs to be leveled correctly as if you have the correct gap at one side, but a different gap at the other then the same problems will apply.

The way to adjust the gap between the print head and the bed depends upon the printer. It could mean adjusting the height of the bed or the position of the print-head. In fact it may involve both, but that is usually during the initial setup as once you have fixed one of these the amount of adjustment needed should be very small.

In the case of the Wanhao i3 plus there are some thumbscrews underneath the print bed that tighten or loosen the distance between the bed and the base of the printer. There is a print leveling option on the screen which moves the print head to 4 different positions (front-left, front-right, rear-right, rear-left). At each position the appropriate thumbscrew needs to be turned so that the paper fits between the print-head and the print bed. In my case I adjust it so the paper can move but that you feel some resistance when moving it.

This is one of the most important adjustments which needs to be correct.

Different filaments

Not all filaments are made equal.

The different filaments available can stick differently to the print bed. I have avoided using the word quality as it may be that some cheaper filaments don’t stick and some better quality filaments do stick, although I do think that sometimes buying better quality and possibly more expensive filament can help. These are the brands that I currently use, but this by no means suggests that other brands would be worse.

The different types of filament can also have different amounts of “stickyness”, which even applies to different colours. I’ve found PET-G and metalic coloured PLA are harder to work with compared with base coloured PLA.

This becomes less important later as I have had more success with various different filmament, although I still think it is worth buying a good quality filament

Different extruder temperature

The extruder temperature can also affect how well the first layer sticks. This doesn’t appear to be as important as the other factors, but it’s worth experimenting with different temperatures. Make sure you are working within the specified range from the manufacturer.

Catching the pre-print

One of the problems I find is that prior to starting printing the 3D printer pushes out a bit of filament. If this sticks at the correct point then it can be useful, but more often than not it just sticks to the end of the hot-end and gets dragged around until it sticks somewhere it’s not supposed to. I’m now prepared for this by having a pair of pliers / tweezers read to grab that bit of filament as soon as it looks like it’s going wrong.

Different bed temperature

If you have a heated bed then that can also help. I found that hotter temperatures (around 60°C) would improve how well the first layer stuck, although some PLAs recommend lower temperatures so you should stay within their guidelines. The problem with hotter temperatures is that it increases the amount of warping when the print cools. I’ve now gone back to using lower temperatures for the print bed.

Different print bed coverings

I also tried adding different coverings to the print bed. One of the recommended materials is blue painters masking tape (as shown in the photo above). Whilst some people have reported better print with the tape I didn’t find it worked very well. It is perhaps more popular with those using ABS rather than PLA.

Cleaning the print bed

Cleaning the print bed can help. If the bed is dirty, such as oil from fingers or from the general area then it can prevent adhesion. I found that methylated spirit is particularly good at cleaning the print bed prior to use.

Build plate adhesion option in slicer

One option in 3D Printer slicer tools is print bed adhesion. This is something that is controlled in the software, before sending to the printer. I normally use Ultimaker’s Cura, but there are other alternatives such as slic3r. Selecting this option will print additional material around the base of the object to help it stick better. This is something I do anyway as I find it can also help with stability problems or if there is some stray filament at the start of the print. It is normally turned on by default so you don’t normally need to do anything to use this option.

Special 3D printer Glue

The above aspects are all important to get right first, but the solution I have come across which works very well is glue. I first tried a couple of different glues such as hair spray and watered down PVA, but they didn’t work very well. In the case of the PVA glue it left a horrible coating all over the print bed which took weeks to get rid of.

I finally found a good glue from the 3D Meetup UK (3D printer event) in Birmingham. I was actually running a workshop there on Pygame Zero for Makers. At the one of the sponsors was 3D Printz who gave free samples of Magigoo Print Bed Adhesion Solution. I thought I’d give it a try and my first print worked fine, so did my next and more and more prints worked reliably. There are still some occasional problems when the filament doesn’t come out cleanly, but my success rate has increased dramatically. Not only that, but the glue it’s easy to apply (glue stick), easy to remove the print (wait for it to cool) and easy to clean off with a damp cloth.

Magigoo 3D printer adhesive - fix first layer print problems

The catch, it is expensive. At the time of writing this there is actually a promotion on, but normally the large bottle is over £40 which is as much as two reels of PLA. It does provide a reasonable amount of glue, but it couldn’t be described as cheap.
Is it worth it? In my opinion definitely! The amount of time I have wasted in failed prints more than justifies the cost and on top of that there is the wasted PLA from the failed prints.
If you are having problems with your filament sticking to the 3D printer bed then after checking print gap and leveling give Magigoo a try.

Here’s a video of how to level the bed and then the Magigoo in action.

Note: This is purely my own opinion. Whilst this website does include affiliate links to help with the costs of running the site, that is not the case for the links for Magigoo. I have not received any money, goods or promises of such for writing this article.

Camping trip to Bala Lake in Snowdonia Wales

August 16th, 2019

This year our main holiday was at Easter. We still wanted to do something during the summer but having spent a lot on the previous holiday it needed to be something less expensive. One option was for a camping trip. Our son loved the idea, but not so much our daughter. It’s not that she doesn’t go camping (she had been on a Scout camp just a few weeks before), but didn’t want to go this time. So we decided to have a Father and Son camping trip without the rest of the family. My son is really into trains and planes, so we used that as a theme for the holiday, with a bit of watersports as well.


We booked a pitch at the Bala Camping and Caravanning Club site. The Camping and Caravanning Club sites are usually of a good standard, but lacking some of the entertainment that you get with more commercial sites. That suited us fine we planned to be too busy for entertainment anyway.

We do like to have electricity on our camping pitch, mainly for our camping fridge, but also useful for mobile phone charging etc. You often need to book quite early to get a pitch with electricty during holiday periods, I think we timed it just right this time.

Camping at Bala Lake - caravan and camping club site

We drove to the site, shortly after the earliest arrival time of 1pm. Staff were very friendly, they gave us a choice of two pitches and we pitched the tent. As it was just the two of us we took the smaller of our two family tents, which is a Woburn 400, with awning, the other one is a large 6 person Kampa air tent, which is actually easier to pitch, but bigger than we needed.

We got the tent up just before it started to rain. It was then time to go off to our first activity.

Snowdon Mountain Railway

As my son enjoys trains then argubly the most novel train in the UK is the UK’s only Mountain Railway which goes to the summit of Snowdon. We had been planning the trip for a while, but I only got around to booking the tickets for the railway about a week and half before. As a result almost all the tickets were gone. This took me as a bit of a surprise as I though that would be ample time, but it seams like there are more days-out activities that need to be booked a month or more in advance. If you want to go on steam (rather than diesel) train then it may need to booked even longer in advance.

We were able to get a ticket, but it was on the last train of the day at 5.30pm. The trip is 2½ hours long which includes half an hour at the summit, so that that meant getting back to the car at 8.00pm.

We arrived at the station about an hour before the train was due to depart. We parked at the pay car park opposite and then went to the ticket office to collect the tickets. When we did we were told that there were a few spaces on the earlier train and would we like to go on that instead. That was better timing for us so we took it.

The trip on the train was a good experience, but unfortunately there was a lot of cloud at the top, so we didn’t actually get to see any of the magnificant views. In fact we could hardly see each other, let alone any nice views.

View from the top of Snowdon Mountain Railway - typical wet day

Ffestiniog and Welsh Highland Railway

Day 2 involved an early start as we wanted to visit both the Ffestiniog and Welsh Highland Railway. It would be (almost) impossible to go the full length of both railways in the same day, and would mean spending the whole day on the trains, so we decided to do a bit on each railway. We drove to Porthmadog, whilst not the closest station to us it meant that we could use that as a base to visit both railways with maximum flexibility. We started with a short ride on the Welsh Highland Railway as that had fewer trains during the day. We took the train from Porthmadog to Beddgelert and spent half an hour exploring the village and shops before returning on the next train. Beddgelert is a nice picturesque village well worth visiting.

Garratt Locomotive on the Welsh Highland Railway

We then took the Ffestiniog railway (which had a 10% discount when we showed our receipt from the Welsh Highland Railway). We bought a half-way and back ticket which went as far as Tan y Bwlch. There was no opportunity for sight seeing at Tan y Bwlch (except by waiting for the next train in about 1½ hours time, so we just switched train. It was still a pleasant train journey.

Scenic view from the Ffestiniog Railway in Wales

The real highlight for my son was seeing two novel locomotives that are commonly associated with each of the railways. The Garratt Locomotive on the Welsh Highland railway, which is unusuable because it has a double articulation with the boiler in the middle and an “engine” at either side of the boiler.
The Double Fairlie is on the Ffestiniog Railway which is a single engine with two boilers mounted in separate power trucks. This gives the appearance of two locomotives fastened together back-to-back.

Bala Lake Railway and Canoeing on Wales largest natural lake

On the way back from our trip to the Welsh Highland and Ffestiniog railway we scouted out Lake Bala, looking for where we would visit the following day for some canoeing on the lake. We didn’t actually realise it had a railway until then, which came as an added bonus. We found two car parks, one with a station at Llangower and the other near the town of Bala.

We decided to take a train ride first and caught the first train out from Bala Pen-y-bont Station to Llanuwchllyn Station and then back again. There is no car park at the station, but there is limited free on-street parking available. The train at Lake Bala is very different to the previous trains we had visited. The carriage we chose on the way out was quite open and a great way to view the lake. There was then a wait of about 40 minutes before the return journey.

Lake Bala Railway - Snowdonia Wales

We decided to go to the car park nearer to the town to go canoeing. This is the more popular of the car parks and includes a watersports hire facility. Despite being busy we found it to be less busy further into the car park. You do have to pay for canoeing in addition to the car park charge. It was a bit tricky to understand the pay machine, but I worked it out and paid the launch fee separately and placed the ticket inside my car.

Canoeing on Lake Bala Snowdonia Wales

We had bought an inflatable Kayak a few weeks before, so this was our first chance to try it out on the lake. It is the first time I’ve used an inflatable Kayak as I used to have my own plastic canoe in the past, I was surprised by how good it was. Useful for having a bit of fun on the lake at least.

There are showers at the car park, but we didn’t need to use them. We were just a little wet and allowed ourselves to dry in the sun.

We then walked into Bala Town, visited the Chocolate Shop where we bought and Ice Cream and some chocolates to take home for the rest of the family. We also visited the local butcher for some food to cook on the BBQ when we got back to the campsite.

RAF Cosford

We packed up the tent during the morning. Taking our time to allow the tent to fully dry from the morning dew, then set off home. Our route home is via the 54 which takes us past RAF Cosford and the Royal Air Force museum. We therefore stopped there for a couple of hours on our way home. This is somewhere my son enjoys, he’s been twice already this year including a day out for the RAF Cosford Air Show.

Entrance to the museum is free with a reasonable car park charge.

RAF Cosford museum - WWI & WWII planes


We had a great holiday. Apart from the lack of view at the top of Snowdon we were quite lucky with the weather and there was lots to do, especially for train fans.

Running at Code Club at a Pupil Referral Unit (PRU)

August 14th, 2019

In the past I have run a Code Club in a mainstream first / primary school. This involved going into the school at the end of the normal school day and spending 45 minutes to an hour working on Scratch projects. This is something that I really enjoyed, watching children taking their first steps in programming and seeing the smiles on their face when they see their games come to life.

The materials are all available from the Code Club website including step-by-step instructions for the pupils and additional notes to help support the volunteer running the club. The materials are really good and mean that even volunteers with little or no programming experience can get a club up and running.

This time it was a little more challenging as I ran a Code Club at a Pupil Referral Unit Primary School. Here’s an explanation of how I run the session which may be useful for others looking to do the same.

Code Club Logo - After School coding club

What’s a Pupil Referral Unit (PRU)?

A Pupil Referral Unit sometimes known as short stay schools are designed for children to attend for a short period of time. They provide an environment where children are able to attend school where they would otherise not receive a suitable education. In the PRU the children can have their needs assessed, are supported to access school and then transition to a permanent school place (which may be a mainstream school or more specialist provision). Many of the children in the PRUs have a special educational need which has not been met in the mainstream school environment and are in the process of having their needs assessed to get the additional support they need.

Additional Challenge

You may think that the additional challenge was behaviour, but actually that was not the case at all. The children were in a fun supported environment and because they had so much fun they behaved impeccably. There is also a very high ratio of teaching staff to pupils, typically one teacher / teaching assistant for every two children and the staff understand the needs of each of the children. On the first session we had a lot of the staff in the classroom supporting the pupils directly, but after a couple of weeks the pupils were working through the projects on their own with the teaching staff available if required.

The real challenge was that unlike previous clubs where all the children were around the same age, the PRU has very small mixed class sizes and so the club had to cater for all different ages, in this case from year 2 to year 7. Whilst the Code Club materials are good for those in year 5 to 7 I had to improvise some new materials for the year 2 to 4 children. I have created materials for different age groups before (including working with Beaver Scouts of that age group), and there were other resources from Raspberry Pi that I could use as well. The real challenge is trying to support different age children running completely different activities at the same time.

Also we did have slightly shorter time, as although we had 45 minutes in total, that included the children being taken to another classroom for a few minutes for squash and biscuits before the club started (which provided a good structure and allowed the children to relax before the session). The club also only ran for a few weeks in the school year as they only have one after-school activity a week which is different for each term / half-term.

I believe it was one of the most popular after school clubs as around half of the pupils in the school attended (the school has around 12 children at a time).

Adding structure

One of the things that the PRU provides is quite a lot of structure. This is something that can be very helpful for many of the children so was something that I tried to include as well. I normally put some structure into the Code Clubs that I run anyway, but formalized it a bit more.

When the children came into the classroom at the start of the club they would come in and write their name on a badge (I used stickers which I printed off for each session rather than the re-usable badges that I normally use). I then spent a few minutes talking about a programming concept. These were very basic such as what an alogorithm is and the need to make sure that what you tell the computer to do is what you want it to do (bugs).

I then got them to take part in an activity (paper based game, controlling a robot, or programming on the computer), finally giving them advanced notice when it was coming to the end of the session so that they could prepare themselves..

Games and BeeBots

For the younger children I started with an activity which I adapted from the Raspberry Pi Scouts materials. This started with a unplugged activity which is a board-style game I created using an A3 grid, direction arrows, a player and obstacles. The children played the game using paper and had to come up with an algorithm to solve. After they had mastered that they did the same using the Beebot.

BeeBot used for Code Club programming activity

This was something that the children enjoyed and worked through really well. The following weeks they got to do something similar using Scratch where they had to enter the instructions into a Scratch game.

Scratch and Advanced Scratch

The older children were instead sat directly at the computer and were able to start working through Scratch programmes. The one thing I did do was to print off the instructions, whereas in a mainstream school I would have them switch to a different browser tab to view the instructions.

I found that the children had already done some Scratch and so were able to jump straight into some of the more advanced Scratch topics straight away.


I have a number of BBC Micro:Bits which I wanted to try with the children, but I waited until part way through the term first.

These were the best Code Club sessions! The children loved the Micro:Bits and it was great to see the smiles on their faces when they could see the code that they had created turn LEDs on and off on the microbits.

BBC Micro:Bit interactive badge smilie face emoji

All the children started out making the Interactive Badge and some of them also created the Against the Clock game or created their own code.


There are Code Club certificates for different attainment levels within Code Club. We didn’t actually follow one of the set courses as we had a mix of different activities, so instead the children all received a Code Club SUPERSTAR certificate. I received a thank you card signed by all the children that attended which was great to receive.

Code Club Certificates - Superstar coder


Running a Code Club is rewarding, but I found that running one in the Pupil Referral Unit was even more rewarding. It did have challenges in working with such a large age range and running multiple activities at the same time but on the other hand having a small group meant that I could give the children more attention than in a large Code Club. It was great to see the children become so enthused by the activities.

I do hope to go back to the school in future and run another session for the next group of pupils.

Installing Linux is getting harder but it’s not Linux at fault

May 14th, 2019

I’ve recently bought myself a new computer. It’s a high spec laptop, a Dell Inspiron 5580 (Inspiron 5000 series), with Intel i7 processor, SSD and 1TB hard disk, and a Nvidia graphics card.

The laptop comes pre-installed with Windows but I really intend to use it running Linux. I don’t want to remove Windows completely as there are a couple of things that I do occassionally run in Windows. So one of the first things I did was to shrink down Windows and install Linux.

Dell Inspiron 15 5000 5580 running Ubuntu Linux

There have been times in the past where installing Linux and Windows side-by-side using a dual boot was almost child’s play. That’s no longer the case but it’s not Linux that is difficult, the difficulty is in not breaking Windows in the process as Windows gets upset whenever you try to make changes to the computer. With a little perseverence I’ve now got Windows and Ubuntu Linux (19.04) able to dual boot. This is an explanation of some of the hoops I needed to Jump through.

I’ve listed the steps below, they don’t neccessarily need to be carried out in this order, but some steps do need to be run before others.

Buying the laptop

I ordered the laptop directly through Dell.

Which Linux Distribution

My first decision was which Linux distribution to install. There are a lot of difference ones, but usually I stick to one of the variants of Ubuntu for my main laptop (I run other distributions elsewhere, including virtual machines on my laptop). For the last few years the particular Ubuntu variant I have been using is Kubuntu, but before then I used to run the standard Ubuntu. As there has been a new release within the last month (19.04) I thought it may be worth looking at both.

I tried both using a live USB distribution and chose Ubuntu because it worked better on the new laptop. The Kubuntu distro had problems with the graphics card drivers, and whilst it may have been possible to fix them by booting in a safe mode and installing the proprietary drivers it would have made the install a bit more complicated.

Once you have decided on a distribution you can download it from the appropriate site and then install it onto the USB stick using Rufus (Windows) or USB disk creator (Linux).

Setting up Windows 10

The first stage is to setup and configure Windows 10, which means logging in with a Microsoft Outlook account, which is available for free registration. In this past this is something I have avoided preferring to use a local login, but I don’t think that’s an option anymore and without registering then you won’t be able to update the bitlocker, although it may be possible if you remove encryption first.

Create a Windows backup recovery USB

The first thing I always do before trying to install Linux on a new computer is make sure that I have a backup of the original Windows installation. That way if anything does go wrong then I can reset the laptop back to the factory settings.

That is created using the Windows built in Recovery Drive tool, which can be found by clicking on the Windows application menu and typing recovery.

It will then tell you the minimum size USB drive which you can insert to make a backup. Or at least that’s the theory, mine said that I needed a 16GB usb drive, so I inserted a 32GB usb thumb drive. The application then gave an error message and crashed. It turns out that this is due to an unusual partition format from a previous use. There is a Windows partition manager application “Disk Management”, but that was unable to deal with the drive, so I had to use the command line application diskpart. There is a guide available at: Command Windows website, but USB drives are so cheap now that it may be easier to just buy a new one and then reset the USB drive in Linux after sorting out the dual boot.

Make windows shutdown properly, disable secure boot and override bitlocker key

You may want to read the next section on disabling encryption first.

The next thing is to set windows to perform a proper shutdown instead of the Hybrid hybernation it does by default and to disable secure boot in the UEFI setup. This did through up a problem with bitlocker, which I’ll explain below.

The reason I need Windows to disable the hybrid hybernation is so that I am able to access the NTFS partition when booted into Linux. It also reduces the risk of corruption on the drive. This is a feature that is well hidden in the system settings and even when you find it it’s set so you can’t change it until you enable the disable checkboxes (who on earth thinks up these things?).

From the Windows menu type “power & sleep settings” to access the power options in the system settings. Then find the section “Related settings” and click on “Additional power settings”. In the new Power Options window, click on “Choose what the power buttons do” on the left hand side. Then click on “Change settings that are currently unavailable” which will then allow you to unselect “Turn on fast startup”.

Windows 10 option to disable fast startup - allows access to NTFS drives from dual boot Linux

If you think that finding that option is difficult if you try and get help by click the link to “learn more” then you just get a link to a web search which doesn’t provide information on that particular setting. Really! What is the point in that link?

Next to disable secure boot. It’s probably possible to install Ubuntu without doing this, but as far as I can see secure boot is more about locking out other operating systems than it is protecting a computer from viruses and hacking attempts (which seldom target the initial boot code). To this you need to access the UEFI setup. First type “startup options” from the Windows menu and open “Change advanced startup options”. Then click on the “Restart now” button under Advanced Startup.

Windows 10 Advanced Startup options - boot to UEFI firmware settings

Then click troubleshoot, advanced options and UEFI Firmware Settings, which will then reboot to the settings. This is similar to the BIOS of legacy computers. From there you can find secureboot and disable it.

I then rebooted, which came up with another problem, that the bitlocker keys were now wrong. Bitlocker is a way of encrypting the disk drives to protect data. Previously it was only included in the professional or business editions of Windows, but it now appears to be included in the Home edition (or at least in the version that Dell includes on this laptop”. This can be a useful feature to protect your data, but it prevents other operating systems from accessing the data on the hard drive, so it’s a feature I don’t want. The problem is that whenever you make changes to the system then the security keys don’t work and you cannot boot the computer or access any information on the drive.

The boot screen tells you to enter the bitlocker key which (assuming you setup with a outlook account) can be found on the address provided by logging in with your username and password. If you do want to completely remove bitlocker then you may be better off just disabling the encryption first instead.

Disabling bitlocker encyrption

I wasn’t aware that bitlocker encryption was included in a Windows 10 home setup (it was previously a feature only in the professional or enterprise versions), but the Windows 10 drives were encrypted.

As I want to be able to access the data on the Windows partitions from Linux I disabled the encryption. I did that by going into the control panel security settings and disabling encryption on the drives. I believe this may have prevented me having to do a “key recovery” on the previous step if I had done this first.

Reducing the Windows Partition to make space

By default all the space on the SSD (Solid State Disk) and the hard disk drive is allocated to Windows. I would have liked to have installed Ubuntu onto the Solid State Disk rather than Windows as Linux will be my primary operating, but I didn’t want to risk breaking the Windows setup, so instead installed Linux on the normal hard drive. To do this I first reduced the size of the Windows partition using the Windows Disk Management tool.

Windows 10 disk management partitioning tool, after installing Linux in a dual boot setup

Right click on the partition in question and choose shrink. In this case I reduced the Windows data partition to approximately 250GB (in addition to the operating system partition on the solid state disk) giving approximately 750GB for Ubuntu to use.

Setting the SSD to non RAID

At this point I thought I had done everything ready to install. I shutdown the PC, inserted the USB memory stick and powered on hidding F12 to be able to boot from the USB stick. I however noticed that I was not able to see the solid state disk. Whilst I was planning to install into the real hard disk and not the SSD I still needed to be able to install the UEFI boot details on the SSD.

This is something that would normally require a reinstall of Windows, but fortunately I found the following forum post which gave an alernative AskUbuntu – SSD not detected during install.

The basic summary of steps I followed to change the SSD to AHCI are:

  • Make sure you have a backup (see earlier earlier)
  • Run command prompt as administrator (cmd)
  • Run command “bcdedit /set {current} safeboot minimal”
  • Using Windows recover boot into the UEFI setup (see earlier in this post)
  • Change the SATA Operation mode from RAID to AHCI
  • Save changes and exit Setup and Windows will automatically boot to Safe Mode
  • Run command prompt as administrator (cmd)
  • Run command “bcdedit /deletevalue {current} safeboot”
  • Reboot and make sure Windows is now working correctly

Installing Ubuntu

Finally your ready to start installing Ubuntu. The good news is that it was all plain sailing from this point onwards. There are a few points that the installer is quite slow as it detects various components so a little patience is needed.

First reboot using the prepared Ubuntu USB disk by pressing F12 during the Dell splash screen. I chose to “Try Ubuntu” first rather than going straight into the installer, and then launched the installer from inside Ubuntu.

I chose to install “alongside Windows” (which was not avialable prior to the changes made to use the SSD as AHCI instead of RAID). I accepted the default setting of letting the installer choose how to partition up the available space. There are advantages to creating a separate home partition (Using a separate home partition can make reinstalling Ubuntu / Kubuntu Linux easier) but by this stage I decided to go for the easy option.

Then it’s a case of a few simple questions and then rebooting, which gives a boot loader allowing you to choose between Ubuntu and Windows boot loader (ie. Windows).


Now it’s done I’m happy with the setup, but it was a very long process to install Ubuntu. As I say from the title it’s not the fault of Ubuntu, but of the way that the laptop is setup and the way Windows doesn’t like to share the computer.

The benefits of Linux are well worth it, including a stable and fast operating system, with tons of free good quality software and no nagging warnings about license keys, expiries or trying to sell you upgrades.

All in all a much better experience from Linux than it is in Windows.

Amazon Dash Button Home Automation with Raspberry Pi, Sengled home automation lights and pi-power Energenie Power Sockets

April 11th, 2019

I have recently been upgrading some of my home automation. I already use Energenie Pi-Mote to control some electrical power sockets, I’ve now replaced some of my light switches with Sengled home automation light bulbs.

Initially I’ve been using my Pi-power software running on a Raspberry Touch Screen and some timed actions to automatically turn lights on and off at certain times of the day.

I’ve now reconfigured some of my now unused Amazon Dash buttons so that they can control both the Sengled Light Bulbs and the Energenie remote control sockets.

Home Automation with Amazon Dash

In the photo shown the dash button is placed on the normal light switch. It may sound like a folly to replace a mechanical switch with a computer based one that does the same thing but it does make sense in this situation. The reason is that this is a porch light between the front door and an inner front door. The light is needed to be able to see the lock on the door at night, but the switch is on the inside of the door. Using home automation I can set the light to come on when I normally arrive home and then another dash button inside the porch allows me to switch it on at times when I come home at a different time. Having a dash on the physical light switch gives a way of turning the light on and off without using the normal switch, which would power off the bulb and disable the home automation capability.

Unfortunately Amazon appear to have discontinued the regular Dash buttons. If you have some old dash buttons around then it is a useful way to give them a new lease of life in home automation.

Using Amazon Dash python module

This uses the Amazon-dash project on pypi. Installation is straight forward using pip3.

On a Raspberry Pi using Raspbian use
sudo pip3 install amazon-dash
sudo python -m amazon_dash.install

(On other Linux distrubtions you may need to use pip instead of pip3).

You then need to edit the /etc/amazon-dash.yml configuration file with the MAC address for each button and the event that needs to be triggered.

The Amazon Dash buttons first need to be registered through the Amazon app (but don’t selected a product otherwise you’ll be ordering something each time you turn the light on and off). To find the MAC address for the buttons use the discovery option and then press the dash button:
sudo amazon-dash discovery
This value is then used for the triggers in the configuration file.

I used IFTTT (If This Then That) for my Sengled home automation light bulbs and the web interface I created for the Energenie Remote Control sockets.

To use IFTTT you first need to register through the website and create a webhook (Maker Event). To find the unique code for your services go to the Services in you account. Click on Webhooks and then settings and you will see a long code as part of the URL. That needs to be used as the ifttt code in the configuration file.

These are the entries used for the IFTTT connections:

  ## Porch light from hallway
    name: Mentos button
    ifttt: myIFTTTlongcodevalueaaaabbbbccccdddd
    event: porch_light_toggle
    data: {"value1": "Mentos button"}

  ## Porch light from porch
    name: Heineken button
    ifttt: myIFTTTlongcodevalueaaaabbbbccccdddd
    event: porch_light_toggle
    data: {"value1": "Heineken button"}

These are both toggle events, so each switch can turn the light on and off.

For the Energenie connections then using the “standard” sockets there is no way of knowing the current state of the plug, as even if you kept track of how it has been triggered through the pi-power app, someone could have pressed the button on the front of the socket.
There are new versions that can report back their status, I haven’t got any of those at the moment, but I hope to add that feature in future.

To overcome this limitation I have used two buttons. One to turn the switch on and one to turn it off. The entries for the configuration file are shown below:

  ## Turn Energenie Socket on
    name: Finish Button
    url: 'http://localhost/switchon?socket=0'  # Url to execute
    method: get  # HTTP method. 

  ## Turn Energenie Socket off
    name: Right Guard Button
    url: 'http://localhost/switchoff?socket=0'  # Url to execute
    method: get  # HTTP method. 

This is with pi-power installed on the same Raspberry Pi as the Amazon Dash button program. If using a different computer then that address would need to be included in the url.


This works well if you already have some of the Amazon Dash Buttons available, it’s a great way of making good use of those that you may have available.

The new IoT buttons are very expensive. I expect that they will work in a similar way (although they are designed for using AWS).

Home automation light bulbs from Sengled

April 3rd, 2019

I have created some DIY home automation in the past. This was based around using remote control of mains electrical sockets (Home automation – controlling Energenie power sockets using a Raspberry Pi) but I also used a home automation light on one of my home lights.

Since then the number of commercial home automation devices has really took off, so I’m now looking at some other home automation projects. Most are designed for use with Google Home or Alexa to provide voice activation I’m looking at how they can be integrated into my own DIY projects.

Sengled home automation light bulb (UK fitting)

I recently bought a SENGLED home automation lighting starter kit. This is a low cost starter kit with two light bulbs (available in B22 UK fitting or E27 European fitting). The total cost including the Hub and light bulbs is comparible to the cost of just the hub with some other manufacturers. One thing about most of the SENGLED products is that they are very easy to install. They are suitable for those that want to automate their house lighting without needing to rewire any wall switches etc. It does limit their usefulness a little as it means they can only be used with standard light fittings, but I can see the attraction of not needing to rewire a light switch.

SENGLED Hub and App

The kits comes with a SENGLED hub. It should be simply a case of connecting this to the router using the supplied cable and then connecting the power. It didn’t work first time for me, which I believe may be due to my home router rather than the hub. I restarted the router and then it worked OK since.

To configure the devices you need to download a mobile app called “Sengled Home” App from the Apple App Store / Google Play Store. There doesn’t appear to be anyway of doing this withough a mobile phone (a web client would be useful). The app allows you to allocate the room that each device is in and then turn the lights on/off and adjust their brightness. To add the devices then you need to be connected to the same network as the hub, but then afterwards it is available over the Internet. You can also change the hub to use wireless after setup, but it must be physically plugged into the router for initial setup. You have to relogin to the App on a fairly regular basis.

The app is quite basic but does include the ability to change the brightness of the lights, which I don’t appear to be able to do with any other service. Once registered with Sengled you can then register with Google home, Alexa or IFTTT.

Using these services then you can turn the lights on and off, but not control the brightness.

I think it’s a shame that there is no direct login to the hub. This means that you must register an account with Sengled and optionally with the other services. If they discontinue any of these in future then you could be left with a device that cannot be used.

DIY home automation with IFTTT

The Sengled hub does not provide any direct access for you to control the lights from a DIY home automation solution. The one thing it does provide is access through IF This Then That (IFTTT). IFTTT is a third party service that allows you to create applets which when triggered cause something to happen. Some of these are predefined, I used one which turns the lights on when I get home. It’s important to note that these don’t run in real time. I found that this particular rule would often trigger after I’d got home and entered the house, which defeated the purpose of what I was trying to achieve.

The most useful feature for me is the Maker Event which provides a web address that you can use to trigger actions. These need to be setup individually (one to turn each light on and one to turn each light off). Once created then you can get the URL for each instruction and include that in your own code (eg. using urlopen in Python, or curl to request the page). Unfortunately there is no feedback if that actually works (such as if the light is completely powered off), but it does at least provide the ability to make requests to turn devices on and off.


The lights use the ZigBee protocol between the hub and the lights. This is a protocol that has been used by makers for many years, popular with makers and particularly using an Arduino. The problem with this is that there does not appear to be any documentation about the communication with the devices. It is perhaps something that I can investigate in future, but that will involve some element of reverse engineering.


The Sengled light bulb starter kit is an easy way to get into home automation. It is a low cost solution that can be connected into a standard light fitting (assuming you have standard light fittings in your home). It works with Alexa, Google Home and can be used with home automation using IFTTT, but with all these they are limited to turning the light on and off, with no feedback of how successful the request is.

Raspberry Pi Birthday Party – Birmingham 2019

March 5th, 2019

I was again involved with the Raspberry Pi Birthday Celebrations in Birmingham.

This years event was held at the STEMHouse in Birmingham. A makerspace / startup space designed for entrepreneurs and small businesses looking to create a product.

There was a strong influence of 3D printing and games programming at the event, including my own talk and hands-on session.

3D printing from Minecraft

During the event I gave a quick talk / demo on a program that I have developed on 3D printing from Minecraft.
It’s designed to lower the threshold for those looking to create 3D printed creations.

Screen shot of Minecraft and Minecraft Print utility program

This is work in progress, but allows you to create a platform to design on, and then export it for use in OpenSCAD. More updates will be coming soon with additional features.

Starting game programming using Pygame Zero

This was a 40 minute practical session on getting started with Pygame Zero. It starts with a very basic pygame zero program, adding a background, some sprites and collision detection.

Raspberry Pi Birthday Party - Birmingham 2019

The complete game is where the player controls a unicorn (or other animal) to collect food which appears at random places across the screen.

Pygame Zero game - beginners tutorial for Raspberry Pi birthday

Other activities

Other activities included talks and practical sessions on 3D printing, a practial Minecraft Python programming session, an introduction to the MicroBit and other talks.

The event was mainly attended by families. It was great to see so many young people take an interest in learning computer programming. My own two children attended and were both inspired by the activities. My son with the programming and my daughter with some of the 3D making opportunities.

I also hope to give my presentation at the UK 3D printer meetup in Birmingham later this year.

Twitter Status - follow stewartwatkiss

UK days out, children and holiday information is also available on the Days Out Diary web site
Linux, LPI and the Quiz / Test Program posts are also available on the Penguin Tutor website
First Aid Information, first aid games and first aid practice test / quiz entries are also available on the First Aid Quiz Web site