162 lines
3.4 KiB
Org Mode
162 lines
3.4 KiB
Org Mode
|
|
#+TITLE: MicroPython Implementation Notes
|
|
|
|
* 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
|
|
#+BEGIN_SRC bash
|
|
esptool.py -b 115200 --port /dev/ttyUSB0 read_flash 0x00000 0x400000 lolin32_original.bin
|
|
#+END_SRC
|
|
|
|
** Update Flash from backup
|
|
#+BEGIN_SRC bash
|
|
esptool.py -b 115200 --port /dev/ttyUSB0 write_flash --flash_freq 80m 0x000000 lolin32_original.bin
|
|
#+END_SRC
|
|
|
|
** Erase Flash
|
|
#+BEGIN_SRC bash
|
|
esptool.py -b115200 --port /dev/ttyUSB0 erase_flash
|
|
#+END_SRC
|
|
|
|
** Flash with MicroPython
|
|
|
|
#+BEGIN_SRC bash
|
|
esptool.py --chip esp32 --port /dev/ttyUSB0 write_flash -z 0x1000 ~/Downloads/esp32-idf3-20200902-v1.13.bin
|
|
#+END_SRC
|
|
|
|
|
|
* Circuit Layout
|
|
|
|
| Pin | Used For |
|
|
| 37 | SDA - MPU6050 |
|
|
| 36 | SCL - MPU6050 |
|
|
| | |
|
|
|
|
|
|
* SSD 1306
|
|
|
|
#+BEGIN_SRC python
|
|
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()
|
|
#+END_SRC
|
|
|
|
* MPU 6050
|
|
|
|
#+BEGIN_SRC python
|
|
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()
|
|
#+END_SRC
|
|
|
|
|
|
* Turn off MPU (through vext, also turns off screen)
|
|
#+BEGIN_SRC python
|
|
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()
|
|
#+END_SRC
|
|
|
|
* Wifi Connection Example, outbound requests.
|
|
|
|
#+BEGIN_SRC python
|
|
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()
|
|
#+END_SRC
|
|
|
|
* Getting a Unique ID for this instance
|
|
|
|
#+BEGIN_SRC python
|
|
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])
|
|
#+END_SRC
|
|
|
|
This can be used to append to e.g. the DHCP hostname to make it likely
|
|
to be unique.
|
|
|
|
* NTP
|
|
|
|
#+BEGIN_SRC python
|
|
import ntptime
|
|
ntptime.settime()
|
|
import machine
|
|
rtc = machine.RTC()
|
|
rtc.datetime()
|
|
#+END_SRC
|
|
|
|
* Web Server
|
|
|
|
#+BEGIN_SRC python
|
|
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)
|
|
#+END_SRC
|
|
|
|
* 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
|
|
|
|
- [X] Can we turn off the MPU with VEXT Control? (ESP Pin 21).
|
|
- [X] Connecting to WiFi - Client Mode
|
|
- [ ] Connecting to WiFi - Direct Mode
|
|
- [ ] BLE?
|
|
- [X] NTP?
|
|
- [ ] How to store the data appropriately - Flash/SqlLite, RTC memory?
|
|
- [ ] How to retrieve data over WiFi
|
|
- [ ] How to detect battery low
|
|
- [[https://github.com/tayfunulu/WiFiManager][WiFiManager]]
|
|
|
|
|
|
|
|
#+BEGIN_SRC python
|
|
|
|
#+END_SRC
|