PWM Handling in Alternate VM: ESP32

Issue #35 resolved
Turgut Guneysu created an issue

Hi John,

Continuing testing with alternate VMs: ESP32.
I was finally able to get FW loaded and connected to microBlocks. There are a few error messages during the connection process, but I want to document those in another issue.

This one is specifically about ability to control PWM pins in ESP32:

I am using a LOLIN32 v1.0.0 ESP-WROOM-32 by WEMOS.

I can control PWM pins 0, 1, and 2 when I test it with micro:bit. Gradual changes in a loop with “set pin <N> to <value>” produce corresponding visible results.

However, with ESP 32, I can only use the “set digital pin <N> true/false” on any pin I want with correct results.
But “set pin N to <value>” does not produce any changes. I first thought that maybe the pins were limited to numbers 0-2 per micro:bit. But that is not the case. None of the pins I tried on the ESP32 respond to PWM changes.

I was not able to explore the VM CODE in a meaningful way due to my lack of knowledge on the environment. Any pointers to further the testing will be appreciated.

Comments (5)

  1. John Maloney repo owner

    Thanks for the careful testing.

    I know about this. It turns out to be a long-standing issue in the ESP 32 Arduino libraries (which we are using):

    https://github.com/espressif/arduino-esp32/issues/4

    The hardware does support up to 12 PWM channels that can be used on any pin that can do digital output (i.e not pins 34-39) according to:

    https://randomnerdtutorials.com/esp32-pinout-reference-gpios/

    I had hoped the ESP32 Arduino library maintainers would have added support by now, but they haven’t so MicroBlocks should probably implement their own PWM on ESP32 boards. However, I’m guessing it’s not totally trivial or it would have been added to the ESP32 Arduino library already..

    Meanwhile, we should document this as a known issue on ESP32 boards.

    We could also implement PWM as a MicroBlocks library, as we do with servo support.

  2. Log in to comment