OpenWeatherMap is a good source of free weather data

I’m writing something that will let you use a Furby toy as a weather station. For that I need a source of weather information. I found OpenWeatherMap and stopped looking. Their free tier gives me all I need and the service is so easy to use, even from a lowly ESP32. If you want to make your embedded applications weather aware I reckon this is a great place to go.

Mysterium is Great Fun

Mysterium.png

We’re playing a lot of online games at the moment. One of them is Mysterium. It’s a very good implementation of the board game, which is a bit like Cluedo, but with clues. One player, the ghost of the unfortunate murder victim. has the task of picking pictorial clues that match the suspected people, place and weapon. Each of the pictures that the ghost can pick has a set of elements that may, or may not, match the particular scenario assigned to each player. It builds up to a nice reveal at the end, and the artwork and presentation is suitably gothic. Worth spending a few hours with I reckon.

Getting your car serviced in the midst of a pandemic

I’m not sure why I was so keen to have the car serviced and tested. It’s not as if I’m going to be needing it much. Just put it down to my mildly compulsive nature. Anyhoo, we took the car down to the garage this morning. We got there nice and early because there was hardly any rush hour traffic. The dealer was very prepared with one way signs on the floor, Perspex dividers on the counters and plenty of hand gel.

The whole thing passed off very smoothly and I now have a shiny car that should be good for a couple more years. Now I just need somewhere to go and permission to go there.

Begin to Code with JavaScript Recording Fun

I quite enjoy recording the Begin to Code with podcasts. Although I’m far from sure how many people enjoy listening to them. I started the project to see if it was possible to produce useful programming teaching content that could be deployed as a podcast. If you’ve listened, I’d love to hear what you think. If you’ve not had a go, I’d love you to have a listen (the link is on the right hand side) and then let me know what you think.

I’m going to keep doing them whatever happens. But I’d be really interested in some feedback as to how they can be more useful.

Using Multiple Inheritance for Good

Multiple inheritance sounds like a good thing. After all, why would you not want to inherit a bunch of stuff? But some programmers don’t like it. They say it makes things confusing, they say that a class made from multiple parents will be neither one thing nor the other. And mostly I think they are right. However, when the alternative is something even more confusing, I can be persuaded to think of multiple inheritance as a good thing.

My problem was that I wanted to make a driver class to control a Furby toy over Bluetooth BLE from an ESP32. The ESP32 has a bunch of Bluetooth libraries and they work fine, but they expose their callbacks the form of class instances that contain overridden versions of the class callback methods. Ugh.

Wow. That sounded cool didn’t it. But did it make sense? Probably not. Here’s the thing in bullet points:

  • When a program connects to something over Bluetooth BLE it needs a way that the Bluetooth BLE library can tell it things. In other words, if the BLE library receives a message from the Furby it needs to be able to deliver this to the program.

  • One way to do this would be to pass the Bluetooth BLE library a reference to a function for the library to call when the message arrives. I like this method, lots of other things use it. However, the BLE library doesn’t. For some reason it likes to be given a C++ class instance.

  • A class is an object that can contain methods (lumps of program code a name). If I pass the Bluetooth BLE driver a reference to the object the driver can then call the methods in it.

  • The Bluetooth BLE library provides templates in the form of abstract classes (classes with method names but no implementation) which I can override with my own methods in new message passing classes that I base on the abstract parents. I then pass references to instances of these message passing classes into the Bluetooth BLE driver so that it can call the methods in them and tell my program things. But this is a right pain, because if I want these methods to interact with the data in my program (which I do) I have to make these objects aware of their context. Which is a mess.

I hope that’s cleared that up. Anyhoo, rather than implement lots of message passing classes and then pass references around between them (ugh), or make everything static so that everything can see everything (double ugh) I simply make my Furby adapter class inherit from all the abstract BLE library message classes and then drop the overridden methods from these classes right into my driver class. Because the methods are now inside my driver they can use all elements inside the driver and it just works. So, a good use for multiple inheritance. Yay!

Unfortunately, the Bluetooth BLE driver writers have thrown in some function references too, which means that I need some static members in my driver class, but I’m in a happy place at the moment.

One of the things that occurred to me as I was writing the code was how much effort I would have had to put in to avoid using multiple inheritance. When you are programming it is important to remember that the final outcome should be a program that solves the problem. Worrying to much about the “right” way to do that can sometimes send you backwards if you are not careful.

The Living Computers Museum has closed

living computers closing.png

I’d planned a trip to the Living Computers Museum as part of my attendance at the MVP Summit earlier this year. I’ve been there a few times and loved it. But, thanks to a nasty little bug I couldn’t get there. And I’ve just found out that the museum itself has closed. Which is a terrible shame.

In the great scheme of things, and considering all the other awful events of the last few months, the loss of a computer museum might not be seen as a biggie, but it is a fantastic place that keeps history properly alive. If we don’t watch out, we’ll be surrounded by technology but no idea of where it came from. The museum does a great job of telling this story and I hope that something can be done to keep it going.

New Begin to Code with JavaScript podcast available

This is a demo game from chapter 4. How strong are your nerves?

This is a demo game from chapter 4. How strong are your nerves?

I’m writing a book at the moment (I love saying that). I’m also reading out each chapter as I write it, and putting the recordings up as podcasts. Today I discovered that I have a listener, hi Mark, who got in touch to ask when the next chapter is coming out.

Well, the answer is today. I’ve just popped a new episode up. You can find all the episodes on Apple podcasts by searching for “Begin to Code with JavaScript”. Alternatively you can use the link on the right, to find my podcast page. I’m also putting the book text up in draft form, along with all the sample programs. You can find them at www.begintocodewithjavascript.com

I’ve just finished the example programs, including a could of silly games. You can find one of them above. Just click the picture to play.

Managing Audio in Windows 10

I’ve been recording sound effects for the new book I’m writing (I love saying that). Today I discovered that just because everything in your signal chain is supposed to be stereo, it is not guaranteed that it actually is. I was recording sounds from my my Kaossilator and it didn’t sound right. Turns out that this was because I was only hearing the left hand channel, but played on both left and right. Much confusion. Turns out that for some reason the audio on that device had become mono. I had to use the old school Control Panel fix it. First I found the sound settings, then I chose my microphone input.

mic1.png

Then I went to the “Advanced” tab and made sure that the default format was stereo. And then it all worked.

mic2.png

Useful Scrap

scrapfolder.png

I may have mentioned this before, but it is still true. When you start a new project, plan on how you are going to throw things away. As I write I generate stuff that is too good to throw away, but not right for where it is. I call this my “scrap”. I’ve now got a fairly structured storage for it, so that I can search for bits I wrote for chapter 2 that didn’t go anywhere, but might be perfect for chapter 4. Rule one is Never Throw Anything Away. Use GitHub to make sure that you don’t lose anything by mistake and find somewhere to put stuff that you’ve written but don’t know what to do with.

I see the first part of writing as a bit like mining. You come up with all this raw material that you then need to refine into something useful. A scrapheap to me is part of that process. So, if you start making something, build in a way of dealing with your scrap.

Big programs in an ESP32

ESP32 Big App.png

As part of the Furby connect development my plan was to be able to control the Furby from the internet using MQTT. This means that the ESP32 device I’m using will need both Bluetooth and WiFi. WiFi to talk to the MQTT server and Bluetooth to talk to the Furby. Both of these protocols are implemented by large lumps of code in the ESP32 libraries and when I turned them both on I promptly ran out of memory on my device. Wah.

A bit of searching revealed that there should be some menus in the Arduino IDE (see above) that you can use to specify how much of the program storage you want to use. By default a device is set up for Over The Air (OTA) updates, which means that only half of the available memory is available. Turn off OTA and you can install bigger programs. However, when I tried to do this on the devices that I was using there was no such menu. Double Wah.

It turns out that some of my devices (the DOIT and the FireBeetle) contain a version of the ESP32 chip (the ESP-VROOM-S2) that has built-in EEPROM program storage (which makes the device simpler and cheaper) but it also limits the maximum program size so the size cannot be extended. But on larger devices you can extend the application. This means that from a software point of view I can have a device that talks both WiFi and Bluetooth at the same time. However, since both technologies use the same frequency band (and on the ESP32 the same radio) it might not work. My fallback solution is to just use two ESP32 devices, one for WiFi and one for BLE. I can link them with a serial connection and then all my problems should go away.

It’s important to remember that throwing hardware at a tricky problem is not such a daft idea. In this case it eases the development and completely removes a whole set of possible failure areas. At the cost of around another fiver or so in hardware.

Controlling a Furby Connect using an ESP32

Remote Controlled Furby.png

I’ve got very fond memories of the original Furby toy. I used to have one that I used to illustrate talks about computing. I’m not sure how many of those present actually went on to become computer scientists, but I’m pretty sure that quite a few of them went out and bought Furby toys as a result.

A while back I saw an awesome presentation at emf about Furby hacking I got myself one and it turns out that you can control a Furby Connect toy using an ESP32 over Bluetooth. There’s a fantastic GitHub repository all about the command structure and I’ve now got some BLE code working on an ESP32 that I’m using to tell the Furby what to do. I can also read back sensor state values too. It’s great fun. It turned the antenna red in the above picture, so it definitely works. I’ll put it on GitHub when it definitely definitely works.

It turns out that my Furby is an excellent companion. He has a huge repertoire of fart sounds which can be easily triggered by pulling on his tail. There’s also a neat little app you can get for your phone or tablet that integrates very well with the toy and would be great fun for me if I was eight years old. Or even now actually.

The Imagine Cup is Still Awesome

I’ve been watching some sessions from Microsoft Build. In a way, the current virus crisis is a good thing, because it has made it possible for anyone to take part in the proceedings, rather than only the lucky few who could get to the campus. One thing I watched was the Imagine Cup World Final. It had all of the Imagine Cup stuff I remember. Bright students speaking fluently about what they had done, neat ideas over a range of areas and judges asking proper questions. It really took me back to my days with the competition. They were great times.

Every year I used to tell everyone that there has never been a better time to take part in the Imagine Cup. This is still true today. Perhaps even more so. There are so many powerful technologies, so many pressing problems and so many ways to deploy your ideas to make the world a better place. I’ve seen the competition change lives. This week I saw it change a few more. Why should it not change yours?

Scythe Board Game

scythe.png

There are lots of things in this world that I wish I was clever enough to do. One of them might be “Play Scythe”. It is a board game all about world (or at least board) domination. You can fight battles, make pacts, build stuff and deploy fighting machines. We watched a half hour video about it which was notable for the way that the presenter failed to take a single breath during the whole presentation. And that seemed to cover board setup and the first moves.

It was fun to play, even though we spent a lot of time wondering what the various buttons did. We were playing the online version which is very well realised. The network play was quite easy to get going and worked reliably right up to the end of the game, when for some reason we were unceremoniously dumped and the AI took over for our final two turns. Perhaps the game had lost patience with us. One thing that Scythe brings home in spades is the cost of doing battle, and the even greater cost of standing up to an incoming aggressor. We won one battle, but in doing so used up all our fighting powers, leaving us as easy pickings at what turned out to be a crucial point in the game.

We’ll be having another go, and probably watching a few more breathless videos to get more of a feel for the game.

M5Stack RoverC with mecanum wheels

Mecanum wheels are deeply strange. Each wheel contains rollers canted at 45 degrees so that when you drive them they apply a force at an angle to a normal wheel. In other words, if you drive something forward with a “normal” wheel you will get a force that pulls you forward. Drive something forward with a mecanum wheel and you get a force that will push you at an angle. By balancing the forces generated by each of four wheels you can drive forwards, backwards, sideways, around on the spot or at any other odd angle.

M5stack make a tiny robot with these wheels and it is great fun. I want to put one of their cameras onto it, so that I can get a robot that can see things and steer round them.

Sunday Quiz Questions

We’ve started having a silly Sunday quiz every week. On Sunday. These are my questions for this week. Which of these is not:

  1. A Teletubby: Dispy, Tipsy, Laa-Laa, Tinky Winky

  2. A Knitting instruction: knit, purl, waft, right twist

  3. A unit of distance: furlong, light year, hectare, angstrom

  4. A baking term: dust, drizzle, glaze, unfold

  5. A Ben and Jerry’s Ice cream flavour: Moo-phoria, Chubby Hubby, Raspberry rampage, Netflix and Chill’d

  6. A blend of coffee: Jamaican Blue Mountain, Equal Exchange Women Farmer Roast, Taylor’s of York Java Blend, Percol Black and Beyond Espresso

Answers eventually.

Amazing AI Enabled Camera

m5stackv.png

This is an amazing device. A while back I had some fun with a very impressive AI enabled camera which is very neat, and around 60 quid. I’ve just got one another AI enabled camera which is a mere 17 dollars. You can program in in Python straight from your PC over a USB port. It exposes a GPIO port that you can use to send commands to another device.

good grief.png

The SDK is a free download and M5stack (who make the device) even seem to have some help for you creating your models and training them. And it has holes in the back that let you fit the camera on Lego models. This is completely awesome.