Printer Meltdown

Number one son has been showing me things that he’s made with his 3D printer. They are very good. Irritatingly so. I’ve been trying to replicate his success on Una my venerable 8 year old Ultimaker printer. I tried increasing the print temperature and the prints got better and better right up to the point when the filament feed got clogged with molten plastic.

Drat. And double drat. I’ve taken a two pronged approach to solving this problem:

  • I’ve completely replaced the bowden tube, PTFE isolator, heater block and nozzle on Una with the spares that I have lying around for when this happens.

  • I’ve ordered another 3D printer.

Best case I'll have two printers. Worst case I should have a printer that works as well as the one number on son owns.

Name in Lights

sealedbox.png

I’ve always wanted to see my name in lights. Today I’ve realised that ambition. It’s all part of the Connected Little Boxes project. One kind of box has your name in it. I’ve just finished making the boxes and to show an appropriate level of confidence in my connections I’ve actually taken the Apple approach to manufacture and glued all the cases shut. I really hope I don’t regret the decision….

Christmas Wrapping

Screenshot+2020-12-20+at+18.56.40.jpg

A while back I had a go with wire wrapped connections in devices. Today I had another go. It turns out to be a very good way to make small devices. Wire wrap wire is very thin and good to work with. It is also easy to connect wire wrap wire to solder points. You can also connect more than one wire to a single pin on a device.

The wire wrap tools is quite easy to use. The only problem that I’ve noticed is that because I’ve only got one colour of wire wrap wire all the connections look identical.

ESP8266 int alignment fun

OK. Pop quiz. What’s wrong with the following C++ code?

unsigned char * chPtr;
int * intPtr;

// point chPtr at a buffer somewhere

// get an integer out of the buffer
intPtr = (int *) chPtr;
Serial.println(*intPtr);

Perhaps a bit of context would help. I use commands like this to tell my Connected Little Boxes what to do:

{"process":"pixels","command":"setrandomcolour",
"pixelSpeed":10, "sensor":"button","trigger":"pressed"}

This command means “send the command setrandomcolour” to the pixels process when the user presses a button. Fade the colour over 10 “ticks”. This means that each time the user presses the button on the box the lights will change colour.

The box is smart enough to understand this tiny chunk of JSON but I don’t want to have to decode the command every time the button is pressed. So the program assembles a block of memory containing things like the “10” value for pixelspeed and this is read when the sensor event is triggered and used to control the command. Works very well. Except sometimes. Sometimes the code throws Exception(9) and the processor resets.

The error came from nowhere and I spent ages checking the code that I’d just written to find what I’d broken. After a while I took the trouble to look up what Exception(9) actually means, and that’s when I discovered the stupid thing I’d done.

The code above uses a pointer to an 8 bit location somewhere in memory and then fetches an integer from that place. it’s what gets the stored pixelspeed value for the pixels process to use. But the ESP8266 stores integers in a block of four memory locations as a 32 bit value and it insists that these are always aligned. In other words, you put the first value in the bytes at locations 0 to 3, the second at locations 4 to 7 and so on, using the convention that the memory is addressed starting at location number 0. If a program tries to load a value from an “odd” location the processor crashes.

This means that if store something in memory and then try to read it back as an integer I have a 1 in four chance of it working and a 3 in 4 chance of it failing. Up until now I’d been lucky, but today I wasn’t.

When you write an assembly language program you can use special directives to line the data up in the right locations. The same thing happens in C++ when you make a structure. The compiler will insert extra space to make things line up when they should. One way to fix it would be to make sure that I always line things up in my program but this would have been a bit of a pain, so I wrote the function below:

int getUnalignedInt(unsigned char * source)
{
    int result;
    memcpy((unsigned char *)&result,source,sizeof(int));
    return result;
}

You pass the function a pointer to anywhere in memory. It copies some integer bytes into a lined up integer value and then returns the value. It seems to work fine. It’s not the most efficient solution but I can live with that for now..

Cube Cleaning

cuberear.jpg

“A rolling stone gathers no moss” goes the saying. Unfortunately it turns out that a non-rolling white car gathers rather a lot of moss. Our little cube has acquired a bunch of green streaks that really needed to be dealt with.

So today I did. I’d read on the internet that toothbrush is very useful for getting little bits out of the various nooks and crannies in the bodywork. And so it turned out. The Cube is now a lot whiter than before.

Although I do get a funny taste in my mouth when I clean my teeth now…..

Drilling comedy holes

I put up our Christmas lights last week, what with it being close to Christmas. I’ve not seen the neighbours getting out chairs and drinks to watch me work, but they should do. I’m quite entertaining when I try to do this kind of DIY.

First thing I had to do was make a hole in the garage wall. In previous years I’ve just threaded the power cable for the lights through the edge of the garage door. However my shiny new garage door fits a bit more closely, so the lazy way is no longer an option.

I carefully planned where the hole should be and got out my special long drill bit. I’m very proud of it. It can go through one or more than walls at once. I started drilling and the wall seemed to go on for a very long time. So long in fact that the drill got stuck. So I was forced to leave the drill hanging off the wall with the wire still connected as I pondered what to do next. It looked as if I’d hired the invisible man to do some DIY for me.

Eventually after a bit of fun and games with a mole wrench I managed to wrest the drill out of the bricks. I discovered that I’d drilled into the side of the garage. In other words there was no inside to this hole, it just went on for the length of the building and out of the back.

The second hole was much more successful, and shortly after that I had my lights up and working. I told number one son that I’d drilled two holes that day, one in the wrong place and one in the right place. “Oh” he said. “Which one did you drill first?”

Developer Developer Developer 2020 online

cat Viewer.png

Giving a session online is a very strange thing to do. You sit in a room in front of a camera giving it your all and hoping that there is someone on the other end watching. I was first on one of the tracks, so I was able to kid myself that I was actually doing the keynote presentation….

I did a talk abut Bluetooth and Furbies. It seemed to go OK, except for the bit at the end where I lost my way around Teams and couldn’t find the Q&A window. As you can see above, the I was also doing well with the feline audience. Thanks to @developerday for the picture. All the sessions are going to appear on YouTube in due course. Keep an eye on here.

Compile early and compile often

yet more leaves.png

I’ve been writing a big and complicated program for a while. I’m not sure if it is supposed to be big and complicated, it just seems to be turning out that way. And one of the things I’ve remembered from my days of doing this kind of thing is “compile early and compile often”. If you wait a while before hitting the compile button you can sometimes get so many errors that it can take you a while to figure out. Modern editors are quite good at spotting coding mistakes as you write, but there is nothing like letting the compiler take a proper look at your code.

I’ve been hitting compile every time I’ve written a few lines. That way, if I get an error I don’t have to look through much text. I do this even though I’ve no intention of running the program at that stage. It’s just that when I’ve done a bit that I think should compile it is worth getting the proper opinion on the matter.

When I was teaching programming we used to get people come in with 500 line programs that didn’t compile and they weren’t sure why. They’d written all the code down and then hit compile and were surprised by the number of errors they got. I used to tell them that a good way to start would be with an empty program that compiles and then add the statements a small amount at a time, compiling at each stage.

Conducting currents

The toaster failed yesterday. It did this at exactly the same time as the lights went out and the radio stopped working. Coincidence? I think not.

It turned out that one of the currents had fallen out of a teacake and landed between the element wire and ground. The resulting current flow (I like the way that sounds) had triggered the earth trip on that power circuit. So all I had to do was figure this out, and then go into the garage and flip the switch into the on position.

Current through currents is not always a win.

Solder pranking

When I was younger than I am now and much less responsible one of the standard workshop tricks we used to play on each other was to replace someone’s solder with a piece of solid core wire. They look very similar, it’s just that one of them doesn’t melt when you apply it to the soldering iron.

I did this to myself today. I’ve been wiring up some connected little boxes with solid core wire and I started to try and melt it. It took me a while to figure out what I’d done. If I’d done it to anyone else I’d be quite impressed with myself. As it was, all I did was burn my fingers a little bit…

Fixing Windows 10 USB problems

mouse power.png

Ever since I got my desktop (four years ago) I’ve had a problem with my mouse and Bluetooth connections randomly disconnecting. This was very irritating, particularly if it happened as I was coming into land or under heavy fire. Or both.

Number one son reckoned that my machine was possessed in some way, but it turns out that the truth is much simpler. I was allowing Windows 10 to turn off these devices to save power. I’ve no idea why a desktop machine should turn off your mouse and keyboard connections in this way, but it does. You have to explicitly tell it not to by using the USB Input Device Properties dialog above that you can find in the Device Manager. I made the change (for all my USB devices) a while back and it has worked for me so far.

Alarms are complicated

I’ve always found it surprising how simple things end up being complicated. Take adding alarms to my Connected Little Boxes…. I want to have alarms that I can set in the device. When an alarm time is reached I want the device to perform an assigned action, perhaps make a sound, drive a servo or change the colour of a light. This is simple I say to myself. And I write a function to celebrate:

bool atAlarmTime(struct ClockAlarm *alarm, struct clockReading *reading)
{
    if (alarm->hour != reading->hour)
    {
        return false;
    }

    if (alarm->minute != reading->minute)
    {
        return false;
    }

    return true;
}

The function will return true when the clock reaches the alarm time. I can use this to trigger whatever action is bound to the alarm. Simple.

Well, not really. My program will be repeatedly checking the alarm to see if it has triggered. So if I just use the above function I will find that an alarm will trigger continuously for the entire alarm minute when it due. And what about when I turn the device on or change the time? Do I want it to ignore “past” alarms or not? If my device was controlling a heating system I’d want it to respond to an alarm even to turn the heating on even if that event was in the past. Otherwise I’d turn the system on at 12:00 and freeze because the event that turned on the boiler was set to 7:00am.

I’ve ended up setting up options and flags and writing code that spins through the set alarms looking for ones that should have been triggered and triggering them if that is what the user wants. Yep. Alarms are complicated.

"Don't Buy" PIR Sensors

dontbuy pir.png

More PIR advice from Rob….

The UK consumer magazine Which? has a “don’t buy” advisory that it slaps on really poor products. I think I’ll have a go at that. I rate these HC-SR505 PIR sensors as a don’t buy. I got them thinking they would work as well as the HC-SR501 sensors that I’m using for my “Connected Little Boxes”. It turns out that they are a bad bet for two reasons.

  1. When they detect a person they hold that signal for around 13 seconds before releasing it. The timeout of the HC-SR501 can be adjusted and it has two different detection modes which are much more flexible.

  2. They stop working after a few hours.

Definite don’t buy.

Things not to do with PIR sensors

pir lense.png

“Hi. I’m Rob. I do stupid things with hardware so you don’t have to”

Today I thought it might be a good idea to see what happens if you try to use a PIR sensor without the plastic dome lens on top. I figured that I’d be happy to sacrifice a bit of sensitivity for a cooler aesthetic. In other words I wanted to get rid of the ugly dome and put the sensor behind a 3d printed panel.

Preliminary tests suggested that this might work, so I designed and printed a case lid and put the sensor behind it. Then it didn’t work at all. I think that 3D printed PLA is probably a bit too opaque to the infra-red signal that the sensor uses. Oh well.