Code like an idiot

Hmm. No matter how good you are at programming, developers will still put bugs in their programs. Including me. Lost a couple of hours today because of this little beauty.

if ((tickCount % lights[i].colourSpeed)!=0 || lights[i].colourSpeed==0)
    return;

This code has been working inside HullOS for a couple of years. No problems. However, when I tried to port the code onto a Wemos device it kept crashing with an invalid instruction message.

Wah. The idea is that the code will exit if is not time to update the colour animation (tick count is not an exact multiple of colourSpeed) or if no animation is being performed (colourSpeed is zero). 

It took me a while to figure out what was happening. Turns out this code is wrong, but under some circumstances it will work perfectly well. 

It's all to do with the % (modulus) operator. This gives the remainder that you get if you divide one number by another (or example 7 % 4 would be 3). If the modulus is zero that we have an exact multiple on our hands. So, every time tickCount reaches the next multiple of colourSpeed the program will perform an update. 

Snag is that I've been stupid, in that I use a colourSpeed value of 0 to mean that the light is not being updated. And the behaviour of a C++ program when you do x % 0 is undefined. In other words, any number modulus zero is a stupid question to ask.

To make things worse the fact that I'm doing this bad thing as one half of an or expression means that, depending on the whim of the compiler, the modulus calculation may not get evaluated when colourSpeed is zero. If the code produced by the compiler does the test for zero before the modulus my program works. If the tests are done the other way round the program explodes.

It's an easy fix, just break the single test into two tests so that I control the order they are performed:

if (lights[i].colourSpeed == 0)
    return;
if ((tickCount % lights[i].colourSpeed) != 0 )
    return;

Now we never use the value of 0 in a modulus expression.  

Oh well, just goes to show that you can learn stuff by doing stuff.....

Go see Incredibles 2

Went to see Incredibles 2 on my birthday. It's really good, you might even say it's incred...

But then you might not. However, the action is great, there are some lovely touches and the dialog is spot on. I want to go and see it again. You should see it at least once. 

However, for me the show peaked during an advert at the start for Disneyworld. On the screen in big letters it said "Where nobody has to grow up." And then on the bottom of the screen in tiny letters it said "Height restrictions apply".  

Connecting a ZPH01 Dust Sensor to Python

I've just noticed that one of the wires came of the connector while I was taking the photograph. Oh well.

Anyhoo, some time back I got a dust particle sensor to play with. Air quality is a big thing, but one that we don't have much information about at the moment. An air quality measurement device is also a perfect application for LoRa. Sensors can gather data and then send summaries over the network. As part of ConnectedHumber initiative (of which much more later) we're designing an air quality sensor with the intention of deploying some city wide.

As a start I've connected the sensor to my PC and written a little Python script that gets the readings from it. You can find the script on GitHub here, in the unlikely event that you've got a sensor just like mine.

To connect the sensor to my PC I just used a standard USB to serial adaptor, the kind of thing you use to program Arduino Pro-Mini devices. I connected all the signal pins, and also took the mode pin to ground, so that the sensor will output serial data rather than pulses. 

The sensor works fine, although I've no real idea what any of the numbers mean at the moment. The next step is to get one into a case with a Wemos or LoRa device connected to it. 

Humber Street Gallery: Measures for Life

The Humber Street Gallery has a splendid new exhibition on at the moment. It runs until the end of September. On the ground floor they've got some neat little devices but further upstairs they've got this awesome cityscape made up of computer circuit boards and lights. It's constantly changing and just looks amazing. I've tried to take some pictures of it, but I've not really done it justice. 

The exhibition is free, and there are loads of lovely places to eat or grab a coffee in the Humber Street area too. 

Hull Minster is Awesome

I was really pleased when they made Hull Trinity Church into a minster last year. It hasn't made the building any more beautiful, but it does give it the status it richly deserves.

They've done a lot of work on the building inside too, removing pews and really opening up the space. That, plus the renaissance of Hull Trinity Market (definitely worth a look) makes this part of the town a must-see. 

Running up and down hills turns out to be fun

I've never been that keen on the outdoors. What, with it not having a roof or air conditioning. 

However, on the basis of this trip I'm having to modify this opinion a bit. I think you have to choose your outdoors carefully, and be lucky with the weather, but we've done a couple of walks that I've really enjoyed. I'm not quite at the point of buying an Ordnance Survey map and a pair of waterproof trousers yet, but I'm thinking about it. 

Smart Meter Time

Suitably redacted....

I've probably missed a trick here. I got a message a while back offering a smart meter for my electricity and I said yes. I didn't know that the energy companies were still installing the "old new technology" smart meters. According to what I'd read a while back, by this time everyone would be getting the new type, but for some reason (perhaps because it makes it harder to change energy suppliers without losing meter "smartness") the old-new meters are still being rolled out. And I've ended up with one.

It seems typical of the way that things are presently working in this country that an initiative that is supposed to bring us to the forefront of energy management has been sabotaged right from the start by short sighted decision making driven by commercial interests. Not that I'm particularly worried. The way I see it, if I'm in the 9 million who've got the old meters there's a lot of incentive for companies to make us happy in the future.

I reckon it's quite possible that the potential of the second generation of meters will never be realised because nobody will bother implementing the back end services to make them work. They'll just claim that there aren't enough of them out there to make it worthwhile. Yes, that is very cynical. And probably right. And anyway, the firmware in my meter is upgradeable......

Anyhoo, the meter is now in place and beaming my electricity usage to a remarkably cheap looking device that lets me see what happens when I use the kettle. It is supposed to motivate me to save power, but the first thing I wanted to find out was how far into the red I could send the readout by turning things on.....

Inadvertent Storytelling

I love it when I go through pictures I've taken and every now and then find one that really tells a story. I took this one at the Steam Rally recently, hoping to get a good shot of the car instruments and totally failed to notice the figures in the background.

But, having revisited the pictures I really like the way that this one seems to be all about a couple and their dog, and their shiny MG. 

LoRa Build a Node Workshop at c4di

We've just had a bunch of folks around to build some LoRa nodes. Robin had put together some kits and we came up with a set of instructions. By the end of the day we expected our attendees to have their LoRa nodes sampling temperature, air pressure and humidity and maybe even be viewing the values on The Things Network website. 

Well, we got that and more. One person had the information going into Microsoft Power BI and was using Machine Learning to predict future room temperatures. Another used If This Then That to tweet temperature readings to his phone. Others left with plans to install LoRa gateways and sprinkle LoRa powered sensors all over their properties.

Very successful, in spite of the fact that we were soldering surface mount components and some folks hadn't soldered since they were 14, or even at all. Thanks for coming folks and being so determined. At some points during workshop you could have heard a pin (or other tiny component) drop. 

We're doing another one in September, ping me an email if you want to get your name on the list. You can find our notes and sample programs here.

If you want to play with LoRa (and anything else that takes your fancy) take a look at the Humber Health Care Challenge. We'll make sure we've got some LoRa kits available there for people to have a go with this technology. 

Mightier Than sword or pen?

LoRa at Humber Street Gallery

Today finds us at Humber Street Gallery. We're looking for locations for a LoRa gateway for the area. They've got a lovely rooftop bar which looks perfect, and has some amazing views. Of course, I happened to have my camera with me. 

We were telling the folks at the gallery about LoRa and we're going to go back and find out a bit more about the possibility of LoRa enabled artworks. Could lead to some interesting discussions. 

Bad Telly

Scene 1: A meeting room, a bunch of TV transmitter engineers are sitting round a table. With an accountant.

Engineer 1: 'If we use this form of broadcast antenna we'll have good strong signals all year round.'
Engineer 2: 'Which is what we want. Right?'
Accountant: 'Hmmm. Looks a bit pricey to me. How about this design, which is cheaper.'
Engineer 1: 'Yes, but with that one the signal will drop in the summer.'
Accountant: 'People should be outside rather than watching telly in the summer. Use the cheaper one'

Scene 2: Another meeting room, another bunch of engineers, this time they are the designers of TV input circuits. And of course there is an accountant there too.

Engineer 1: 'If we use this circuit the TV will work, even with low level signals.'
Engineer 2: 'Which is what we want. Right?'
Accountant: 'Yes, but if we take out that amplifier the TV will work for most people, save us some cash in components and we can also make a fortune selling aerial amplifiers.'

And this folks is why every summer televisions in our area stop working....

Waiting for the Ice Cream Machine to Warm Up

We went down to the waterfront today. Wonderful weather, cool breeze from the water. A scene that could be made completely perfect by the addition of an ice cream.

We went into the local ice cream parlour. They were just getting going, what with us being there quite early. Anyhoo, the machine wasn't ready for use, and I had this lovely idea that we were waiting for the ice cream machine to warm up.