variometer using e-ink + stepper + encoder + UART; interrupts or threading?

Im working on a variometer for a glider

It has a mechanical needle driven by a x168 stepper, and AX1201728SG microstepping controller. It has a eink display, a turn/click encoder and will communicate with the flight computer (which contains the pressure sensors) over a serial port. The microcontroller will be ESP32 based.

I have most of the individual components working, but bringing it all together is a challenge, mostly because the display uses a blocking library, and a display update takes almost 500ms, which will cause the stepper to stall , I will miss encoder clicks and I may even run in to trouble with the serial port.

Im considering 2 approaches;

  • interrupts
  • threading (esp32 has two cores).

Interrupts sounds like the easiest solution. Using hardware interrupts on the encoder pins, and a timer interrupt to drive the stepper. But how do I make sure Im not waiting 500ms before reading the serial port? Also a timer interrupt?

Since the ESP32 has dual cores, it kinda makes sense to use them. If I dedicate one core to the display, I shouldnt have any issues running the rest on the second core. Ive googled and found some examples and managed to create a test where one thread checked the encoder pinned on one core, while the display was being driven by the main loop on other core. That worked, but passing variables between the threads is something I do not understand and may be out of league. I should have mentioned: Im a newbie!


Did you ever get this working? I like the idea for ultralights but dont need it to display mechanical and could use a stand alone sensor to get the data. Very interested in this.