Python Shorts

I’m trying something new for April. I’ve got a whole bunch of tiny posts about Python which I’m going to be releasing over the next couple of weeks. Each one of them reveals a facet of the language that you might or might not know. If you know it, never mind - there’ll be another one along the next day. They start on Friday.

If there are any specific Python topics you’d like to know more about, post in the comments and I’ll see what I can do.

M5Stack Large Language Model

On the left is the Rabbit, then the LLM and then the Core2

For the price of a video game you can now get a device running a Large Language Model. Its made by M5Stack who seem to specialise in taking interesting technology and packaging it up for us to play with. This means you can have a self-contained unit the size of a matchbox which can understand and answer your questions without needing a network connection. Everything happens on the device. Embedded ChatGPT is becoming a thing. Although it is not quite as good yet.

In the UK you can get one from PiHut. At time of writing they had six left. Search the store for LLM. Things get a slightly more expensive when you realise that you also need an M5Stack Core module to control the LLM, but you might already have one of those lying around. I got myself a Core 2 device because most of my M5Stack Core modules are pretty old. The Core sits on top of the LLM and provides a touch screen and display. The LLM also has a microphone and speaker with “wake word” support.

The LLM device contains a fairly powerful CPU (which apparently came from some night vision goggles) paired with 4G of RAM and 32G of storage. It delivers 3.2TOPs (whatever that means) and comes with the Qwen2.5-0.5B LLM pre-installed. Other models are promised for later.

The M5Core device fits on top of the LLM and connects to a standard M5STack multi-pin connector which sticks out of the LLM. As the name implies you can stack other layers underneath if you want to. I’ve seen pictures of a base for the LLM which contains a wired Ethernet port but I’ve not seen it for sale anywhere. The LLM will unit will run freestanding, although I’ve no idea how you would get it started. You tell the LLM what to do via a serial connection. The M5Core device on top can run Arduino or UIFlow programs to send commands.

I had all kinds of fun getting the fancy UiFlow programming environment to work on my M5Core 2 so that I could use it to tell the LLM what to do. First I had to flash the firmware for Flow 2.0 into the Core 2. Then I had to bind it to my account, then I had to browse for it in the IDE, then I had to find that the device wasn’t recognised, then I had to scratch my head for a while and then I had to install the earlier version of the firmware to finally get it to work.

Then I had to enter the UiFlow block programming code. For some reason the sample programs are tightly bound to the M5 S3 version of the Core and if you try to change this it throws everything away. Very frustrating. Then I found that simply by connecting Thonny to the device and deleting boot.py from it you can get to write and deploy MicroPython and it just works (although resetting it can be a pain). The UiFlow environment is just a wrapper for a bunch of MicroPython. You can ask the IDE to show you the Python source, copy it out of the web editor, paste it into Thonny and away you go. The only change I had to make was to configure the serial connection to the LLM module:

llm_0 = LlmModule(2, tx=14, rx=13)

These are the numbers that worked for a Core2 device. When I finally got it running the results are pretty impressive. The model is small and it doesn’t know a huge amount. It thinks the earth is one million miles from the sun. However, it does work and response times are fine. I’ve printed a base from here and fixed it to the bottom of the stack so it now looks fully formed. I have to power it from a USB power supply but it works fine from that. At the moment I’m running a very simple Python script in the Core2 but I plan to add a bit of richness.

Core built with the LLM

So, around a year from getting the Rabbit (which uses a network connection to a big server) I now have a tiny battery powered device which does everything internally. No network. Blimey. Much more fun than a video game.

Just present

Something to remember: Presenting in front of people is a skill. Give an engineer a new thing to work with and ask them to use it and they will just do that. So treat presenting as a tool you need to learn how to use. Apply yourself to it in the same way. Have a go, learn from your mistakes and then have another go. You don’t have to look very far to find someone to present in front of. You could take it in turns next time you get together with a bunch of like minded souls.

Don’t make the mistake of thinking that presenting in front of people is a skill that you are born with. It is something that you can learn. And if you are born to be good at presenting (lucky you), applying yourself to your craft has got to be a good idea.

Chord Keyboard Trainer

ChatGPT is officially amazing. I wanted to make a chord trainer for my PICO powered chord keyboard. So I pasted the Python source for the device into ChatGPT and asked it to make a JavaScript program that could train a user on the chords. And, after a fair bit of discussion we’ve managed to make the program I wanted.

We did have some fun. ChatGPT was determined to put linefeed characters into string literals rather than ‘\n’, which made the program break a few times. The worst bug we found was that when you are entering text into the game and press the space bar this can re-trigger the “Start New Game” button to very confusing effect.

However, it now works. If you want to test your Micro Writing skills you can have a go. If you type a letter quickly, before the help layout appears, you get 5 points. Otherwise you only get one. You can use the other buttons to get a complete list of the keys.

You can find it on GitHub here. You can have a go with it here.

PICO Musicbox

Say hello to the PICO Musicbox. It contains a Raspberry Pi PICO and uses an M5 Stack Synth module to make the sounds. There’s also an OLED display in the mix along with a rotary encoder. And of course some neopixels. You can see inside the box here. I’ve spent the last couple of days dropping out Circuit Python to make it all work together. If you fancy building one I’ll have the circuit diagram and software available soon, along with the STL files for the case.

Vintage Audio at the Hardware Meetup

We had some lovely vintage audio stuff at the Hardware Meetup. Including Tracey’s amazing vertical record playing HiFi.

This is my portable tape recorder. By portable I mean that it has a handle on the top. I can’t believe that we used to carry things like this around just to have music along.

This is kind of portable and it does play music. And it does look vintage.

We had a saxophone too, which was super cool. Not sure what the theme of the next Hardware Meetup is, but it will be on April the second.

Mad Software

For the last six weeks the car has been asking me to accept a change in terms and conditions covering the software in it. A cheery reminder pops up after five minutes of driving. But it won’t let me see the conditions of course. Because I’m driving.

So today I waited for the reminder in the car outside the house before I set off. There were several pages to be gone through and I didn’t read any of it. Mainly because I wanted to drive somewhere. I just clicked on OK and NEXT to get me through to the end and out. I’m pretty sure that the changes are so that when I drive past a Starbucks the car can tell me that latte is on offer at the moment.

I’m not sure how we got to this place, but something tells me it is not a place I want to be in.

Airecon 2025

Went to AireCon 2025 today. It was awesome. Good company, good food and a great atmosphere. I did my rounds of the second hand game shop and bought a bunch of super-cheap games.

Get Lucky is a kind of reverse Cluedo where you try to kill Dr Lucky and stop other players by making him lucky enough to survive their attempts. Good graphics and some lovely writing on the playing cards. Trophies is a nice little “ice-breaker” game, comes in a tin and has a real trophy in it. Moo’s Cafe is fun for youngsters (and young-old people) and comes with a wooden spoon. Bucket of Doom is not as good as I thought it would be. Never been a fan of “Cards Against Humanities” type games and this is a bit like one. And I bought “Dead and Breakfast” just for the name (although it looks fun too). Thanks to the organizers and the staff who made everything work so well. Great fun. Now counting down to AireCon 2026….

Daleks can't see red

The invisible dalek?

Back in the sixties I was reading a Dr. Who annual, as you do, and I happened upon the “Dalek Defence Guide” which gave helpful tips for surviving a Dalek invasion. Daleks were the number one science fiction baddy of the time, so I reckoned these tips were worth taking seriously. One of them was that, since Daleks can’t see the colour red, you should wear red clothes and hide behind a red post box if you see a Dalek going past.

This caused me all kinds of problems. If they can’t see red, how does this work? Does red appear black (in which Daleks would see you as black) or transparent (in which case the Dalek would see what was behind you). If they see red as transparent, how does the view of what is behind get through you for the Dalek to see. And how does the universe know to show the world behind you to the dalek, and not you behind the red thing?

Yep, I started over thinking things pretty early in life….

Update:

Thanks to the wonders of the internet I’ve found the original reference. You can read the entire Dalek World from 1965 here. I actually think the description makes a kind of sense. It’s not that red stuff is hidden, just that the dalek brain does not notice it as such. But I might be overthinking again….