MicroPython Connected Little Boxes

All new lego logo

I’ve just released the latest incarnation of Connected Little Boxes. I’m in the process of converting the original C based system into MicroPython. I’ve got enough of it working to make it useful and now I’m looking for people to break it and tell me it’s rubbish.

You can find it here. If you have a spare Raspberry Pi PICO you might like to give it a spin.

Holey Stupid

I’ve got a new desk. Gone are the bright red Ikea ones that weighed substantially less than the things we put on them. Now I have a big strong counter which hopefully won’t move much when I strap a steering wheel to it.

Anyhoo, I wanted some holes for cables to go through. And I also fancied the device above, which sets a rather useful mains socket and some powered usb ports into the desk. I discovered that these are 80mm diameter. So I asked for some holes which were 80mm diameter. Big mistake. Turns out that two things which are exactly the same size don’t fit together properly. The result you see above is the result of a bunch of frantic extra sanding on my part…

Tales of Yore: Toilet Flushing

Inspired by a Discord post (which might be where all the good ideas come from) I thought I’d start a new series of intermittent blog posts about things I’ve done over the years. Starting, of course, with flushing toilets. The University of Hull used to have a “Centre for Applied Electronics” which was a technical “gun for hire”. Companies with problems would get in touch and we would go along and sort them out. Sometimes it was new product developments, sometimes it was automation or sensors. And sometimes it was toilets.

Reckit and Colman, a local chemical company, had built a lab containing toilets from all over the world. They made chemical tablets (also known as “loo blues”) which dissolve over time, releasing chemicals into a toilet each time it was flushed. These were clipped into the toilet bowl to keep things clean and fresh. The company wanted to know how well their tablets worked around the world. Rather than send someone out with a fistful of plane tickets and a case full of loo blues (I’d totally have done that job) they instead brought the world to a lab in Hull.

What they wanted was a way of producing timed flushes which mimic typical household use. Someone else built the actuators and I was called in to make the control system. At the start of the job the customer pointed to a manhole cover in the courtyard below the lab and said “If you flush all the toilets at once, that’s the cover that lifts up and floods everywhere. Don’t ask me now I know”.

I ended up programming a microcontroller in Forth to control the toilet actuators. It had quite a few timeouts in it. The controller was connected to a brand new (at the time) IBM PC XT. All the software was written in GW (Gee Whizz) BASIC which worked a treat. I discovered that the language had an ON TIMER GOSUB construction which let me build a system that allowed the user to edit and store time profiles while the toilets were being controlled in the background.

We installed the system and left them to it. We went back six months later and they told us they had a problem with the cathode ray tube (CRT) display “burning in” the screen. They asked what I could do about it and I pointed at the brightness control on the screen and suggested that they turn this down after use. In the end I added a screen timeout, mindful of the possibility that I would now get calls from people saying “The screen keeps going blank”.

Anyhoo, the system worked well for years, and I was rather cheered by the thought that, at any time of day or night a piece of my software could be flushing a toilet. Not a lot of programmers can say that.

A little bit of telemetry goes a long way

def update(self):
        for name, mgr in self.manager_entries:
            start_time = time.ticks_ms()
            mgr.update()
            now = time.ticks_ms()
            mgr.update_time_ms=time.ticks_diff(now,start_time)
            self.status[name] = mgr.get_status()

This is the update loop for the Python version of the Connected Little Boxes software. It works through all the managers and updates them all. It also records how long each manager took to update and stores this value in the manager. I’ve found this to be incredibly valuable when trying to measure performance. When I display the status of the managers I also show the update_time value, which tells me who is slowing things down. When you make something that might be a bit performance sensitive its always worth adding a tiny bit of telemetry to find out what is going on.

Reverse Vibe Coding

“Vibe coding” is apparently a phrase of the year. It describes a programming practice where you tell an AI system what you want a program to do and then AI writes the code for you. Then you test the code, it works perfectly, you embed it in a mission critical system and everyone lives happily ever after. Or not.

I’ve tried this a few times and what I end up doing is what I call “Reverse Vibe Coding”. I describe what I want, the AI makes something which mostly works. I describe what changes I think should be made to make it work properly, the AI then makes something new which may, or may not, be better. And then we repeat. There seem to be inflection points in the process where the AI can jump in massively the wrong direction and you have to kick it back on track. Rather than AI helping me solve my problem I end up helping AI solve its problems. This is kind of fun, but not usually very efficient. Although the AI probably learns a lot.

Hyper Japan Manchester

We like Hyper Japan in London. So we thought we’d try Hyper Japan Manchester. The journey was different, in a car rather than on a “more exciting than we needed train”. But no less exciting as it turned out, thanks to the antics of Apple Maps navigation which insisted on taking us off the motorway so that we could enjoy some A-road action and a trip through Oldham that we didn’t expect. Then, when we needed it most in the middle of Manchester, the navigation had a complete meltdown spouting random instructions to head off down unknown streets and make sudden U-turns. I’ve no idea what caused it, but fortunately I kept my nerve and found the car park next to the venue.

You could say that the event was “more intimate” than the one in London. You could also say it was smaller. But it was no less interesting and enjoyable. Although we didn’t find anyone selling bubble tea. We got great stands, amazing musicianship and good food. Plus fantastic costumes. I’ve dropped some pictures down below. You can find all my Hyper Japan pictures here.

Python Shorts 16: Getting an exception description in Micro Python

This is useful if you want to find out how your otherwise perfect code has just fallen to pieces. One of the nice things about Python is that when a program fails you get a description of what happened and where:

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "main.py", line 21, in <module>
NameError: name 'zanzibar' isn't defined

However, if you catch the exception you need a way of displaying this useful information in the handler. This is how you do it:

try:
    mgr.setup(mgr.settings)
except Exception as e:
    print(f"[CLB] Manager {name} crashed during setup:")
    sys.print_exception(e)

The call of sys.print_exception takes in the exception object that was thrown and prints the terribly useful message. If you want to put the message into a string (perhaps so you can log it or send it somewhere) you can do this:

import io
import sys
try:
    x=zanzibar
except Exception as e:
    buf = io.StringIO()
    sys.print_exception(e, buf)
    trace = buf.getvalue()
    print("bang")
    print(trace)

The code above will throw an exception (unless your program contains a variable called zanzibar). The exception is copied into the variable called trace which you can then do what you like with.

Out of date spam

Does anyone know how I can delete all the emails from a particular sender on Gmail using the web client? You would think that this would be easy. There would be some way of specifying the sender and then a convenient button that you could press to delete everything.

If there is such a button, I’ve not been able to find it. All I can do is work my way through pages of mails, deleting everything in each page. It’s almost as if Google want to make it hard for you to get rid of dross so that your email fills up and you have to pay them for extra storage….

Happy snaps at the Hardware Meetup

There is a lot of detail in the gloom, Thanks to Ben for arranging the elements in this shot

We had great fun taking pictures and developing film at the Hardware Meetup tonight. Ian’s film, taken on a 100 year old camera, looks really good. My shots suffered from serious underexposure/developing, but I’ll have some scans tomorrow.

Update: By using a magical power called “Posting From the Future” I’ve added a picture. It seems that I seriously overestimated the power of the flash I was using. I think it looks good and properly atmospheric.

Im quite pleased with how this picture looks as well.

Analogue Photography at the Wednesday Hardware Meetup this week

I’m getting bits and bobs together for the Film Processing Hardware Meetup on Wednesday this week (12th of November). We’ll have 120 and 35mm film plus some cameras to play with, along with some cameras to play with. We’ll take some pictures and then develop them. If you fancy having a go at analogue photography (or just want to see how it works) then come along to the MakerSpace at the top floor of Hull Central Library on Wednesday evening from 5:00pm. We’ll develop a few films and you’ll be able to take your negatives home with you (although they might be a bit wet).

Creating Multi-Colour prints from FreeCAD

I need to work on the letter sequencing…

I’ve been working on the self-solving wordsearch for a while now. Today I’ve been creating two different models for the case, one is the white outer case and the other is the black letter grid. I managed to print out a small test piece and I’m quite happy with how things turned out. The idea is that I put lights behind the letters and you can watch the answers appear.

This is the back of the text. There are some bad bits, but they don’t really show

The design is built using Python in FreeCAD which made it very easy to create and align the two models. Next step is to make the full size (16x16) wordsearch and then print it out, which might take a while. Great fun.

Rob at The Tech Sessions in Hull on December 2nd

If you are in Hull you should go to Tech Sessions. If you aren’t in Hull you should come to Hull. And then go to Tech Sessions. I’m doing half of a session at the University of Hull starting at 6:30 pm on December 2nd in the Brynmor Jones library. I’m talking about making stuff. The other half of the session is from Rory Reid who is talking about writing meaningful, valuable, and maintainable tests.

And there will be free food and drinks too. And it’s free to attend. You can sign up here. Why would you not?

AI is nice. Only humans can be kind.

A nice person can be expected to give you what you want. A kind person can be expected to give you what you need (which might not be what you want). AI is in the business of being nice. Once it has figured out what you want it considers that the job is done. It is really hard for a human to work out how best to be kind, and it is a human thing to want to try.

I’m far from convinced that we can ever encode kindness into an AI. I think it adds a layer of introspection which would be an order of magnitude bigger than what we are doing at the moment. This doesn’t mean that we can’t use AI. It just means that when we do we need to remember that is only ever nice.

Snap Fit Fun

I’m trying something different with 3D printed components. Snap fitting. Rather than using screws and whatnot I’m cutting grooves in one element and putting a lip on the other so that they snap together. It’s all done by the software that makes the panels, and I’ll be able to tweak the size and configuration of the snapping bits. All I have to do now is print the parts and see if they snap together….

Light Leaks?

This one looks OK

I think I have a light leak. Either that, or something weird is happening with the film developing process.

At first I thought this was cloud, but it isn’t

This one has weirdness down the right hand side.

It’s here too

I don’t think it is problems developing because that would lead to dark marks, and these are light. I think some light is sneaking down the side of the dark slide and getting onto the film. It might be time to invest in some new felt here and there…