Lego Lunar Lander

I’d really like to be rich. If I was rich I could afford the new Lego Lunar Lander kit and a big house containing a “Lego wing” into which I could put it once I’d made it.

Actually, to be honest I’m not that bothered really. As someone who was around at the time of the landing (#oldagebrag) I remember getting and building the official Airfix Lunar Lander kit (complete with a piece of the moon). Mine even had gold tin foil from Caramac bar wrappers around the legs, just like the real thing.

Lamppost Sensors Live

Well, this is rather exciting. The air quality sensors that we handed over to Hull City council to be attached to lamp posts and measure air quality are now attached to lamp posts and are measuring air quality.

We didn’t expect them to show up on the network just yet, but thanks to one plucky LoRa gateway in the middle of Hull, three of the four sensors are getting readings into the servers.

The next step is to get the data onto our interactive map so that everyone can see what it looks like.

Free Azure Sphere Development Kit

One of my big concerns about the Internet of Things is that people might not do it properly. By that I meant that they will rush to market with the ability to put connected control into all kinds of situations without worrying about security, deployability and maintainability. That’s one reason why I very much like a new competition where you get to play with an Azure Sphere embedded device which has those abilities at its heart.

Another reason why I like the competition is that you can get a free device to play with if you enter. You can find out more here.

Werewords rocks

This is a really good game. I’ve been a fan of werewolf for a while. That’s the game that pits werewolves against villagers. Werewords has a similar basis, but rather than trying to just spot the werewolves the villagers are in a race against time to deduce the “magic word” that only the seer, the werewolf and the mayor know. If the werewolf identifies the seer the wolf wins. If the villagers spot the werewolf, they win. Everyone can ask the mayor yes/know questions to try to work out what he word is.

The seer can try to steer the questions towards the answer, but not too much in case the werewolf spots them. The werewolf is doing the same thing, in the opposite direction. And sometimes the mayor is a werewolf.

Confused? You won’t be. Not after a few rounds. The whole game is run by an app that sets the scene and times each round. A complete game lasts around 6 minutes, and so over an hour or so of play everyone gets a go at the different roles. Well worth a look.

Shifty Eyed Spies

Shifty Eyed Spies is not a serious game. At least, not the way that we played it. Our attempts ended up mired in frequent hilarity and general shiftiness.

Players have to signal to each other via surreptitious nods and winks, while all the time looking our for others doing exactly the same thing.

It’s very unlikely you’d want to spend an entire evening playing it.But as a warm up for something a bit more meaty, or just a reason to be deeply silly for a while, it is rather fun.

Learning through games

I’ve got my two button game working now. It’s fun watching people play a game that you’ve made. They start doing things that you weren’t expecting. But sometimes you find out other things too.

The gameplay (press the red button if there are more red lights lit, blue if more blue) is simple, but I make the task more interesting by adding more colours and making the colours move around the lights. Then I thought I’d make the lights flash on for half a second and then off, so that the player has very little time to count them.

This actually makes the gameplay seem easier (at least for me). The brain seems to retain the information for a while so that you can work out the answer, even with a very brief look at them.

I think this is the basis of “flash cards” although I may be wrong. But it is a useful reminder of the way that you can start going down really interesting tracks when you start fiddling with games.

Getting Started with Micro Python on ESP32

I got my little game working on the Raspberry Pi yesterday, and today I got to thinking how I could make it work on something a bit, er, cheaper. It’s not so much that I begrudge paying the price for the Pi, more that I can think of more demanding things to do with the Pi than just run the game. My thoughts turned to the ultra-cheap ESP32 devices that I’ve been playing with. The only snag is that I’ve written the entire game in Python for the Raspberry Pi, and I don’t fancy re-writing it in the C++ that these devices normally run.

So, why not run Pyhon on an ESP 32 device?

This turns out to be really easy. If you’ve installed ESP32 devices as part of your Arduino development environment you will have a useful little program called esptool.py on your machine. To convert a device to Micro Python you just have to plug in one of those ultra-cheap devices, find out what serial port it is connected to (in my case com4) and then use the command below to program the chip with Micro Python.

esptool.py --chip esp32 --port com4 --baud 460800 write_flash -z 0x1000 micropython.bin

This loads the image in the file micropython.bin into the device. To get a Python image, go to the download site and look for ESP32 devices. I used the one in the file esp32-20190714-v1.11-146-g154062d9c.bin

Above you can see what happened when I ran the command.

When you restart your ESP32 you will be able to talk Python to it via a command prompt. That’s fine, but what you really want is an IDE that lets you write and deploy Python programs.

The best one I’ve found is called Thonny. It’s works with “normal” Python nicely enough, but it also has an option you can use to point it at an embedded device:

In the options menu above I’ve told Thonny to search for a device running MicroPython and connect to that. Now, when I run a program it is deployed into the device and executes from there.

The MicroPython installation provides a tiny filesystem that can hold python programs. When you run a program it is transferred into that filesystem and runs from there. There are two special program files on the device, boot.py and main.py. The program in the boot.py file is executed when the device powers up, followed by the one in main.py The Thonny program has an option (in the Device menu) to save the program you are editing one of these files. This makes it really easy to make your Python program run when the device is powered up. I made my game program the main.py one and now I have my original Python program running inside a device that only cost around a fiver.

It wasn’t quite as simple as just copying the files over. The api (application programmer interface) to use GPIO ports and Neopixels are different in the two devices and I discovered that MicroPython does not provide a random.shuffle method. This meant that I had to create my own shuffling function, which wasn’t too hard.

Anyhoo, I now have my program running in Python on a tiny embedded device. Which is rather nice. I’ll put the code up on GitHub later this week.

Hull Raspberry Jam with Two Buttons

Well, that was fun. I really should have taken some pictures of the jam, it was great fun. There were loads of machines set up and creativity going on all over the place. I took my “Two Button Box” along and developed the rest of the software. Thanks to Ben, Jon and Matt for advice and help on getting my Python program to run each time the box is powered on (this harks back to my Unix days of old - editing the rc.local file to run programs on boot up).

Players need to press the red button when there are more red lights lit, and the blue button when there are more blue lights lit. I’d taken a bit of care to make the gameplay progressive. The game starts simple, with just red and blue lights, but then other colours appear and then they all start to move around.

It’s always nice to see people playing a game that you made. I’m not sure it pushes back any frontiers or brings anything particularly new to gaming, but it is always nice to see someone enjoying playing with something you’ve made; particularly if you enjoyed making it.

You can see it in action here. Thanks to Jon for the video.

Making plans for Hull Raspberry Jam

There’s a Raspberry Jam in Hull tomorrow. There is a kind of development theme where attendees are invited to create a game that only uses two buttons to control it. I love a good constraint. Ask me to make a game and I’ll fall apart. Ask me to make a game that only uses two buttons and I get interested. I mean, as you can see above, I’ve got two buttons….

My plan is to put the buttons, a Raspberry Pi and a power supply in a box. It’s one of the boxes that is supposed to have an Air Quality sensor in it (sorry Robin).

There’s a kind of reason in this madness, in that I’ve often wondered how good the Raspberry Pi is for creating what I’d call “pure” embedded devices. The Pi Zero W is very close in price to things like ESP32 based devices and brings a lot of advantages, including much more power and a “full fat” operating system. I get to write in Python - which I love - and I can actually run the IDE on the device itself if I want to.

You can see my first step above. The first thing I do is make sure that all the components will fit inside the box. As you can see, I think it will probably be OK. The only snag I’ve hit so far is that the holes for the buttons need to be a little bit larger than the ones in the box itself. However, a few minutes with a drill have sorted that one out.

The box that I’m using, like pretty much everything in my life, came from Amazon. You can get it much more cheaply if you are prepared to order it from China via Aliexpress. It’s supposed to be used as a junction box for connecting cables. It has eight big holes all round the sides into which you can run cables and connect them together, or put devices into. It has these rubber inserts for all the holes that you don’t want to run cables into and I got to wondering how good they would be at defusing light from a neopixel. Perhaps I could put some lights in the box and use these as the basis of a game of some kind. Time to build a circuit…..

What we have here is the first circuit. The two micro-switches will be fitted onto the buttons. The coloured pixels are to be stuck inside the box against each of the rubber fittings. The chain of lights is connected to a single GPIO (General Purpose Input/Output) pin on the Pi Zero. The buttons are connected to two other GPIO pins. There’s a splendid library available from AdaFruit that allows a Python program running in a Raspberry Pi to set the colour of each of the leds and also read the state of the inputs. So in no time at all I had the lights on under program control. Some tests have indicated that they will work quite well. I’ll put them all in the box tomorrow.

The next thing I need is an idea for a game. What I’ve come up with is a very simple idea. Each light around the box will light up with a particular colour. If there are more red lights lit than blue lights, the player must press the red button. If there are more blue lights lit than red lights, the player must press the blue button.

This should be easy to code and might make for some compelling short term game play, particularly if I add a bit of complication as the game is played.

I’m looking forward to taking the box to the Raspberry Jam tomorrow and finishing off the code.

Mobile Phone Navigation is still rubbish

Wrong side of the tracks….

The satnavs that I’ve used in cars are mostly OK. The ones I’ve used in phones are mostly awful. Some observations:

  • The official Apple Maps application for iPhone actually consumes power faster than a normal car USB connector can charge it. So on a long journey your phone can go flat even if it is plugged in. On the plus side, it does make for quite a good hand warmer.

  • The Google Maps application (which you switch to because the Apple Maps one kills the battery) has a navigation display that is obscured by appointments that pop up on the screen and have no obvious way of cancelling. This is great if you are on the way to a scheduled meeting. Not.

  • The Official Apple Maps app (which you decide to use for a short journey) just plain gets things wrong. Exhibit A above. Searched for the West Avenue car park in Filey, asked the phone to navigate me there. Got taken to a residential street across the railway from my destination. Rather than using the geographical location of the thing I’ve searched for (which it seems to know because it draws it in the right place) it instead navigates to the post code which covers an area including lots of wrong destinations)

O2 Apple Watch Data Fix

After all the fun and games getting the Apple Watch on O2 I was hoping for a happy ending. But this didn’t happen because although we could quite happily make phone calls with the device all the network and SMS features were broken. I was thinking for a while that I’d have to ring up and they’d try to sell me another watch. Wah.

But the good news is that the fix was quite simple. I opened the Apple Watch app on the connected iPhone and then went to the Mobile Data tab. This shows you the data used by the watch. Just as the phone was heading to the page it displayed a “Carrier settings update” message and offered me the chance to confirm. After doing this the watch seems to work fine with SMS and mobile data. So, if you’ve bought one (or even several) Apple watches from O2 and can’t get the data to work you might like to try this.

Raspberry Pi Model 4 a bit slow at 4K

So I’ve got my Raspberry Pi model four running and I thought I’d try it driving a 4K monitor. Promotions of the device have made much of the fact that this new version has not one, but two video outputs and they can run 4K video.

I don’t want two 4K displays, but a single one that works correctly would be nice. Unfortunately the performance is not great. It might be me, but it seems that although the desktop looks splendid it does seem to lag a bit. Moving the mouse around turns into a game of skill, where you have to stop moving the mouse before it arrives at the desired destination. This might be a great idea for a video game, but it isn’t much fun when you are trying to use the device.

I’m hoping that this is caused by early versions of the operating system not being optimised for the new hardware, but if you’re thinking of getting a model 4 I’d advise you to get your hands on a device and have a play before you splash any cash.

Awesome Overhang fun

So I’m printing some camera clips on Una, my Ultimaker (seven years old this year). I forgot to ask for support for the print. I needed support because the top half of the clip just sticks out into the air. If I’d asked for support the gap on the left of the picture above would have been filled with removable printed bits that support the “ledge” that is being printed.

However, when the print finished I was impressed that even with the lack of support I’d got something that is probably usable. You can see the dangling loops of filament at the bottom of the ledge but after a few layers they had bunched together enough to get enough material to complete the print.

I’m not proud of my inability to specify support when a print needs it, but I’m very proud of the way that Una coped without it.

Uninspiring O2 Apple Watch

Drop everything - your order’s ready to pick up.

Turn off the TV. Put down your sandwich. Get off the bus. Whatever you’re doing, it’s time to hotfoot it to your O2 store. If you can’t come right now, that’s okay. We’ll hold it there for seven days. But don’t leave it any longer, otherwise we’ll assume you’ve changed your mind and we’ll have to cancel your order.

I had to work very hard to get the above message. The plan was simple. I thought it would be nice to replace number one wife’s ageing Version 0 Apple watch with a new and cellular version. And O2 were doing a discount offer that looked rather tempting. What could go wrong?

Lots.

I thought I’d perform the transaction online. Half way through - just after I paid my 20 pound deposit - the web page crashed. No order, no nothing, just a 20 pound transaction on my bank account. So I rang up and asked them to sort it out. Of course they can’t do that. There’s no transaction to find. But they can sell me the watch again. Cue 25 minutes of minutely detailed purchase discussion. The kind of thing I’d been trying to avoid by buying online. At the end of this fun and games I was promised an email containing a link that I could use to complete the transaction.

Guess what? That link crashed too. Another 20 pound transaction on the account. So I rang up again to try and sort if out and, bless my soul if they don’t try to sell me a watch for the third time. I suggested that it was time to get someone along who knew what was going on. Finally I got escalated to the point where someone asked “Are you using a pop-up blocker on your browser” .I’m not, but the merest mention of issues like these sends me scurrying off to try a different browser. And finally, after another 20 pound payment, I get an order completed. I’d carefully used Google Chrome to perform the purchase because I worry about browser issues breaking things but it turned out that this was broken. And the transaction that came through was made using Edge. Go figure.

Apparently the other payments will disappear after a while. They had better. Or I’ll probably have to go online and buy another watch to sort it out….

Anyhoo, a couple of days later I got the breathless email at the start of this page. So today we hurried along to the O2 store to get our hands on the treasured technology. It was a very uninspiring pickup. I wasn’t expecting fireworks, or a red carpet. This was just as well. I’ve had more engagement picking up parcels from the Post Office. In fact it was just like that - even down to the DHL wrapper the watch came in.

Pro tip for O2 shop staff: you can greatly enhance the pickup experience for customers by taking the item out of the postage bag before giving it to the customer, and then showing an interest in what was bought. I guess there’s no commission to be had in handing something over, but that’s not really the point as I see it.

I got the watch installed after three or four hours. Software updates over Bluetooth take an age. And it seems to work fine. But I can’t recommend the customer experience at all.

Talking Air Quality at South Hunsley school

David got in touch a while back. Would I like to talk to his students at South Hunsley school? Would I? Oh yes. So today it was into the bag with the Air Quality Sensor Top Hat and a few other goodies and then off back to school. They were a great bunch of folks. And they were even polite enough to laugh at my first (and only) joke. I was talking about air quality, hardware, self promotion and whatnot. I said at the time I’d put some useful links onto my blog (always a good way to drive traffic). Here they are.

To find out about the Arduino and get the software you can go here.

To make yourself poorer buying things from China you can go here. You can get cheap Arduino Uno devices, along with a whole bunch of other hardware.

If you want to buy one of the tiny LoRa enabled devices with a screen search for “Heltec LoRa”. The devices are sold in pairs for some reason, make sure you get the ones which are marked as 868Mhz.

You can also get the tiny cheap WiFi devices here, search for “Lolin D1 mini”.

If you want to get an air quality sensor you can get one of the good ones by searching for “SDS011”. If you want to measure temperature, pressure and humidity, search for “BME280”.

If you want some fun coloured leds search for “WS2812” followed by “ring”, “strip” or “panel”. These are dead easy to interface to any of the devices I’ve mentioned above. But make sure you get hold of a properly beefy power supply if you are driving more than 12 or so to full brightness.

I’ve not had a problem buying from China. In over 50 orders I’ve only had one not turn up, and I’ve only had a couple of broken devices.

You can find my Air Quality stuff on GitHub here. That has drivers for the hardware that you can buy and there are also circuit diagrams and box designs.

Byte ordering is a thing....

I’m upgrading the Air Quality sensor software so that I can send configuration messages over LoRa to the sensor. The thing I’m most interested in is the ability to tell the sensor the rate at which it should send readings. It would be useful to have a message sent every five minutes or so for testing, and then dial back the rate once the sensor has been installed. I’m using a tiny packet format to do this. The packet is three bytes long:

01 58 02

The first byte is the command number (there is only one command at the moment). The other two bytes are the number of seconds the sensor should wait between sending each reading. The value I want to send won’t fit into a single byte (a byte can represent an unsigned integer up to the value 255 and I want to have intervals longer than 255 seconds) so I’m using two bytes. The first byte is the “low” byte of the value I’m sending and the second byte is the “high” byte. In the tiny sample above the low byte is HEX 58 and the high byte is 2. This gives an interval of 2 * 256 + whatever 58 hex is in decimal. This boils down to an interval value of 600 seconds, or 10 minutes.

I wrote the software, tested it, installed it in all four of the sensors we are building and then set them off. I then sent the above command to the sensors to set 10 minute updates and then relaxed in the knowledge of a job well done.

And all my sensors stopped transmitting completely. Wah.

Turns out that I am an idiot. I’d done everything right except the last bit, when I’d sent the following command:

01 02 58

I’d got the MSB and LSB bytes the wrong way round. Rather than having 2*256 I now have HEX 58 times 256. A big number. A six hour or so number. So all my sensors were now not going to transmit for six hours.

Sending the new command wasn’t a problem, but because of the way that we are using LoRa the sensors only look for new commands when they send a reading. So I had to wait for six hours before the command would get picked up and acted on. This is something to bear in mind about LoRa. The remote node is not always listening for a message, it only turns on after it has sent something. This is one way they manage to get such impressive battery life for LoRa connected devices.

I managed to solve the problem by turning the sensors off and on again. They always transmit a packet when they start up so I was able to update the timing with more sensible values without having to wait six hours.

Shelf collapse chaos

That was scary. We were having a quiet coffee downstairs when we heard a noise rather like the one that a house makes when it falls down. A tsunami of bangs and crashes that must have lasted a minute or so. We hurried upstairs to find out what was left of the top half of the building and expecting not to find much..

It turns out that one of my shelves along the top of my project room had come loose, depositing onto the floor all the boxes and bits and bobs I’ve been stashing up there for the last few years. The good news is that nothing was broken that didn’t deserve it. I’ve put most of the stuff back, given everything a proper tighten and I’m going to keep an eye on it in future. Such excitement.