Detecting different ESP devices in Arduino Code

This is one of these “Rob writes a blog post about something so that he can find it later when he forgets how to do it” moments. I’m writing some code using the Arduino platform that I’d like to run on both the ESP32 and the ESP8266. They both run C++ and have a lot in common. But some things are just different. For example they have different commands to ask a device for its unique ID is getFuseMac for the ESP32 and getChipId for the ESP8266.

Fortunately we can use the magic of conditional compilation to make our C++ code always do the right thing. The code below shows how it works.

#if defined(ARDUINO_ARCH_ESP32)
#define PROC_ID (unsigned int)ESP.getEfuseMac()
#endif

#if defined(ARDUINO_ARCH_ESP8266)
#define PROC_ID (unsigned int)ESP.getChipId()
#endif

The symbols ARDUINO_ARCH_ESP32 and ARDUINO_ARCHESP8266 are defined if the program is being built for the respective device. The C++ above defines a PROC_ID symbol that can be used in my code to get the right version.

FreeCad Simulator is now on GitHub

FakeFreeCad.png

I’ve made this horrible hack to make it easier to debug my Python macros that run inside FreeCad and design little boxes. It means that I can use all the lovely debugging features of Visual Studio Code to find out why my code don’t work. The hack takes the form of a few simple Python objects that fake part of the FreeCad ones and allows your macros to run in any Python environment you fancy.

If you like the idea of writing Python code that produces physical artefacts you might want to take a look at it. You can find it on GitHub here.

Star Trek: Discovery Season 3 is Awesome

discovery3.png

The first two seasons of Star Trek: Discovery were pretty good. But the third is just brilliant. It seems to be a return to a lot of the original Star Trek tropes. Rather than convoluted and long winded stories leading up to a grand finale that is a bit hard to get your head around we have a bunch of people dropped into a nasty situation and then going about doing the right thing.

Each episode so far has ended with the amount of good in the universe increasing slightly. There’s still time for a grand story arc to shuffle in and take centre stage, but for now I’m really enjoying well told free standing episodes that leave you smiling at the end. I really hope it continues this way.

Heating Fun

This is bad. No matter how well printed the labels are.

This is bad. No matter how well printed the labels are.

Did you know that if you place two Honeywell EvoHome BDR91 remote valve controllers within 300mm of each other they don’t work properly?

Neither did I. Until I woke up in a cold house and had to do some digging. Apparently the radio connections in the two devices interfere with each other. Or so the very helpful tech support person told me. I’ve moved them a nice long way apart and look forwards to continued warm toes.

Use OTADrive to remotely update your ESP devices

I’m making a bunch of devices that I’ve decided to call “clever little boxes”. I’ve taken the important first step and bought the domain name. Now I have to make everything else. I’ve decided that the best place to start is with the deployment. You might think that this is crazy, but actually it is the most important phase of your development. If I’m not able to easily update the devices in the field and manage their deployment I won’t have a product, just a demo. Also, modern product development is a continuous process. You don’t make something and ship it. You make version 1.0 and then create version 2.0 based on the feedback you get.

To help me with this I’ve started using otadrive. Once you have created an account you can store firmware images on the site and then your remote devices can download and install new firmware images from them. You’re given an access key and a web based interface for uploading firmware and managing the devices that need to be kept up to date.

You get a tiny bit of Arduino code you can drop into your device to check for new versions. It works a treat. The only snag in my mind is that the site doesn’t seem to have a business model. At no point in the process of configuring and deploying versions have I been asked for any payment. This worries me for two reasons:

  • I might suddenly be hit with an enormous price list which makes the whole thing unviable.

  • The site might vanish overnight taking with it my entire network of devices.

I’m not that concerned just at the moment though. And if things get tough I can look at this on GitHub which might be where I end up putting everything.

Oculus Quest 2 Headband

headband.png

If you are lucky enough to own and Oculus Quest 2 you will be enjoying the higher quality and lighter weight of the device compared to the first version of this device. However, you might have noticed that the head strap arrangement is a bit more primitive than the earlier version. One way to fix this would be to buy the expensive Elite Strap. Another approach is to print out a support that fits on the back of your head and holds the straps in place. I had a go at printing it and got the above result. I’m quite pleased with how well it came out. I used a very large layer height so that I got the strap quickly, which is why the quality is not the best. I also used “tree” support to hold up the large mid section. That worked really well too.

Use Quick Access to work with recent files

recent files.png

Now and again I fall over something so useful that I regret not having used it before. Such is the Quick Access feature of Windows 10. I found it by mistake and it is really rather nice. It lists the files that you have just been using. You might not think that is very useful, but if you remember that lots of applications, for example all the Office apps and programs like Cura, will open a file if you drag it onto them and drop it. You can also upload files to the wonderful OctoPi printer controller by just dropping them onto the browser page.

So when I want to take my saved design file from FreeCAD into Cura I just have to drag it out of the Recent files folder and drop it onto Cura. This saves a lot traipsing through file open dialogs. Now I keep the recent files folder open on the desktop just for things like these.

Pin numbers are not port numbers

esp8266 pins.png

In a blog post last month I confidently asserted that the output pins on an ESP8266 didn’t have enough “oomph” to drive the neopixels on an Adafruit 8x8 panel. I’m sure you remember the post.

Anyhoo, it turns out that the post (rather presciently titled “Making Mistakes”) was wrong. What I should have written is that if you use the wrong pin on your device it won’t work. Just because a pin is labelled D1 doesn’t mean that it is connected to GPIO1, as the diagram above makes very clear.

So now I can use an ESP8266 to drive my panel, which is nice.

Version control and the end of time

boom.png

The Timelords met, as Timelords do, from time to time for a coffee. And when they met they liked to talk about the old times and universes that have come and gone. “Ah, the earth universe” said one. “Indeed” said another. “I thought it had promise” said a third.

“The humans had discovered software and version control, and all was going reasonably well. And then one human decided to try to find out what happens if you put the name of the gitignore file into the gitignore file. And then their reality collapsed on itself. ”

The first timelord stared into his coffee cup. “If only they had known the true power of Git” he said glumly.

Consistency is key

height adjustment.png

I was quite proud of the height adjuster I made for Una my Ultimaker 3d printer. Although I wasn’t very proud of the way that I’d handled a lack of bolts of the correct length. Anyhoo, it seemed to work and allowed me to adjust the print head height just by turning the screw at the top. There was only one problem with it.

It didn’t work.

I could use it to move the switch up and down but it also moved the switch all by itself. There was too much play in the mechanism. I’d adjust the height carefully and then find that next time I homed the printer the height was all wrong again. Wah.

One of my favourite quotes is from Ralf Waldo Emerson and goes “A foolish consistency is the hobgoblin of little minds”. This is worth remembering when you are trying to make all the wires in your circuit the same length, or arrange your DVDs in alphabetic order and fretting about how the word “the” works in the movie title. However, when we are talking about things that only work if they are within a tenth of a mm of the correct position, I’m a big fan of consistency.

So it has been out with the fancy adjuster and back to the sturdy little bolts that fix the switch in one position. I’ve not got a bit more of a job to adjust the height of the print bed, but at least the adjustment will stick for a while.

The man who labels chutney

chutneylabels.png

It doesn’t happen very often, but every now and then I find myself in the perfect position with just the technology that I need at my fingertips. It happened today. A while back number one wife came into possession of a large number of green tomatoes. Which screamed “chutney” to her and had the pleasing outcome of a number of differently shaped jars being filled with fabulous smelling stuff.

Today she asked me if I had any blank labels that she use for the jars. She was going to fill in each one by hand. “I can do better than that” I said and vanished upstairs for half an hour. A long while back I bought a label printer to liven up the entrant packs for Three Thing Game. So I happened to have a label printer and just enough labels to make the above. I’m rather pleased with the result.

Wide eyed and pinless

esp32 vroom.png

The ESP32 is mostly my weapon of choice when making embedded devices. The only problem that I’ve had with the device is that tends to be supplied as a device with ready soldered pins. This is fine if you want to plug it straight into a socket but I don’t tend to do that. I’m much happier soldering the wires directly onto the unit. This makes for a more reliable device and also allows me to use smaller boxes. T

The good news is that I’ve now found a supplier on AliExpress who is selling versions that don’t have the pins already fitted. They cost slightly more than the “normal” devices (which I find a bit surprising) but they do give a lot more flexibility.

One thing to remember though; it is a pain to build the ESP32 device into your device and then find that you have a faulty one. So make sure you test the ESP32 before you solder it in.

The power of the chamfer

freecad bevel.png

One of the problems that you can have when 3D printing is called the “elephant’s foot” problem. It is caused because the very first layer is usually printed very slowly and is very thick, causing it to spread out slightly. This leads to the side of the object having a profile that looks a bit like an elephants foot. Which I suppose explains the name…

I’ve found that one way to fix (or perhaps hide) this effect is to apply a “chamfer” to the printing face. This makes the first print layer slightly smaller and hides the foot effect. The chamfer is easy to perform in FreeCAD. You select the Part view in the Workbench and then select the chamfer option (it’s blue and looks like a chamfer (a corner with the edge flattened off). You can then select the face that of the object that you want to chamfer and you can get the rounded appearance you can see on the left hand shape in the design above. One day I’ll figure out how to do this from Python inside FreeCAD and then add it to the part design program.

chamfer.png

Then I print using a “brim” which is a bit of print around the outline of the object which helps it stick to the print bed. When the print has cooled I cut the brim off with some sharp scissors and this makes the edges look quite neat as you can see above.

Maketober Day 31: Christmas Cake to finish

cake.png

This is not actually something that I’m making. But I do get called in to give it a stir.

I’ve really enjoyed Maketober. Thanks to the folks at the Makerspace Hull for giving me the idea. It’s been very useful to have a focus on making (or at least achieving) something every day. I plan to keep on trying to deliver something useful each day and then write about it here. And I can’t wait until I’m able to go and show them what I’ve been making. And I might take along some cake too..

Makertober Day 29: Wiring up

wiredup.png

This is the completed light box, all wired up. I’ve printed a tiny little mounting plate that holds the ESP8266 device and allows it to be fitted onto the mounting pillars. I’m doing the wiring by soldering directly between the devices.

broken ring.png

I like using solid-core wire tor connections as it is easier to work with. But you have to be careful as it puts more strain on whatever it is connected to. Above you can see what happens when things go wrong. The solder pad for DI (data in) on the pixel ring has detached from the PCB and turned this ring into scrap. Fortunately I have a few spares.

fittingscrews.png

I’m fixing things together using tiny self-tapping screws. These can be hard to get hold of. I found this rather nice kit on Amazon for a reasonable price. The screws as supposed to be used when repairing laptops, but they work into 3D printed parts rather well. After a while I suppose I’ll use up all the screws of one particular size, but at least I’ll know which size to buy next time.

Makertober Day 28: Printing Boxes

Some people say that you shouldn’t use your 3D printer to make boxes for things. I disagree. Sure, a box is quite large and takes ages to print. But its not as if you have to spend that time yourself. Once you’ve set the printer off you can leave it to get on with it. Although I do still find the process fascinating to watch. Above you can see the output of my design which I think is fairly tidy. I could spend some time fiddling with settings to get the print better, but this is not actually something that the user will see.

shinyside.png

The reverse side, which is where the print was built up on my glass bed, is nicely shiny.

Makertober Day 27: Levelling your print bed

Yesterday I sorted out the printing temperature of my 3D printer. Today I’m going to spend some time on the other important aspect of 3d printer configuration: print height.

Una, my Ultimaker 3D printer is a “Fused Filament Fabrication” device. This is a posh way of saying that she “prints by squirting plastic onto a plate”. The distance the print nozzle from the plate is absolutely crucial. If the distance is too small you will get nothing because the plastic can’t get out of the nozzle. If the distance is too large you will get a ball of “plastic wool” because the plastic doesn’t stick to the plate and allow layers to build up. It’s also very important that the print head is the same height all over the bed, otherwise the plastic will stick in some places but not others.

bedlevelling.png

On Una you adjust the print height by moving the height limit switch up and down and then twiddling three screws to set the level of each corner of the bed. This is made much, much easier by a plugin I’ve found for the OctoPrint system that I use to send print jobs to the printer. You give this a bunch of locations and it moves the print head to each one in turn and lowers it down to the printing position. You can then adjust the height there and move on to the next one. Once you’ve been around the print area a few times you have got your print bed level. For my printer the correct height is when I can slide a sheet of paper underneath the print head and it just (and I mean just) catches the print head. I need to do this when the print head is at printing temperature.

I used to check the print height at positions all over the bed using a little height gauge but I’ve given up on that. My starting assumption is now that the bed is flat so that once the three points where it is supported are the right height the print height will be correct. If the print bed is not flat there’s not a lot I can do about it other than buy a new one anyway….