NodeMCU seemed like a natural choice for my new ESP32, but I quickly learned that the support was not ready yet and decided to look elsewhere. MicroPython was on my list for a long time so I gave it a try, here's how I went about it:
First, the latest MicroPython firmware for the ESP32 board needs to be downloaded from here (esp32-20180416-v1.9.3-548-gd12483d9.bin at the time of writing)
Second, we will need to install the esptool.py tool, the easies way to get it is via pip, like so:
Code: Select all
$ pip install esptool
Code: Select all
Collecting esptool
Downloading https://files.pythonhosted.org/packages/cd/68/c28961d88cf50ca6d5de5e4b354dc47f77b9e74d4cd4d5bee4feaa7963b3/esptool-2.3.1.tar.gz (72kB)
100% |################################| 81kB 744kB/s
Requirement already satisfied: pyserial>=2.5 in c:\dev_tools\python27\lib\site-packages (from esptool)
Collecting pyaes (from esptool)
Downloading https://files.pythonhosted.org/packages/44/66/2c17bae31c906613795711fc78045c285048168919ace2220daa372c7d72/pyaes-1.6.1.tar.gz
Collecting ecdsa (from esptool)
Downloading https://files.pythonhosted.org/packages/63/f4/73669d51825516ce8c43b816c0a6b64cd6eb71d08b99820c00792cb42222/ecdsa-0.13-py2.py3-none-any.whl (86kB)
100% |################################| 92kB 1.4MB/s
Installing collected packages: pyaes, ecdsa, esptool
Running setup.py install for pyaes ... done
Running setup.py install for esptool ... done
Successfully installed ecdsa-0.13 esptool-2.3.1 pyaes-1.6.1
Code: Select all
$ esptool.py --chip esp32 --port COM3 write_flash -z 0x1000 esp32-20180414-v1.9.3-548-gd12483d9.bin
Code: Select all
esptool.py v2.3.1
Connecting........___
Chip is ESP32D0WDQ6 (revision 1)
Features: WiFi, BT, Dual Core
Uploading stub...
Running stub...
Stub running...
Configuring flash size...
Auto-detected Flash size: 4MB
Compressed 973584 bytes to 604211...
Wrote 973584 bytes (604211 compressed) at 0x00001000 in 54.0 seconds (effective 144.2 kbit/s)...
Hash of data verified.
Leaving...
Hard resetting via RTS pin...
Code: Select all
>>> help('modules')
Code: Select all
__main__ flashbdev random uos
_boot framebuf re upip
_onewire gc select upip_utarfile
_thread hashlib socket upysh
apa106 heapq ssl urandom
array inisetup struct ure
binascii io sys urequests
btree json time uselect
builtins machine ubinascii usocket
cmath math ucollections ussl
collections micropython uctypes ustruct
dht neopixel uerrno utime
ds18x20 network uhashlib utimeq
errno ntptime uheapq uzlib
esp onewire uio websocket
esp32 os ujson zlib
Plus any modules on the filesystem
Code: Select all
>>> import machine
>>> i2c = machine.I2C(scl=machine.Pin(4), sda=machine.Pin(5))
>>> i2c.scan()
[60]
There's another useful tool worth installing which will help us to upload files to the board. The tool in question is Adafruit MicroPython Tool (ampy), you can get it via pip as well, like so:
Code: Select all
$ pip install adafruit-ampy
Code: Select all
Collecting adafruit-ampy
Using cached adafruit-ampy-1.0.3.tar.gz
Requirement already up-to-date: click in c:\dev_tools\python27\lib\site-packages (from adafruit-ampy)
Collecting pyserial (from adafruit-ampy)
Using cached pyserial-3.4-py2.py3-none-any.whl
Installing collected packages: pyserial, adafruit-ampy
Found existing installation: pyserial 3.2.1
Uninstalling pyserial-3.2.1:
Successfully uninstalled pyserial-3.2.1
Running setup.py install for adafruit-ampy ... done
Successfully installed adafruit-ampy-1.0.3 pyserial-3.4
Code: Select all
$ ampy --port COM3 put ssd1306.py
Code: Select all
>>> import os
>>> os.listdir()
['boot.py', 'ssd1306.py']
Code: Select all
>>> import machine, ssd1306
>>> i2c = machine.I2C(scl=machine.Pin(4), sda=machine.Pin(5))
>>> oled = ssd1306.SSD1306_I2C(128, 64, i2c, 60)
>>> oled.fill(0)
>>> oled.text("Hello World!", 0, 0)
>>> oled.show()