Restoring Arduino servo movement

clb turner.png

Servos are a great, cheap, way of giving your devices a bit of physical movement. You can pick little ones up for around a pound each and a single Arduino can control quite a few servos. You can make a Connected Little Box control a servo. In the example shown above you turn the knob on the left and the servo on the box on the right turns, tracking it. However, there are two bad things that a servo can do:

  1. Not move as far as you might want it to.

  2. Burst into flames trying to move to a point that it can’t get to.

The writers of the Arduino servo library have decided that point 2 is actually more important than point 1. So they’ve changed the way that the servo libraries work. This caused some of our servos to misbehave. How did we fix them? Read on…..

When you want a servo to move you give it a pulse of a particular length. The servo converts this pulse into a value which is matched against one that represents the position of the servo output shaft. The servo attempts to turn the shaft so that the two values are the same, causing it to move to a particular position. If something tries to move the shaft away from this position the servo will push back. If the pulse size changes the servo will move the output shaft in response. So far, so wonderful.

But what happens if the computer gives a pulse that is converted to a value that the servo shaft can’t match? The answer is that the servo will try to move to that position and get stuck on the way, stubbornly pushing until coils heat up and melt, gears break and so on. And then you have to buy a new servo.

The original Arduino libraries for the servo assumed a range of movement that some servos can’t match. So they’ve reduced this range. The range boils down to two values that used to be 544-2400 but are now 1000-2000. The new range makes servos a lot safer, there is less chance that they will move into dangerous positions, but it does significantly reduce the amount of movement that you get. The good news is that you can override the pre-set values when you attach to your servo:

servo = new Servo();
servo.attach(2,544, 2400);

The statements above show you how to do this. The first statement creates the servo. The second attaches the server to GPIO pin 2 and restores the range of movement to the values used in the bad old dangerous days.

ESP32 DOIT reset procedure

esp32.png

One of the things I like about WEMOS ESP devices is that they can be reset into boot mode via their usb serial connection. However, I’ve also bought a bunch of these ESP32 DOIT devices which are really cheap, which is nice, but you need to boot them by hand whenever you want to transfer new code into them. I thought I’d write down the process, since I seem to keep forgetting it:

1.       EN down
2.       BOOT down
3.       EN up
4.       BOOT up

Do this while PlatformIO (or Arduino) is trying to load a program into your device and it should connect and work.

Read Ask Iwata

iwata.jpg

Satoru Iwata was a corporate president who disproved the notion that heads of large companies must have egos to match their salaries. After running his own software company for a while he became Chief Executive Officer of Nintendo at a time when the company was not at its best. He transformed their fortunes by launching a bunch of ground breaking products including the 3DS and the Wii.

He was taken from us at the tragically young age of 55, but not before he had inspired a whole generation of engineers with his constructive and empathic leadership. The good news, for us, is we can get a copy of Ask Iwata, a set of essays and musings from the man himself. I got one today as a Father’s Day present and it is a lovely read for anyone interested in working with people and achieving great things.

Debugging with Magic

Trying a new blogging approach. Blogging when I have something to say, rather than fretting about making a post every day……

Only a code magician can fix a program by renaming a variable. That’s me.

I’ve just encountered an hilarious (and by hilarious I mean horrible) bug with an upgrade to the ESP8266 compiler. I’ve been building my Connected Little Boxes software for quite a while now and it just works. Today I noticed that I had upgrades to the Espressif SDK in Platform IO. So, like a fool (and I do mean that) I pressed OK to upgrade them.

And suddenly my newly built program broke. It would start running and then spontaneously explode with Exception(29). Which means that my program is twiddling a memory location that is not where it should be.

First step was to recompile the code for the ESP32 processor (my code works on both). That worked fine. OK, so it is not necessarily something stupid that I’ve done. Back to the ESP8266.

It’s hard to debug code running in a separate device, but after a few minutes (I am pretty good at this - although I was slowed down as bit by the way that the bug vanished when I enabled debug mode) I’d isolated it to this statement:

RegistrationProcessDescriptor.status = REGISTRATION_OFF;

It runs during startup and turns off the registration process. But I guess you’d already worked that out because my commenting game is so good. Anyhoo, when this statement runs the device explodes.

OK. Welcome to planet weird. First thought is that RegistrationProcessDescriptor is not pointing to the right place. But it is. Otherwise the call to the exploding function would not have worked. So, second thought is that REGISTRATION_OFF is a silly value. It isn’t. It’s 1004 since you asked. And status is an integer property in case you were wondering, so everything make sense and the code has been working perfectly for ages…..

Of course I’ve fixed it. I’ve renamed the variable RegistrationProcessDescriptor to RegistrationProcess. Something deep in the compiler must be getting upset about long variable names and dropping dodgy code. There were a few clues:

  • It works with a different compiler

  • It worked when I changed the code a bit (by adding debug)

  • The variable name was a bit longer than ones I normally use

I’m not happy that the problem occurred, but I’m pleased I was able to fix it.

Bye bye to the piano

insidepiano.jpg

I said goodbye to over 50 years of my past today. Two men came and took away the piano. Our family got it in the 1960s and I, and my sister did our piano practice on it. Then it found its way into our house and we inflicted piano lessons on our kids too. It has been a fixture in our house every since.

It’s been rather neglected for the past few years though. It was heralded as an interesting instrument when it was launched because it used a novel, weight-saving design to mount the keys. Unfortunately this design also meant that after a while all the plastic key mountings fell to pieces giving the instrument a rather snaggle toothed appearance and making the keys not work properly. Then the felts all got sticky so that notes would play forever so for the last while it has been a nice ornament but not really useful. So we decided to get rid of it and get something more up to date that we might actually play. This was done with a heavy heart, but you have to keep moving forwards in this life.

I asked the man who took it away if it would go to a good home. I had a vision of some kind of retirement home for pianos where they could see out their days with plenty of tunes and whatnot. “Well”, he said “we’ll melt down the frame and turn the case into firelighters”. Oh well…

Ratchet and Clank - A Rift Apart

ratchet and clank.jpg

I’ve just spent nearly seventy quids on a video game. Oof. That ‘s a lot of money. And I haven’t got anything to show for it. Just an entry on a server somewhere in the land of Sony noting the fact that they have just made me a bit poorer. My PS5 is one of the ones that doesn’t have a disk drive. I was very happy to get it back last year when they were very hard to source. I don’t buy many video games. This is the first one I’ve purchased since the first week of ownership. I find that the PlayStation Plus monthly subscription gets me enough new toys to play with. However, I’d been planning to get this game since the console came out.

It is very good. The only jarring note for me was the way that the first screen I saw after downloading (a 45G download in about 12 minutes or so - thanks KC) was one offering me a chance to spend an extra 10 quids on the “deluxe” edition of the game. As if. However, the gameplay, the writing and the effects are very impressive. Movie impressive. They’ve used all the colours in their paint box, plus a few new ones, to make a bright and vibrant environment for you to blast your way through. I’ve not played it for that long, but I know enough to want to play it through to the very end. Then I want to go back through again and spend more time looking at the scenery.

And I seem to remember that when the first PlayStation came out all those years ago some of the games were nudging 60 pounds or so a pop which, allowing for inflation must have been a sizeable chunk of change back in the day.

Project Blogging for Fun

flowersburnby.png

It’s been a bit quiet on the blog for the last few weeks. I always said that I blog because I want to force myself to do interesting things so I can write about them. Recently there have been so many interesting things going on that I’ve not had time to write the blog, which is an interesting problem. Or perhaps I’ve persuaded myself that I’m too busy to blog…

That is going to change a bit now though. I’ve decided to experiment with “project blogging”. I’m going to take the thing I’ve just done, which is create some JavaScript code that runs in a web page and can load code into ESP devices, and write it up. I’m doing this retrospectively from diaries that I kept during the development process. If you’re a programmer it might be an interesting read. The posts will appear around the time I did each task. I’ve tidied things up a bit to reduce the number of dead ends and whatnot.

They start around here. If you then click the left hand link at the bottom of the text on each post you can move through them in order. There will be other topics here and there too, and some pictures. You can just see the project posts by using this link.

I’d love to know what you think of it and how I can improve the presentation content. Feel free to comment (he said dangerously).

Connected Little Boxes servo pulse

I’ve added a new feature to the Connected Little Boxes software. You can now ask a servo to move to a certain position, stay their for a specified length of time and then move back to its previous position. This makes it much easier to create devices where you want to open a lock or wave a flag.

{"process":"servo","command":"pulseservopos","value":1,"pulselen":2.5}

The command above will move the servo to the end of its travel (the value 1) and hold it there for 2.5 seconds before returning it to its original position.

Apple TV in less needy shock

Yesterday I got a nice new remote for the Apple TV. Today I noticed another improvement to the Apple TV user experience. The new remote has a prominent power button. You can use this to turn your Apple TV (and anything else connected to it) on and off.

You might think that this should not be news. It is after all what a power button should do. You are correct, but the thing is that in the past the Apple TV has always been a very “needy” device when I’ve used it. Previously, if the Apple TV was turned on and had HDMI control enabled it would to grab the foreground at every opportunity. Even if you didn’t want the Apple experience at that precise moment you seemed to have it thrust upon you.

The new device is much more relaxed. The Apple TV is happy to sit in the background until you wake it up.

Apple TV Remote

apple TV remote#.jpg

I’ve had an Apple TV for a while. I like the Apple TV. I hate the remote that came with it. The very first Apple TV devices had a lovely little silver remote that had just enough buttons to be properly useful. It was very well made and worked a treat. The next Apple TV that I got had this horrible black thing. It looked like it had actually been designed so that you couldn’t tell which way up you are holding it, so that using it involved a lot more messing around than it should. It also had a touch pad that was as useless as it was unnecessary. In short, not good.

Then, a while back, Apple announced a new Apple TV remote. As I use Apple TV a lot, i thought I’d get one. It is annoying to have to spend lumps of cash to get to a situation where you should have been at the start, but the new remote does a good job of making amends. The buttons are nice and clicky, the design makes sense and it works very well. I’m now a less unhappy customer than I was.

The Price of Greed

This post doesn’t reflect well on me. I present it as a salutary tale about greed.

When I started working on the “Connected Little Boxes” I invested in the domain name “cleverlittleboxes.com” as I thought that might work for the name of the product. Then I found out that there actually is a company called Clever Little Boxes which rather scuppered my plans. So I switched to the name “Connected Little Boxes” which is just as meaningful and ties in rather well with our “Connected Humber” project. I spent another six pounds or so on “connectedlittleboxes.com” and went on my merry way.

Last week, via a domain sharing thingy, I got word of an offer for the “cleverlittleboxes.com” domain. The mysterious purchaser was offering 199 dollars for the domain name. Visions of riches swam in front of my eyes. Or at least, enough riches to get a new iPad. So, having done some research on the domain selling site I sent back a counter proposal of around half the price of what I saw as comparable names. This is a long-winded way of saying that I got greedy.

Anyhoo, today I got a rather sniffy response from my mysterious buyer, complaining about my profiteering actions and dropping the offer to a very iPad unfriendly 50 dollars or so. Oh well. I’m going to hang on for the domain for now and see what happens.

Imagine Cup Judging

I’ve got very fond memories of the Microsoft Imagine Cup. At one point I was the captain of one of their competitions, which meant that I got to travel around the place and see awesome work from students. That was a while back. Today I spent a happy afternoon as a judge going through submissions for the junior competition. They were lovely. Some great work and some splendid explanations. The best bit for me though was knowing how much value taking part in these competitions adds to the contestants. I’m really pleased to see that the competition is still out there doing good. If you want to sign up for next year you can do it here.