Grappling with KiCad

This is the view from the underneath of the board

One of my new year resolutions this year (apart for the one to by a 4K monitor - ho ho) was to make my own printed circuit board and have it made. The Bluetooth chord keyboard seems to be an ideal device for this. The number of connections is limited. I’m using the wonderful PICO LiPo shim (of which more later) for the power management so I just have to wire up the switches and the display.

I’ve played with KiCad before but I don’t make enough circuit boards to have built up much experience with it. Every time I use it I get tangled up in library management and fretting about schematic designs and footprint files. Today was no exception. I found a PICO-W design schematic on GitHub and tried to add it to my project. This did not go well. The model seemed to be missing important files (or at least I couldn’t find them). All the instructions seemed to imply that what you want to do is add your components to a library on your machine so you can easily add them to projects. I much prefer to make all my projects free-standing so I’ve put all my files in with the designs.

It got a lot easier once I worked out that libraries in KiCad are just folders that contain stuff, and when you browser a library you are just traversing that folder. If you put the files in the right place they just get picked up and all is well. You assign a footprint file to the schematic component and this is picked up by the PCB. Above I’ve used the “push button switch” component in the schematic. I then assign this component to the key socket that I’m going to be using on the board.

Above you can see the PCB view of part of the circuit. If I was using a different component I’d change the footprint file. The schematic and the footprint editor are used together. You can update the design in one from the other. You start by drawing the schematic and then you import that circuit into the footprint editor and start laying things out. After a while it becomes quite fun.

PICO Examples vs OneDrive - Fight!

Size comparison with an SD card. Remember them?

I’m doing some work on the Raspberry Pi PICO. To make things easier I bought a debug probe. It’s tiny. It comes with all the cables that you need for your PICO, but you do need to solder three pins onto your PICO device to connect it up. That is, unless you get the much sought-after “H” versions of the PICO which come with pre-soldered pins and a tiny socket that connects directly using the cable provided with the kit.

It works a treat. Rob’s pro-tip: read the instructions very carefully and do all the steps, otherwise getting it working takes twice as long.

I installed the PICO SDK using a script you can find here. The script works fine, but by default it installs the examples into one of your document folders (or at least it did for me). I use OneDrive for file synchronisation and the next thing that happend (at least on my machine) is that OneDrive went nuts and started uploading thousands of tiny files into the cloud. I don’t remember seeing an option to install the examples somewhere else when I ran the script, but if you do the install I’d strongly recommend you look for it and put the examples somewhere in a folder which is not being synced with the cloud.

20Q - a harbinger of ChatGPT

In 2005 I bought a little toy called 20Q. It’s seems to be able to work out what you are thinking off. It asks 20 questions and then makes a guess. If it gets it wrong it asks 5 more and then tries again. Today we managed to beat it by thinking of “coffee table”. It thought we meant “whiteboard”. So it’s not perfect. But it is darned impressive. And around 20 years ago it was even more so. Of course its not clever. It uses a neural net that was derived from users who logged onto a website to play the game. The developers managed to cram enough of the questions and answers they had harvested from the site into the device to make it work.

I don’t recall it being that much of a sensation when it came out, but it is very interesting to compare it with ChatGPT. Both devices take in lots of information and then respond to queries about it. Both give you the impression that they know what is going on, when really they don’t.

You can’t buy 20Q devices any more, but you can play online and there is also a mobile application. I got out our original device which still works really well and really impressed a certain six year old of our acquaintance.

Final Draft of the book has arrived!

Well, this is exciting. The final draft of Begin to Code: Building Apps and Games in the Cloud has arrived. I’ve got a couple of days to go through it before the book goes to print on Tuesday next week. It’s taken pretty much a year to do. 545 pages plus another 35 or so in the online glossary. Over 50 code samples, 25 sample applications and 67 videos. Phew….

Connected Little Boxes remote control

If you want to change the colour of the “Rob” light in my room you can scan the QR code above and then use the menu that appears to pick a colour. You can also follow this link or click the image.

The site that I’ve built lets you create collections of commands to send to Connected Little Box devices. It also lets you download the firmware into an ESP8266 or ESP32 powered device and then attach it to the Connected Little Boxes network.

I’m going to be making a bunch of videos and releasing all the code for you to play with. It’s going to be fun.

Writing code with Chat-GPT

I’m still playing with ChatGPT. It’s turning out be quite useful. Today I asked it this question:

A command group contains a name and a url value. A command group also contains a number of commands. Each command contains a name, description and url value. A command also contains a number of messages which contain a device identifier, message string, name and description. The data objects are stored in a Mongodb database. I want to edit all these items using a web page generated using Express and using Mongoose to interact with the database elements. What routes and express page templates would I need?

ChatGPT came back with a useful description of what I needed to and I was able to ask more detailed questions about specific elements of the code that it suggested. I was then able to ask for sample code for the Express pages and the route handling code. This was all very impressive. It didn’t save me a lot of work because I’ve already implemented the system as described, but it was interesting to see that it produced a design and some code that was pretty close to what I’d written.

If you need some code writing you might like to try creating a description of what it needs to do and then dropping it into ChatGPT. At the very worst at least you’ll have a good description of your problem, at best you might get something useful back.

Laser Rangefinders are cool

A while back I ordered an awesome little laser rangefinder. It arrived last week and I’ve found an excellent holder for it which I can use on my 3D printed camera. I printed the holder this morning and above you can see my fully tricked out camera. It has a viewfinder, level and now a range finder. It might only be able to take one picture at a time, but it certainly looks the part.

The power of the backend....

I spent a big chunk of today trying to work out why my software was putting two entries into the database whenever a device connected to the system. I’m adding logging so that I can detect if a device is resetting more than it should. After commenting out lumps of code and generally getting very confused I eventually worked out that as well as the test code running on my PC there was of course also a version of my system running in the cloud. So it was responding to device messages and writing to the database alongside the code running on my machine. I think I need separate development and test databases……

Pixel pinning

Last week I made it very easy to load Connected Little Boxes firmware into a device. Today I spent some time making it easy to configure the device too.

The form on the left shows how you configure the connection to the neopixels. The values have been pulled from the device over a serial connection. The user can edit them and then save them back into the device and test it.

I’m going to make a bunch of videos explaining how this all works and then deploy the server for anyone to have a go. Should be fun.

Getting environment variables into code in your web page

This is one of my “I’m putting something into the blog so that I can find it in a couple of years when I need to do this again” posts. I’m doing some work on the Connected Little Boxes website and I've been deploying the latest version. This one automatically configures a device by downloading setting information from the cloud. Code running inside the browser gets the settings from the server and then sends them into the device. To make this work the code in the browser needs to know the url of the server based data source. When I’m developing the program this will be on the localhost (my pc) and when the code is deployed the data source is the server in the cloud.

I’ve put this information in an environment variable. I have a local .env file that holds the local address. I’ve then put the deployed host address in the environment variable in the cloud. This works a treat, but I do have one problem. How do I get the value of this environment variable into the JavaScript code running in the browser? I’m using an Express web page to hold the web page source and I can embed JavaScript into the HTML but I don’t seem to be able to embed JavaScript elements into the <script> parts of the page. Probably because doing this kind if thing might disrupt the space-time continuum. So, I’ve done this… Below you can see the statement that renders the createDevice.ejs page. I pass this statement the HOST_ADDRESS environment variable that I want to feed into the JavaScript code in the createDevice.ejs page:

res.render("createDevice.ejs", { name: res.user.name, host: process.env.HOST_ADDRESS });

When the page is loaded the name and host variables are loaded with values supplied to the render method. Now, I pick those up inside the HTML and pass them into the page initialise function:

<body onload= "doStart('<%= host %>');" >

The HTML above specifies that a function called dostart will be called, and supplied with the value of host as a parameter. This is the environment variable that I want to use as the base url for my server requests.

function doStart(host) {
    console.log("starting");
    hostAddress = host;
    settingsURL = hostAddress + "createDevice/networkSettings.json"

    selectStage(stages.ConnectUSB);
  }

Above is the doStart function. It sets hostAddress with the base url for all requests and then uses this value to build the settingsURL that is used to fetch settings information from the host. It works a treat. When I run the application on my local PC the url is set to the local host and when it runs in the cloud the address is set to the cloud location. There is probably a much easier way of doing this which I don’t know about, but I’m still quite pleased with making this work myself.

In praise of older video games: Left 4 Dead 2

This has been a weird week. What with having a visitor who, thanks to the “Magic of Covid” I’m not allowed to be in the same room as. Anyhoo, one way we have found to get around this is to play video games. The game “Left 4 Dead” was suggested as a way we could get together and play games without mixing too much, and so it has turned out. The game came out in 2009 and so it runs handily on most everything, including the Steamdeck and my rather elderly PC.

We’ve been having a great time running round shooting zombies and working our way through the levels. We’re playing in a team of 4 with two computer powered players and it works a treat. Your teammates are helpful and not at all silly. The dialogue is nicely done and the environments are large and challenging. There is lot of fun to be had in older games and you can pick this up for around 8 pounds on Steam. Well worth it for zombie slaying fun.