CNC ESPduino
You know how a simple thing leads to an endless number of tasks...
I have a CNC controller board that drives stepper motors for various playfield tasks.
CNC Board / Shield
It sits neatly on top of an Arduino UNO; and is pretty much an industry standard.
Now the Arduino UNO is a 5volt device, and the STM32 used for telling everything what to do, is a 3.3 volt device - they can't talk to each other as they are. There are fine little things that convert these voltages, and if you get the right ones, they are bidirectional - so communications can go both ways. For Anubis, I'd need about 10 extra connections to start, and more as I add the remaining features. Not wanting more devices and connections that can fail over time (or right now if I get them wrong) I hit on the idea of replacing the Arduino with a 3V3 device.
Enter the ESPduino!
This device has the same formfactor as the UNO, but with an ESP32 WROOM-32C.
Pro | Con |
UNO Formfactor (fits the CNC board) | UNO Formfactor (wastes some space) |
3.3 Volts - no converters needed | Lots of ESP I/O inaccessible (no pins) |
Cheap (US 4.59) | |
Reported as "should work" by the Internet |
Seems a no-brainer...
It turn out the designers of the ESP32 used an IO pin that has a very specific boot task as a general purpose I/O. Why they did this is a mystery - there are so many IO pins available. On the CNC board, this pin is attached to a pullup resistor, and controls the default enabling of the stepper control modules. This pullup causes the ESP32 to go into an endless boot loop. It's the only pin on the microcontroller board that does this, and the only pin on the CNC board with a pull up resister - how lucky!
Removing the resister is the way to go, I will enable the CNC modules individually...
I lifted the resistor, so it's easy to put back. It can be easily removed with a quick snip when the testing is done.
Let's talk about Software
The Arduino IDE comes in two flavours - the v1 Series, tapped out at 1.8.19, and the v2 series. The Internet will tell you to use v2. Don't listen, it's all lies.
>>> Start Rant
One of the most important things with microcontroller development, is managing libraries. This gets especially tricky if you are making your own, or using some that are not mainstream. Both V1 and V2 IDEs have super-easy library management. Only V1 gives you decent control and portability. The developers of the V2 branch don't think that being able to move an Arduino project from machine to machine (or archive it and its libraries) is very important. If you are developing for the long term (years) then it is very important. V2 is focused on the home-coder and education market - making everything that you want to do-right-now super easy. It shoves libraries under home directories, rather than in projects. V1 acts that way as well, but can be easily overridden, so everything ends up in one place - so 2 years down the track, when you want to fix a little bug, you don't have to update and test everything because it's all changed - or track down old (lost) libraries. The developers have lost the plot.
<<< End Rant.
Anyway, the support for the ESP series of microcontrollers in the Arduino IDEs uses a huge tool chain (lots and lots of programs and things that happen, in order), and lots of environment variables are used as part of this process. On Windows (boo) there is a limit on how long these things get, and if you have long directory names, these use up that limit very quickly. I have very long directory names and structures, to keep everything in its own place and neat and tidy. When you exceed this environment variable length weird things happen as the tool chains only get part of their instructions. The errors don't match the cause. If you spend long enough, you will discover the reason. The easy fix is to throw away the everything in its own place and neat and tidy, and replace it with short and nasty but working directory structure...
Which I did.
Let's Talk About Pins
No, not pinball machines, the pins on chips.
The pins used in the software for an Arduino UNO, and an ESP32 WROOM are completely different. I hunted down the differences on the Interwebs, then checked them against my board, making a header file to match.
That done, I edited my code, since I now had better names for the definitions of the pins.
Testing
It works. After a surprising amount of effort - I'm back where I started, but with 3.3 Volt logic — Hazar!