Stocktaking

At the hardware group on Thursday, when we were talking about hardware for new members. We have a kit of parts that we make available for those who want to have a play with Arduinos and I realised that I had absolutely no idea how many devices I had in stock. So on Friday I spent a while going through all my little boxes from China and counting devices.

I then thought it might be a good idea to label some boxes for all the various bits and pieces. I thought I could use a whiteboard maker to write the stock levels on the printed labels. When I use something I can then just rub off the number and write another one. You can trace the evolution of the labelling process above through:

  • Using these printed labels with big letters is fun

  • I’d better switch to smaller text, running out of labelling tape

  • Ah. No labelling tape left. Let’s just write letters on insulating tape…….

Windows 10 October Update

I installed the latest Windows 10 update over Wednesday night on two machines at the same time. I was quite amused to see my lowly Surface Go upgrade in around same time as my proper desktop. The Surface Go is really growing on me.

The installation just worked. On Thursday morning I had the new system running. I’ve not noticed much different to be honest. The biggest change for me so far is that the Snipping Tool is being phased out. This has been a mainstay of my workflow for a very long time. One of the first things I used to do after installing Windows was put a shortcut to the Snipping Tool on the task bar. It was very good at capturing the entire contents of windows. It did have its foibles though. One of the most annoying was that when you drew with a white pen on a white background the pen disappeared. I’ve wondered for a long time why this has not been fixed.

I’m talking about the Snipping Tool in the past tense because I’ve switched to the new replacement, the Snip & Sketch tool. It seems to do all the things that the Snipping Tool does. I even used it to capture the image at the top of this post. It also sets the cursor colour correctly when drawing, which is a step forwards.

I’ve not noticed any huge changes in Windows 10 so far. But I’m looking forward to doing some more exploring.

Connexin Live

I can’t help thinking that HullOS has a much better ring to it…

A couple of weeks ago I was at the Hull Arena marvelling at how Hull could put on such a fantastic digital awards ceremony. Today I’m at the same place marvelling at how Hull can host a splendid technical event. One of of the first thing the delegates were told about Connexin was that they are a Hull company. Born and bred. And proud to be here.

Connexin are a local company with global plans and big hitting partners in the form of Cisco. A Cisco person had even flown all the way from San Francisco to speak at the event. The theme was something very dear to my heart; Smart Cities. We heard from Hull City Council and Hull University about their ideas for the future and from folks from Newcastle about what they had been up to.

These are challenging and exciting times for local government. Challenging because budgets are being squeezed as never before, and exciting because technology is showing real potential for improving the lives of the people that the councils serve.

It was great to hear all these inspiring plans being laid in Hull. I couldn’t stay to the end unfortunately, I had to go and see how the Hardware Group at c4di was getting on. The answer, by the way, is very well. We’ve got three new members who’ve turned up and want to have a go with the Arduino. I’m putting together some kits for them for the next meeting. You can come along and have a go too if you like. The next meeting is on the 11th of October at c4di, starting at 6:00 pm.

Hot Fingers

I’ve been doing a lot of 3D printing lately. What with josh lights and everything. Today I thought I’d replace the print nozzle on Una, my 3D printer. Turned out that hardest part of the process was finding the replacements that I’d rather sensibly bought a while back. I looked where they should have been and didn’t find them. This triggered a huge hunt all over the house, loft and garage. All to no avail. So in the end I resorted to going tack to where they should have been and used the ancient old trick of looking properly. And of course they were there, tucked in the bottom of the drawer. Idiot me. But, on the bright side I now know where lots of things are that aren’t 3D printer nozzles.

Replacing the nozzle on a 3D printer is made much more exciting that it might be by the way that you have to do it when the print head has been heated to 200 degrees centigrade. Fortunately I’ve done this before, and consequently no longer have any nerves in my fingers so, in no time at all, the old head was off and the new head on. I think the prints look better, which is a good thing.

MQTT topic management conundrums

Well, this sounds like a gripping title for a post eh?

But actually for me it’s a thing. I’m getting my head around MQTT as a way of sending data from our air quality sensors to the systems that want to work on the data. MQTT is a “publish and subscribe” transport. An MQTT node can send messages to a particular address managed by sn MQTT broker process running on a machine somewhere. Other processes can subscribe to that address on the broker and, when the mode sends a packet of data (string of bytes) to the that address the broker will then send that message to everyone who has subscribed to that address.

Make sense? OK, think of it as a mailing list for a pop star, perhaps David Essex. Anyone interested in what David is up to can subscribe to the mailing list, which has a particular name. David’s publicist, who produces the content describing the amazing life that I’m sure David has, (other pop stars are available for this exercise) connects to the mailing list as a publisher, and sends messages which are then sent out to all the subscribers. So MQTT Is basically a fan mail management system.

The address expressing the a particular endpoint is called a topic. Topics are hierarchical. So, an air quality sensor could send a messages to the following topics with the respective data items from that sensor:

Sensor01/temp
Sensor01/pressure
Sensor01/humidity

Alternatively, an air quality sensor could send a single message containing all three values, encoded as a lump of JSON (JavaScript Object Notation) to a single endpoint:

Sensor01/data

Which is better? I’m not sure. Object Oriented Rob says that having all the related items in a single cohesive object which can also contain things like timestamp and location information will make it much easier to process. Free Wheeling Rob says that having individual data on separate topics makes it possible to handle data produced at different rates by different sensors, and also makes it easier for something only interested in temperature (a fan perhaps) to just subscribe to that data item. And both Robs need to remember that the broker is just that, a broker. It doesn’t have any bearing on what will happen to the values that are passed through it from a device to a process that is doing something with it.

As usual, when faced with a problem like this, I’ve gone a bit meta. To me the important thing is probably not which particular way the values are configured for a given application, but that it should be easy to change this configuration during the lifetime of a node. To this end I’m working on a little protocol which will let a node advertise the readings that it has available and then be told which readings to be sent where. Once a node has been told where to send its data it will do that until told otherwise. This means that we can change how we use the sensors so that we could use either of the above approaches.

The good news is that this will be wonderful. The bad news is that I’ve got to do it. Oh well. Today I got a Python program talking to MQTT. The next step is to get JSON working on the Arduino so our systems can start exchanging configuration information.

Talking MQTT

Ha! Today has been a good day. I’ve got my Air Quality sensor talking MQTT to the Connected Humber server and sending messages. This has been a bit of an adventure, mainly because I had to mess around with the libraries for the Heltec device that I’m using.

Anyhoo, I’m now sending messages over both LoRa and MQTT at the same time. Go me. Now I just need to add some configuration options and I think we might actually have a product here.

Incidentally, I’m using a Windows app called MQTTBox to view the messages on the server and post test messages to my sensor. Works rather nicely. And free.

Pointers to Functions in C# and Python

After the description of pointers to functions in C it occurred to me that you might like to know how to do function pointers in other languages. Then again you might not, in which case just look at the picture above that I took in Singapore a while back.

Pointers to methods in C#

If you want to make a reference to a function in C# you need to create a delegate type which contains the reference. Instances of the delegate type can then be made to refer to methods. It’s a bit more long-winded than the C way of doing things, but delegates can also be used as the basis of some quite powerful publish and subscribe mechanisms which I might mention later.

class Program
{
delegate void SimpleDelegate();
static void aMethod()
{
Console.WriteLine("Hello from a method");
}
static void Main(string[] args)
{
SimpleDelegate myDelegateInstance = aMethod;
myDelegateInstance();
}
}

This is a tiny example of a program that uses a delegate to make a reference to a method. The delegate type that I’ve created is called SimpleDelegate. Variables of this type (I made one called myDelegateInstance) can be made to refer to a a method and then called.

If you compare this with the C syntax, it’s not that different. The good news is that before the program runs the compiler can make sure a program will never call a method incorrectly using a delegate. Because SimpleDelegate is declared as returning void (i.e. nothing) and accepting no parameters it is impossible to make instances of SimpleDelegate refer to a method that returns a different type or has a different set of parameters. If you worry about these kind of things, this is a good thing.

Pointers to Functions in Python

If you want to make a pointer to a function in Python you just do it:

def a_function():
print("Hello from a function")

function_ref = a_function
function_ref()

The variable function_ref is made to refer to the function a_function and the function_ref variable can then be called as a function. Later in the program function_ref might store an integer, or string, or a reference to an object of type Cheese. That’s how Python is. This means that a Python program can fail in ways that a C# program won’t, because the errors that cause the Python program to fail would be picked up by the C# compiler.

This nicely encapsulates the difference between the cultures of C# and Python. C# is great because it forces you to invest effort to make sure that the objects in your programs can only ever be fitted together correctly. Python takes everything on trust. It lets the programmer just get on with expressing the actions to be performed and assumes that things will turn out OK. If they don’t the program will fail at runtime.

I love the way that C# forces me to think about my code, and I love the way that Python just lets me get on with writing, without me having to worry about adding lots of extra syntax to express what I know I want. You should know about both ways of working.

Crazy Rich Asians

Now, don’t spread this around, but I quite like a good Romantic Comedy every now and then. If you all you go to is superhero films you get a bit tired of great slabs of exposition about “Shifting into the Quantum Space and causing the end of the universe” in between huge, choreographed fight sequences. And occasionally it’s nice to see a film in which the none of the laws of physics are broken.

Crazy Rich Asians is about a bunch of people, most of whom are crazy rich. It has all the required rom-com ingredients and it mixes them together really well. For me the biggest star is Singapore, which looks awesome. I was lucky enough to go there a few years back and now I want to go all over again.

If you like a good comedy which is well played and (not really a plot spoiler) a nicely realised happy ending then it is well worth the trip. The exuberance of the cast and the flair of the production are really uplifting. Great fun.

Pointers to Functions in C

I’m re-writing my neopixel animation software for the new light. I’m using a C feature that is sometimes very useful. I’m using pointers to functions.

Note that this is quite strong magic. If you don’t use it properly your program will just stop with no errors or warnings. But then again, that’s pretty much how it is when you write Arduino code anyway, so feel free to have a go. You won’t break any hardware.

The reason why I’m using function pointers is that I want to make the program to select between different animations to control the lights. The update behaviour for each animation is a different function. For example, I’ve got two different displays, one which walks colours around the lights and one which just displays the text in a particular colour. That means I’ve got two update functions:

void update_coloured_message()
{
// update the coloured message
}

void update_text_message()
{
// update the text message
}

Each of these is a function that accepts no parameters and does not return a result. I can create a C variable that can refer to these methods as follows

void (*animation_update) ();

This rather convoluted syntax creates a variable called animation_update that can refer to methods that accept no parameters and don’t return a value. I can make this variable refer to one of my update methods by using a simple assignment:

animation_update = update_text_message;

Note that normally when you want to create a reference to a value in C or C++ you need to put an ampersand (&) in front of the thing you are getting a pointer to. In the case of function references you can leave this out. This is either a neat trick to make C programming easier or a nasty trick to make C programming more confusing. I’ll let you decide.

Anyhoo, once I’ve set animation_update to refer to a function I can call the pointer just as I would the function:

animation_update();

I’ve actually gone one more, in that I’m using function pointers in a structure. Go me. I’ve got a structure that describes an animation in terms of the function that sets up the animation, the function that updates the animation and the number of frames it should run for:

struct Animation_item
{
void(*animation_setup) ();
void(*animation_update)();
int duration;
};

I then create an array of these items that contain all the animations that I want to move between:

struct Animation_item animations[] = {
{ setup_coloured_message, update_coloured_message, 600 },
{setup_walking_colours, update_walking_colours, 600} };

Then just need to count around the array to move between animations.

animations[animation_number].animation_update();

This statement calls the animation update method for the animation that is selected by the value in animation_number. If I add more animations to the array my program just picks them up automatically with no need to change anything else.

"Do It For Josh" Light

Joshua (Josh) Barnfather is a lovely chap who needs your money. Really. You can find out here why he needs the cash. And also give him some. Please.

Josh is a member of c4di and I’ve been really moved by the way that the community has rallied round to help under the tag line “Do it for Josh”. We’ve had Nibble, the local eating place, pitching in with a “Josh” sandwich (which is delicious - I had one on Thursday) and lots of members coming up with neat ways to bring in the cash. Since I can’t make sandwiches as good as the ones that Nibble turn out, I’ve decided to make something electronic.

Behold, the “Do it for Josh” lamp. This prototype will be going in the c4di lobby later this week, but I’d be happy to make one for you. You can even tell me what words you want to put in the 4x4 matrix. A light will cost you fifty pounds with at least forty of that going to Josh. The lamp will be WiFi connected so that you can control the animations from your phone and tell it when to turn on and off. And I’m going to get the Connected Humber bods onto adding even more interesting features.

If you fancy one, just send me an email (rob@robmiles.com). If you want to just want to help, send some money through via the donation page.

Back in the Zone

New board in action

My Twilight Zone pinball machine is the nearest thing that I’ve got to a family heirloom. Rather sadly, it’s been poorly sick recently, owing to some leaky batteries. These are rather stupidly mounted over the main processor board and covered some important chips with corrosive liquid. Although I managed to get the board back to life by cleaning it up a while back, a few weeks ago the input connected to the game start button failed, which made it rather hard to get a game.

Fortunately, even though (or perhaps because) the machine was made in the mid nineties you can still get replacement circuit boards. These are re-manufactured using the same components as the original and, once I’d got one, my machine sprang back into life.

Hull Pixelbot at the Digital Awards

Hull Pixelbot finalist in two categories. Yay!

Hmm. Three blog posts in one day. What an interesting life I lead….

Anyhoo, today it was time to put on my best smart casual wear and head for the Bonus Arena for the finals of the Digital Awards. This was all rather exciting. Firstly because the Hull Pixelbot is a finalist in two of the competition strands, secondly because I really fancied having a look around the new Bonus Arena, which is where the event is being held.

Well, the arena is is splendid. After an lovely meal, accompanied by a saxophonist with a fantastic illuminated saxophone, we went through to the arena for the awards themselves. We had a few speeches at the start which were all shot through with a theme that this is a great place to do digital business. One speaker made the point that they were feeling a bit sad about being in the bottom 48% of Lightstream users in Hull for network performance. He was cheered up a lot when he found that this still meant he was in the top 2% of network users in the country.

And another fun fact stood out for me: A third of the optical fibre in the UK is under the streets of Hull. The government has set what it calls an ambitious project to get all households in the UK connected to fibre by twenty thirty something. KCOM (the telecoms company that provides home networking in Hull) will achieve this in Hull by the end of March next year. Other cities in the UK are now playing catch up with us. Big time. And, we don’t just have networks. We have talent too. As the awards were about to show.

Mark Dolan was a great compere

I’d not seen that much of Mark Dolan before to be honest. But by gum he’s good. After a brief (and very amusing) comic set to break the ice he got things going and presided over the proceedings with some wry observations and knowledgeable comments. The finalist in each award category was introduced by a short video of them in action. Which for me meant two sessions of squirming in my seat as I watched pictures of me and my stuff on the enormous screen. Although I loved the moment when the audience went “Ah…” when they saw a bunch of Hull Pixelbots doing one of their little dances.

I didn’t win. I didn’t expect to, to be honest. I’d taken a look at the field and come to the conclusion that there were much better entries in my categories than mine. But I was mightily honoured to have been picked to get into the finals. And I did get two lovely certificates in really nice frames. One for the office at c4di , one for home. And If you check the awards lineup you’ll see that the Hull Pixelbot was actually first in each category. Alphabetically…

It’s a measure of the confidence that I’m seeing in the area that it can put on what I consider to be a world standard awards ceremony. I’ve been to a few of these over the years and the whole setup, the organisation, the venue and the presentation really was world class. And, and this is the really wonderful bit, so were all the finalists. The winners were real stand-outs.

I was especially pleased to see Hayden Barton win “Young Digital Person of the Year”. I first met Hayden at a Hardware Meetup at c4di when he showed me a neat little device he’d brought along. “That’s nice” I said. “Where did you buy it?”. His reply marked him for greatness in my book. He said “I made it.”.

After the awards we staggered home tired and happy. Thanks to every one who put the event together. Great fun and great for the region.

Build another LoRa Node in a Day

Everyone looking happy at the start

In July we held a “Build a LoRa node” workshop at c4di. It was great fun for us, and those who took part. Today we did it again. I turned up, fresh from my media appearance and helped Robin set things up. As before, the aim was to get attendees to build a working LoRa node and finish up with a device sending environmental data to the cloud.

Everybody succeeded. It was great to watch them all convert a “bag of bits” into a working sensor node and then watch as they saw their readings appearing in their browsers.

We run the events when we get eight or nine people together who want to have a go. They are hosted in the lovely environment of the c4di and we only charge you for the parts that you take away. If you want to come along to our next one, just send me an email or a direct message on twitter and I’ll add you to the list.

Rob on Radio Humberside

The light first thing this morning was rather good

This morning I was up bright and early (oh, OK, just early) and heading into town to review the papers for the Radio Humberside breakfast program. I love doing radio. Apparently I have the perfect face for it. Anyhoo, I settled down with a pile of newsprint and started looking for some vaguely happy stories. There’s so much depressing stuff in the news at the moment that I figured folks would rather hear something a bit uplifting with their cereal.

It turns out that this was surprisingly hard to do. Papers seem to have got a lot more miserable over the years. However, I found a few things to talk about, wandered into the studio and did my bit, which was great fun.

Now, onto building some LoRa nodes….

Test Air Quality with the EMF Badge

The air here seems ok

One of the (many) wonderful things about the electromagnetic fields event I went to was the badge that everyone was given. This was an embedded device with a nice colour screen and a powerful processor that just happened to be a mobile phone as well…… I thought I’d turn it into an air quality display. So I 3D printed a case and make some modifications so that I could fit an air quality sensor and a battery to power it on the back of the badge. This is the back of the badge:

The hardware construction went fine, and I had the badge and the sensor exchanging messages quite nicely. Then I tried to write the software and it all went wrong. So I gave up and decided to enjoy the event instead….

However, I’m not a quitter. So, after a lot of fun and games, I’ve finally submitted my air quality app to the badge store for the emf badge. You can find it in amongst the other apps in the store here. It seems to work a treat and I can wear it around my neck with pride. Although I guess this would probably look a bit silly around Hull, where a lot fewer people seem to be wearing emf badges than there were at the event.

Anyhoo, one significant (at least for me) takeway is that if you want to use the serial port in MicroPython in binary mode (i.e. not have the driver mess around with carriage return and linefeed characters), you can use a special option to request this:

sensor_port = UART(2,9600, bits=8, mode=UART.BINARY, parity=None, stop=1)

This option is, of course, undocumented on the MicroPython pages for the UART class, leading to endless hours of “fun” for developers (like me) who spend ages wondering why their binary checksum values are all wrong…..