ESP32 Programming with Arduino IDE

ExpressIF implemented FreeRTOS with their Arduino IDE library, so by using this we get a lot for free. By default we run Wifi etc on core 0, while the classic Arduino loop() run’s on core 1. In my case I want to use core 1 for bit banging and that is straight forward to program in loop(). By using an ever loop I bit-bang with < 50yS accuracy which is very good.

The more tricky part is the communication tasks that we have to add to core 0. Firstly we need to deal with the Task Watchdog. Since core 0 is used for system tasks it also monitor it’s tasks and trigger the watchdog if any of them run forever, so we need to (1) create a loop, and (2) call delay within that loop.

The console print below show a loop w/counters in loop being monitored by a task in core 0.

Ca 526191 iteration a second and stats show that we max have 10uS delta with an average of 1.9uS between iterations. This is our bit-bang accuracy. These 10uS will probably be 50uS as we add content, but that is still 50-100Khz accuracy or 0.05 – 0.01ms if you like.

My alternative would be to attempt a 10,000 timer per sec timer interrupt that would give 0.1 ms accuracy and use ca 10% CPU load. I have not tried this on ESP32, but this technique have its advantage that you can use 80-90% of Core2 for something else.

Leave a Reply