Moving code from ESP8266 to ESP32

A while ago I made a mashup of Dan Royer's code CNC 2 Axis Demo with my own code for trapezoidal motion stepper and servo control for ESP8266.

I assumed porting the code to the ESP32 would be trivial, and that was true for the most part: changes like library name being Wifi.h instead of Wifi8266.h were not a problem. UDP now does not like multicharacter writes but you can use print instead. So far so good.

However, when it came to the interrupt code I was stuck with the stepper interrupt causing an exception sometimes. And to make things weirder, the servo interrupt worked flawlessly (both of them had the IRAM_ATTR directive if you ask me).

Going little by little, I could narrow down the culprit to a floating point operation during the interrupt, that would cause problems sometimes but not always. Browsing around I found this post. Where the solution was simple: do not use floats within the interrupt routines but doubles. The reason was the float calculation would be performed by…

ESP-32 in UNO format

A few years ago, the IC manufacturer Expressif surprised many of us with their ESP8266 SoC.  A 32- bit processor, running at 80 or 160 MHz with built-in wifi support. It proved to be a very interesting proposal and, eventually, a versión with the same form-factor as the Arduino UNO was made available (which opened compatibility with many available shields).

The same manufacturer developed the next versión, a new and improved SoC this time with Bluetooth and Wifi support, more I/O pins and low-power modes.

I almost forgot, the main reason these chips got successful in the DIY world was that the price was right and a powerful SDK was made available, that eventually led to a group of enthusiasts to create an Arduino-compatible library that made possible to use Arduino code and Arduino IDE to develop with these chips.

A few weeks ago I was contacted to see if a wifi-enabled stepper motor controller board could be done with an ESP. As that is something I had already done the obvious answer was yes. But as they added more features, like SD-support and some extra I/O the limited capability of the ESP8266 was exhausted.

But that request made me look around for what I did not know might be available: Another Arduino-UNO form-factor board but, this time, based on the ESP-32 SoC. Of course, other people had thought about it and there were several boards available in that format. I ordered one UC-406 board, that included a micro SD socket.

On the software side, I followed these instructions to get the Arduino IDE working with the ESP-32 in Linux. Please have a look at the code examples as some things are slightly different here and analogWrite won't work as we are used to.  The built-led is pin 2 (not 13 as in UNO) and the built-in SD card circuit works with the included SD code examples.

I am already loving this platform and I just hope it will keep on getting cheaper. Definitely, a very interesting board that can charge a lithium battery and run from one too.


Popular posts from this blog

VFD control with Arduino using RS485 link

4xiDraw: Another pen plotter

Software I2C for Arduino