Raspberry BASIC > General Discussion
ESP32 MicroPython
John Spikowski:
I was able to get MicroPython loaded on my ESP32-DEVKITC32D board. I'm using Putty on the RPi 3B to connect via /dev/ttyUSB0.
>>> help('modules')
__main__ gc ubinascii urandom
_boot inisetup ubluetooth ure
_onewire machine ucollections urequests
_thread math ucryptolib uselect
_uasyncio micropython uctypes usocket
_webrepl neopixel uerrno ussl
apa106 network uhashlib ustruct
btree ntptime uheapq usys
builtins onewire uio utime
cmath uarray ujson utimeq
dht uasyncio/__init__ umqtt/robust uwebsocket
ds18x20 uasyncio/core umqtt/simple uzlib
esp uasyncio/event uos webrepl
esp32 uasyncio/funcs upip webrepl_setup
flashbdev uasyncio/lock upip_utarfile websocket_helper
framebuf uasyncio/stream upysh
Plus any modules on the filesystem
>>>
>>> machine.freq(240000000)
>>> machine.freq()
240000000
>>>
John Spikowski:
I was able to get my DS18B20 temperature sensor to work with the ESP32-DEVKITC32D board.
The interpretive method of programming sure beats having to compile an image and flash it to the controller with each experiment.
I'm going to flash my ESP32-PICO with MicroPython to free up my faster board for more demanding projects.
>>>
paste mode; Ctrl-C to cancel, Ctrl-D to finish
=== import time, ds18x20
=== from machine import Pin
=== import onewire
===
=== ow = onewire.OneWire(Pin(12))
=== ds = ds18x20.DS18X20(ow)
=== i = 1
=== while i < 11:
=== roms = ds.scan()
=== ds.convert_temp()
=== for rom in roms:
=== print("Sensor " + str(rom) + ": " + str(ds.read_temp(rom)))
=== time.sleep_ms(2000)
=== i += 1
Sensor bytearray(b'(\xff&\xc2\x80\x17\x04\x93'): 22.375
Sensor bytearray(b'(\xff&\xc2\x80\x17\x04\x93'): 22.3125
Sensor bytearray(b'(\xff&\xc2\x80\x17\x04\x93'): 22.3125
Sensor bytearray(b'(\xff&\xc2\x80\x17\x04\x93'): 22.3125
Sensor bytearray(b'(\xff&\xc2\x80\x17\x04\x93'): 22.3125
Sensor bytearray(b'(\xff&\xc2\x80\x17\x04\x93'): 22.375
Sensor bytearray(b'(\xff&\xc2\x80\x17\x04\x93'): 22.375
Sensor bytearray(b'(\xff&\xc2\x80\x17\x04\x93'): 22.375
Sensor bytearray(b'(\xff&\xc2\x80\x17\x04\x93'): 22.375
Sensor bytearray(b'(\xff&\xc2\x80\x17\x04\x93'): 22.375
>>> print(rom)
bytearray(b'(\xff&\xc2\x80\x17\x04\x93')
>>> print(roms)
[bytearray(b'(\xff&\xc2\x80\x17\x04\x93')]
>>> print(ow)
<OneWire object at 3ffe5360>
>>> print(ds)
<DS18X20 object at 3ffe5370>
>>>
John Spikowski:
I got MicroPython running on my ESP32-PICO board. The sensor blinks each time it's scanned.
Picture
pi@RPi3B:~/esp $ /home/pi/esp/esp-idf/components/esptool_py/esptool/esptool.py --port /dev/ttyUSB0 erase_flash
esptool.py v3.1-dev
Serial port /dev/ttyUSB0
Connecting........_
Detecting chip type... ESP32
Chip is ESP32-PICO-D4 (revision 1)
Features: WiFi, BT, Dual Core, 240MHz, Embedded Flash, VRef calibration in efuse, Coding Scheme None
Crystal is 40MHz
MAC: d8:a0:1d:5f:c1:54
Uploading stub...
Running stub...
Stub running...
Erasing flash (this may take a while)...
Chip erase completed successfully in 5.1s
Hard resetting via RTS pin...
pi@RPi3B:~/esp $
pi@RPi3B:~/esp $ /home/pi/esp/esp-idf/components/esptool_py/esptool/esptool.py --chip esp32 --port /dev/ttyUSB0 --baud 460800 write_flash -z 0x1000 esp32-idf4-20210202-v1.14.bin
esptool.py v3.1-dev
Serial port /dev/ttyUSB0
Connecting....
Chip is ESP32-PICO-D4 (revision 1)
Features: WiFi, BT, Dual Core, 240MHz, Embedded Flash, VRef calibration in efuse, Coding Scheme None
Crystal is 40MHz
MAC: d8:a0:1d:5f:c1:54
Uploading stub...
Running stub...
Stub running...
Changing baud rate to 460800
Changed.
Configuring flash size...
Compressed 1484624 bytes to 951640...
Wrote 1484624 bytes (951640 compressed) at 0x00001000 in 24.2 seconds (effective 491.4 kbit/s)...
Hash of data verified.
Leaving...
Hard resetting via RTS pin...
pi@RPi3B:~/esp $
John Spikowski:
This is a ESP32-PICO MicroPython pystone_lowmem benchmark example. This also shows how to use upip to install additional libraries.
--- Code: Python --->>>MPY: soft rebootMicroPython v1.14 on 2021-02-02; ESP32 module with ESP32Type "help()" for more information.>>> import network>>> sta_if = network.WLAN(network.STA_IF)>>> sta_if.active()False>>> sta_if.active(True)True>>>>>> sta_if.scan()[(b'jrs', b'\xd8\x07\xb6\xf8\xb1\x97', 10, -31, 4, False), (b'BillingsHouse', b'D\x1c\x12\xd8\x99\x96', 1, -64, 3, False), (b'Nika', b'\xec\xaa\xa02\xb0h', 6, -79, 3, False), (b'chicken shit', b'\xd4\xab\x82\xc7\x8d\x92', 1, -84, 3, False), (b'AOL', b'\xbc\x9bh\xa6\x0f\x18', 11, -84, 3, False), (b'2018NEW3beginsYIP!', b'\xd4\xab\x82\xc3\x15\xea', 11, -84, 3, False), (b'My Bell', b'\x80>H\xb7o\xc5', 11, -86, 4, False), (b'Anahouse', b'\x84\x00-\x03\xc1\x98', 11, -89, 3, False), (b'Guapo', b'\xac\xdbHB\xa9\x86', 11, -89, 3, False), (b'IslandHouse', b'P\xd4\xf7\x02b\x89', 2, -90, 3, False), (b'password', b'<z\x8a9\xce`', 1, -91, 3, False), (b'BK WiFi', b'\\\xe3\x0e\xbc\x13\xb5', 6, -91, 3, False), (b'UmbrellaCorp', b'\x84\xd8\x1bfu\xce', 1, -95, 3, False)]>>> sta_if.connect('jrs', 'MY_PASSWORD')>>> sta_if.isconnected()True>>> import upip>>> upip.install("micropython-pystone_lowmem")Installing to: /lib/Warning: micropython.org SSL certificate is not validatedInstalling micropython-pystone_lowmem 3.4.2.post4 from https://micropython.org/pi/pystone_lowmem/pystone_lowmem-3.4.2.post4.tar.gz>>> import pystone_lowmem>>>>>> pystone_lowmem.main()Pystone(1.2) time for 500 passes = 536msThis machine benchmarks at 932 pystones/second>>>
This is the same benchmark but using my ESP32-DEVKITC32D board and increasing the processor frequency rate.
--- Code: Python --->>>MPY: soft rebootMicroPython v1.14 on 2021-02-02; ESP32 module with ESP32Type "help()" for more information.>>> import network>>> sta_if = network.WLAN(network.STA_IF)>>> sta_if.active()False>>> sta_if.active(True)True>>> sta_if.connect('jrs', 'MY_PASSWORD')>>> sta_if.isconnected()True>>> import upip>>> upip.install("micropython-pystone_lowmem")Installing to: /lib/Warning: micropython.org SSL certificate is not validatedInstalling micropython-pystone_lowmem 3.4.2.post4 from https://micropython.org/pi/pystone_lowmem/pystone_lowmem-3.4.2.post4.tar.gz>>> import pystone_lowmem>>> pystone_lowmem.main()Pystone(1.2) time for 500 passes = 537msThis machine benchmarks at 931 pystones/second>>> import machine>>> machine.freq(240000000)>>> pystone_lowmem.main()Pystone(1.2) time for 500 passes = 432msThis machine benchmarks at 1157 pystones/second>>>
I retried the ESP32-PICO (not related to RPi Pico) and increased the frequency to 240000000 it ran faster than my ESP32-DEVKITC32D board. :o
>>> pystone_lowmem.main()
Pystone(1.2) time for 500 passes = 428ms
This machine benchmarks at 1168 pystones/second
>>>
I need to do a side-by-side comparison to see what makes them different.
I found a post that shows the RPI Pico pystone_lowmem results.
>>> exec(open('Pi_Pico_Pystone_lowmem.py').read())
Pystone(1.2) time for 500 passes = 460ms
This machine benchmarks at 1086 pystones/second
>>>
John Spikowski:
ESP32-PICO-D4
Detailed Spec.
ESP32 contains two low-power Xtensa 32-bit LX6 microprocessors. (240 MHz) The internal memory includes:
* 448 KB of ROM for booting and core functions.
* 520 KB of on-chip SRAM for data and instructions.
* 8 KB of SRAM in RTC, which is called RTC FAST Memory and can be used for data storage; it is accessedby the main CPU during RTC Boot from the Deep-sleep mode.
* 8 KB of SRAM in RTC, which is called RTC SLOW Memory and can be accessed by the co-processorduring the Deep-sleep mode.
* 1 Kbit of eFuse: 256 bits are used for the system (MAC address and chip configuration) and the remaining768 bits are reserved for customer applications, including flash-encryption and chip-ID
* 4 MB Flash
* Wi-Fi and Bluetooth
$10
ESP32-DEVKITC32D
Detailed Spec.
ESP32-D0WD contains a dual-core Xtensa 32-bit LX6 MCU microprocessor. (240 MHz) The internal memory includes:
* 448 KB of ROM for booting and core functions.
* 520 KB of on-chip SRAM for data and instructions.
* 8 KB of SRAM in RTC, which is called RTC FAST Memory and can be used for data storage; it is accessedby the main CPU during RTC Boot from the Deep-sleep mode.
* 8 KB of SRAM in RTC, which is called RTC SLOW Memory and can be accessed by the co-processorduring the Deep-sleep mode.
* 1 Kbit of eFuse: 256 bits are used for the system (MAC address and chip configuration) and the remaining768 bits are reserved for customer applications, including flash-encryption and chip-ID.
* 4 MB Flash
* Wi-Fi and Bluetooth
$10
Raspberry Pi Pico
* Dual-core Arm Cortex-M0+ processor, flexible clock running up to 133 MHz
* 264KB on-chip SRAM
* 2MB on-board QSPI Flash
$4
Navigation
[0] Message Index
[#] Next page
Go to full version