Using the ESP8266 Real Time Clock memory to manage device reboots

newclb.png

The ESP8266 device has a built in Real Time Clock (RTC) that can work as, well, a real time clock. This is very useful if you want to put the processor to sleep for a while in low power mode and have it wake up later. The RTC also contains a small amount of memory which is maintained in low power mode. You would put values into this that you wanted to remember when the device wakes up again.

You can also use RTC memory to store values that will be retained when the device is rebooted. After a reboot you can’t make any assumptions about values that might or might not be in memory, but you can assume that the RTC memory values are intact.

I’m using this ability to allow an ESP8266 to reboot in different “modes”. The problem that I am solving is that there is not enough memory in an ESP8266 to allow it to run the Connected Little Boxes software and a web server at the same time. My program sets the type of device it needs into RTC memory and then resets the device. When it starts running it reads the value back and then starts in the requested mode.

int getInternalBootCode()
{
    uint32_t result;
    ESP.rtcUserMemoryRead(0, &result, 1);
    return (int)result;
}

void setInternalBootCode(int value)
{
    uint32_t storeValue = value;
    ESP.rtcUserMemoryWrite(0, &storeValue, 1);
}

The getInternalBootCode function returns the contents of the value at the start of the RTC user memory. the setInternalBootCode function sets it. The functions use the ESP.rtcUserMemoryRead and ESP.rtcUserMemoryWrite functions which transfer a block of data between the program and the RTC memory. The first parameter is the offset into the RTC memory (I’m using 0 to indicate the start of the memory). The second parameter is a pointer to a 32 bit data value. The third parameter is the number of 32 bit values to transfer. I only want the one value for my boot code. Now I can store it and fetch it back.

Non-Fun Gibbon Tokens are now a thing!

NFT.jpg

Non-Fun gibbon Tokens now a thing.

They are a horrible pun (on non-fungible tokens) made 3D real.

Thanks to the efforts of Geoff and Derek who supplied the line art plus the InkScape and OpenSCAD tools you can now have the ultimate in slightly unique art.

Prints a treat. They are quite big in the STL files, but shrink then down to 30% size in Cura and you get something which is printable and retains detail - but check with the preview mode first to make sure that none of the lines in the design have been missed.

If you like them (and why wouldn’t you) lob a donation my way for Comic Relief here.

Quack House at Three Thing Game

quack house.png

At 3:00pm this afternoon we shipped “Quack House”. It kind of works. You can even have a go yourself here. It supports loads of players (we were surprised to find) and the goal is to attract ducklings and steer them to your badly drawn duck house. There are some gameplay issues. The ducklings are attracted to ducks and will follow you although they are very determined followers and an unwary duck can end up pinned to the side of the game environment by ducklings.

We are all quite proud of it. I did the graphics, the sound and the music in a style that I am calling “placeholder”. David and David (which made for confusing team conversations) did most of the code, but I did just enough to be able to convince myself that I contributed something.

The other teams had produced some really splendid stuff. One of the things that struck me was that they were all focused on making a game with a beginning, middle and end rather than just a tech demo. There was a nice mix of technologies and some of the teams had dedicated artists for sound and graphics which added a huge amount to the quality of the finished products. The games will all be placed on itch.io once the teams have finished tidying them up. I’ll post the links here when they are available.

As usual, I learned a ton from the experience. Not least that phaser is a splendid framework and that creating server based games is nothing like the challenge you might think it is. And also that the flame of Three Thing Game is alive and well and still burning brightly. Thanks to David for inviting me and letting me see what the students are up to these days.

Overhead Duck Pictures for Three Thing Game

OverheadDuck.png

Nothing like starting the day with some duck photography. I’m using the same duck as appears on the cover of the “C# Yellow Book”. We’re using the Phaser game framework and the socket.io framework for the communications to create a multi-player browser game where you control a duck seeking to attract ducklings back to your duck house. It’s going OK so far.

Return to Three Thing Game

thingbay.png

I’ve got very fond memories of Three Thing Game. It’s a game development event run by the University of Hull. Entrants get three things and then write a game that incorporates them. I was invited by the estimable Dr. Parker to take part this weekend as part of the “Spooky Elephant Collective” team.

We were all gathered together (in an on-line kind of way) for the Thing Auction. We had a menu of things to bid for and some “Bank of Thingland” virtual cash to spend. We ended up with “building, duckling and resurrection”.

Its going to be a fun weekend.

What a difference a bracket makes

if (tolower(name[i] != com->name[i]))
    return false;

Sometimes it seems to me that programming is a long, slow process of proving to myself how stupid I am. Take the statement above as an example. It is from the console process in my Connected Little Boxes project.

The code is comparing a character in a name typed in with a character in a command name. The command name is always in lower case, but I wanted to convert the incoming character to lower case before the comparison so that my device would ignore the case of incoming commands. In other words, I wanted “print” and “PRINT” to be recognised as the same command.

The code above was supposed to stop matching characters as soon is the incoming name and the command name don’t match. That bit works fine. But it doesn’t recognise that “print” and “PRINT” are the same.

This is because the brackets are in the wrong place. The tolower function (which converts a character code to a lower case value) is being applied to the result of the comparison, not to the character in name[i]. A language like C++ will let you get away with this. C# would have told me that it is silly to try and use a number (the result returned by tolower) in a test. The fix is a simple one, put the brackets in the right place:

if (tolower(name[i]) != com->name[i])
    return false;

Now the character in name[i] is converted to lower case and then compared with the stored name.

Bitcoin boilers

Bitcoin mining, where powerful computers solve mathematical puzzles to generate money that is almost probably real, is consuming an increasing amount of power around the world. As all the power that goes into the computer comes out as heat, it seems to me that it would be sensible to make good use of this power.

Why not make “bitcoin boilers” that use heat from the computers to do something useful? That way you could get paid for having a hot shower. I’m not sure about all the detail - I’m strictly an ideas man here - but I think it is worth a try.

Raspberry Pi Wide Angle Zoom Lens

lens.png

Pimoroni now stock a new lens for the Raspberry Pi HD camera. This one is a zoom wide angle lens. I’ve been impressed with the quality of the longer focus lens that I got a while back, so I thought I’d invest in the new one too. The price is very reasonable at 15 pounds.

The quality is very good. Focussing is fun. It is not a “pure zoom” in that if you change the zoom settings to move closer or further away from the subject you will have to refocus. And sometimes (at least on mine) I can’t find focus positions for some zoom settings. But the bokeh (the effect you get when things are out of focus) is rather nice in a blurry kind of a way

The artistic view..

The artistic view..

I’m using mine to give an overhead view of my work area for videos. If you want to do this you’ll need to set the camera up so that it gives you a full desktop view. This is the command that I use:

raspistill -t 0 -p 0,0,1920,1080

This makes the viewfinder image from the camera fill my video output, you can change width and height values to match the display values you are using.

The lens will focus very close, which makes it ideal for viewing components and circuits. If you have the Raspberry Pi HD camera unit it is well worth a look.

Decaying Digital Ownership

20210325_113315786_iOS.jpg

I bought a CD last week. It’s one that I already “own” having bought it from the iTunes store a few years ago. Unfortunately, the 10 tracks that I thought I’d paid for turned into 2. This is probably due to licensing changes that should not in any way be my problem. I suppose there are some weaselly terms and conditions somewhere that make this quite OK.

Anyhoo, the CD arrived today. I had to find a CD-ROM drive and then use iTunes to rip the music onto my PC, and thence to Apple music share so that it reappeared on my phone. So, after spending only 9 pounds plus a bit of messing around I’m back where I should have been if Apple had kept the promise that buying something actually means buying something. Modern life eh?

Creampie Canon Fail

Showing bravery in the face of whipped cream….

Showing bravery in the face of whipped cream….

Well, the lecture was a great success. Except for the “Creampie Canon”. Which kind of failed. It was mostly my fault. In the excitement I forgot to attach the trigger so that the firing mechanism didn’t work. In the second attempt the actual mechanism fell to bits.

At this point I was determined not to allow my shoddy workmanship to let me off the hook, pie in the face wise. So I did what I thought was the right thing, which was to fire the canon at myself.

That worked fine. Although I also got whipped cream over the keyboard and a few other devices that are now going to need cleaning. If you want to be part of the event by giving me some money donations are still open. You can donate here:

The Pie Face Canon

canon.png

As part of my Red Nose Day presentation I’m making a remote controlled “pie face canon”. The pie flinging mechanism is a canon from a pie face game that you load up with whipped cream and then fire. I want to people to be able to control it from the internets and maybe even hit me in the face with it. No idea why. Perhaps it is the technical challenge.

And technical challenge it is. The biggest problem is that when the mechanism is cocked the back tension from the spring loaded piston is considerable, so you have to pull quite hard on the trigger to fire it. And Lego Technic is not very good at pulling hard on things. What happens instead is that the mechanism comes apart. Which is fun to watch but ultimately not that useful.

In typical idiot fashion I solved all the easy problems first. I can move the canon up and down and left and right by remote control. But I can’t fire it yet. A proper engineer (which might be me next time - who knows?) would have solved the mission critical part first and then added the gold plating later. At the moment it works sometimes..

Driven mad by pixels

mad maths.png

There’s a scene you see in lots of movies where the camera pans across a selection of crazy drawings and formulae, to imply the emerging madness of some deranged character or other. I feel that I’ve just lived through that. I’ve been trying to make my pixels move over surfaces in my Connected Little Boxes. I don’t want them to “snap” from one pixel to another, I want adjacent pixels to fade up and fade down to give the impression of the light moving. I want it to work in both “1D” (a line of lights) and “2D” (a grid). I’m sure there are off the shelf solutions for this but I want to roll my own. I’ve finally finished it. It was one of those occasions where actually knowing some trigonometry was really useful.