3.4 KiB
3.4 KiB
MicroPython Implementation Notes
- Backup Up firmware, flashing, etc.
- Circuit Layout
- SSD 1306
- MPU 6050
- Turn off MPU (through vext, also turns off screen)
- Wifi Connection Example, outbound requests.
- Getting a Unique ID for this instance
- NTP
- Web Server
- Connections
[3/8]Things to look at
Backup Up firmware, flashing, etc.
On lolin32, need to hold down the reset while esptool is connecting, and then release to get this to work.
Backup existing firmware from 4M Flash ESP32
esptool.py -b 115200 --port /dev/ttyUSB0 read_flash 0x00000 0x400000 lolin32_original.bin
Update Flash from backup
esptool.py -b 115200 --port /dev/ttyUSB0 write_flash --flash_freq 80m 0x000000 lolin32_original.bin
Erase Flash
esptool.py -b115200 --port /dev/ttyUSB0 erase_flash
Flash with MicroPython
esptool.py --chip esp32 --port /dev/ttyUSB0 write_flash -z 0x1000 ~/Downloads/esp32-idf3-20200902-v1.13.bin
Circuit Layout
| Pin | Used For |
| 37 | SDA - MPU6050 |
| 36 | SCL - MPU6050 |
SSD 1306
from machine import I2C, Pin
import ssd1306
rst = Pin(16, Pin.OUT)
rst.value(1)
scl = Pin(15, Pin.OUT, Pin.PULL_UP)
sda = Pin(4, Pin.OUT, Pin.PULL_UP)
i2c = I2C(scl=scl, sda=sda, freq=450000)
oled = ssd1306.SSD1306_I2C(128, 64, i2c, addr=0x3c)
oled.fill(0)
oled.text('ESP32', 45, 5)
oled.text('MicroPython', 20, 20)
oled.show()
MPU 6050
from machine import I2C, Pin
from mpu6050 import accel
scl=Pin(36, Pin.OUT)
sda=Pin(37, Pin.OUT)
i2c = I2C(scl=scl, sda=sda, freq=450000)
a = accel(i2c)
a.get_values()
Turn off MPU (through vext, also turns off screen)
from machine import Pin
vext = Pin(21, Pin.OUT, Pin.PULL_HOLD)
vext.value(0) # Turns ON Vext
vext.value(1) # Turns OFF Vext
machine.deepsleep()
Wifi Connection Example, outbound requests.
import network
import machine
wlan = network.WLAN(network.STA_IF)
wlan.active(True)
binary_id = machine.unique_id()
hostname = 'timeular-{:02x}{:02x}{:02x}{:02x}'.format(binary_id[0],binary_id[1], binary_id[2], binary_id[3])
wlan.config(dhcp_hostname='timeular')
wlan.connect("Hart's",'D187wn644GeH')
wlan.if_config()
Getting a Unique ID for this instance
import machine
binary_id=machine.unique_id()
hex_id = '{:02x}{:02x}{:02x}{:02x}'.format(binary_id[0],binary_id[1],binary_id[2],binary_id[3])
This can be used to append to e.g. the DHCP hostname to make it likely to be unique.
NTP
import ntptime
ntptime.settime()
import machine
rtc = machine.RTC()
rtc.datetime()
Web Server
import picoweb
from network import WLAN, STA_IF
app = picoweb.WebApp('main')
@app.route("/")
def index(req,resp):
yield from picoweb.start_response(resp)
yield from resp.awrite("Hello world from picoweb running on the ESP32")
app.run(debug=True,host=WLAN(STA_IF).ifconfig()[0],port=80)
Connections
Pin 23 ESP -> SDA MPU Pin 19 ESP -> SCL MPU
MPU AD0 -> - Rail MPU GND -> - Rail MPU Vcc -> + RailArduino MPU 6050 Serial Monitor
ESP GND -> - Rail ESP VEXT -> +Rail
[3/8] Things to look at
- Can we turn off the MPU with VEXT Control? (ESP Pin 21).
- Connecting to WiFi - Client Mode
- Connecting to WiFi - Direct Mode
- BLE?
- NTP?
- How to store the data appropriately - Flash/SqlLite, RTC memory?
- How to retrieve data over WiFi
- How to detect battery low
- WiFiManager