Trying to use PWM with pin 1 results in this error message:
Code: Select all
ValueError: PWM not supported on pin 1
I played with Arduino IDE, and with that "analogWrite()" did work on all 4 ESP-01 pins 0-3.
I found reason for pins 1 and 3 not allowing for PWM for MicroPython -- they are not listed here:
Code: Select all
pi@raspberrypi400:~/pico/micropython/ports/esp8266 $ grep "2, 4, 5" *.c
esppwm.c:STATIC const uint8_t pin_num[PWM_CHANNEL] = {0, 2, 4, 5, 12, 13, 14, 15};
pi@raspberrypi400:~/pico/micropython/ports/esp8266 $
I am used to build my own MicroPython for Raspberry Pico.
Today I tried to build ESP8266 MicroPython and failed on 32bit Raspberrry Buster, 32bit Raspberry Bullseye as well as on 64bit Intel Ubuntu 20.04.
On Raspberry I tried to install esp-open-sdk, that failed complaining about bash version not >=3.1 although bash version is 5.0.3. Commenting that out building fails later in "_toolchain" target:
https://github.com/pfalcon/esp-open-sdk
On Ubuntu 20.04 python-serial is missing, and cannot be apt installed.
So I tried an adventure, and succeeded.
I searched for byte sequence 00 02 04 05 in hexdump of ESP8266 1M binary, and found it exactly once:
Code: Select all
$ od -Ax -tx1 esp8266-1m-20210902-v1.17.bin | grep "00 02 04 05"
08def0 00 00 00 00 00 00 00 00 00 02 04 05 0c 0d 0e 0f
$
Since pins 4 and 5 do not exist on ESP-01, I used hexedit to change them to 1 and 3:
Code: Select all
$ diff <(od -tx1 esp8266-1m-20210902-v1.17.bin) <(od -tx1 esp8266-1m-20210902-v1.17.bin.mod)
36074c36074
< 2157360 00 00 00 00 00 00 00 00 00 02 04 05 0c 0d 0e 0f
---
> 2157360 00 00 00 00 00 00 00 00 00 02 01 03 0c 0d 0e 0f
$
After flashing the ".mod" binary, I enabled webrepl by "import webrepl_setup".
Finally I removed ESP-01 from little USB programming board and connected only GND and 3V3.
(no idea why connecting 3V3 to EN was not needed)
<EDIT>this was not needed on newer 1M ESP-01 module with printed pin numbering, just tested on an older 1M ESP-01 module, and that works only when EN is high</EDIT>
Then I did "chromium-browser webrepl.html" in directory cloned:
https://github.com/webrepl/webrepl
Then I connected my Pi400 to "MicroPython-......" network and pressed on "Connect" button.
After connecting, PWM works on all 4 ESP-01 pins (I verified each pin with oscilloscope): This modified MicroPython binary is only useful for ESP-01, but for that it enables control of two DC motors for my tiny MicroPython robots with DRV8833 motor driver:
viewtopic.php?f=5&t=11454
Until now I used ESP-01 for telnet wireless into Raspberry Pico microcontrollers (with Arduono WifiToSerial.ino example flashed):
Now that I have 4 PWM channels on ESP-01, the next tiny robot will get only ESP-01 and DRV8833 motor controller (the robot is built from two solar car toys with the help of a Dremel and superglue). And it will still allow wireless robot control with MicroPython REPL: