Can MicroBlocks support ESP-PICO-D4?

Issue #321 resolved
梁帅 created an issue

Hi John,

I found that the ESP32 firmware of MicroBlocks can program the ESP-PICO-D4 chip, but there are some problems.

For example, GPIO9 and GPIO10 are connected to the internal SPI FLASH in ESP32-WROOM-32 and are not recommended to be used as GPIO pins. However, it can be used normally in ESP-PICO-D4. In addition, ESP32-PICO-D4 also has I38 pin.

I found that the ESP32 firmware of MicroBlocks cannot control the above three pins. Unfortunately, my mobile robot just uses these three pins. Will MicroBlocks optimize the ESP32 firmware and add support for ESP-PICO-D4?

ESP-PICO-D4 Datasheet:

https://www.espressif.com.cn/sites/default/files/documentation/esp32-pico-d4_datasheet_en.pdf

ESP-WROOM-32 Datasheet:

https://www.espressif.com.cn/sites/default/files/documentation/esp32-wroom-32e_esp32-wroom-32ue_datasheet_en.pdf

Comments (13)

  1. John Maloney repo owner

    MicroBlocks includes firmware for about 16 supported boards that are widely used by educators and Makers. However, firmware for many more boards (over 40) can be installed using PlatformIO.

    If you are willing to build and install the firmware yourself, I'd be happy to add an entry for the PICO-D4. But I need the PlatformIO board name. See ESP32 boards for a list of the boards supported by PlatformIO.

  2. John Maloney repo owner

    I've added preliminary support for building firmware for the Pico-D4. To try it you will need to:

    1. Install the PlatformIO command line tools.
    2. Clone this repository and checkout the "dev" branch.
    3. Run the following:
    pio run -e esp32-pico-d4 -t install
    

    You can modify the reserved pins and other details for the Pico-D4 by editing vm/ioPrims.c. A 1 in the reservedPins map means that the pin is reserved and can't be used by MicroBlocks code. The reservedPins map prevents people from accidentally crashing the ESP-32 by using a pin that is used internally (e.g. to access Flash memory).

    Here is the current entry:

    #elif defined(ARDUINO_ESP32_PICO)
        #define BOARD_TYPE "ESP32-Pico-D4"
        #define DIGITAL_PINS 40
        #define ANALOG_PINS 16
        #define TOTAL_PINS 40
        static const int analogPin[] = {};
        #define DEFAULT_TONE_PIN 2
        #define PIN_LED 13
        static const char reservedPin[TOTAL_PINS] = {
            0, 1, 0, 1, 1, 1, 1, 1, 1, 0,
            0, 1, 1, 0, 0, 1, 1, 1, 0, 0,
            1, 1, 1, 0, 1, 0, 0, 0, 1, 1,
            1, 1, 0, 0, 0, 0, 0, 0, 0, 1};
    

    I do not have a Pico-D4 so I will leave it up to you to test this and let me know anything needs to be changed.

  3. 梁帅 reporter

    Thank you so much, john!
    I tested the code you provided, which is very useful, but two reserved pins need to be adjusted. GPIO4 and GPIO39 can be used on the chip ESP32-Pico-D4.

        static const char reservedPin[TOTAL_PINS] = {
            0, 1, 0, 1, 0, 1, 1, 1, 1, 0,
            0, 1, 1, 0, 0, 1, 1, 1, 0, 0,
            1, 1, 1, 0, 1, 0, 0, 0, 1, 1,
            1, 1, 0, 0, 0, 0, 0, 0, 0, 0};
    

  4. 梁帅 reporter

    The command to compile firmware and upload it should be:

    pio run -e esp32-pico-d4 -t upload

  5. John Maloney repo owner

    Sorry I told you the wrong command for upload; I should have checked.

    I've added your change and pushed it to the dev branch.

  6. 梁帅 reporter

    I found some puzzling problems.
    I connected GPIO9 and GPIO10 of the ESP32-Pico-D4 chip to a signal pin of the motor drive chip, but the motor works strangely. Sometimes I want it to rotate but it doesn’t respond. Sometimes I set GPIO9 and GPIO10=0, but it suddenly shakes.
    Do we need to add codes like "PinMode (9, OUTPUT)" in some parts of the MicroBlock firmware?

    I have tried to program GPIO9 and GPIO10 with the Arduino framework in PlatformIO, and such bugs will not occur.
    In MicroBlocks, GPIO25 and GPIO26 are connected to another motor drive chip, and such bugs will not occur.

  7. John Maloney repo owner

    I just fixed a bug that could explain the problem you are seeing. (See issue 322.)

    Pull the latest changes from the repository, checkout the dev branch, and build and install the firmware. Does that fix the problem?

  8. Log in to comment