ESP8266
Revision as of 22:39, 26 February 2021 by Colettace (talk | contribs) (→Program the board via boot.py and main.py)
Contents
General
- Developing for ESP32/8266 on Windows using the Linux subsystem(WSL) from 2019
- How to Connect ESP8266 to WiFi | A Beginner’s Guide
- MobaXterm for serial communication with REPL
- Use ampy ampy to manipulate files on the board's internal filesystem and run scripts.
pip install adafruit-ampy
- Can't use ampy while also simultaneously having a (MobaXTerm) serial communication (REPL) open
C-based development
Wemos Mini D1 Setup with MicroPython
- Install CH340 driver
- Install Python on Windows by opening a PowerShell and typing Python, which will bring you to the app store. You may need to edit your powershell profile file to add python installed scripts path to $Env:Path.
pip install esptool
- download MicroPython Firmware for Generic ESP8266 module
- Make sure a new COM device shows up in Windows Device Manager
- Install MobaXterm and Connect with baudrate 115200
D1 Mini V2 ESP-12F Wiki
- ESP8266 D1 Mini V2 ESP-12F WiFi Module - from protosupplies.com - $4.95
- ESP8266EX datasheet
- Operating current 80mA
- Power management
- Active mode
- modem-sleep mode
- wifi off (15 mA)
esp.sleep_type( esp.SLEEP_MODEM )
- light-sleep mode
- CPU paused.
- Wake up events will wake up the chip.
- Maintaining a sleep of 300 ms with a wakeup of 3ms to receive AP’s Beacon packages at interval requires about 0.9 mA.
machine.idle()
- return the amount of time that it slept before receiving a wake-up signal from one of the peripherals.machine.lightsleep([time_ms])
- deep-sleep mode
- Only real-time-clock is on.
- Sleep for 300s and wakes up to connect to AP (20 uA)
machine.deepsleep([time_ms])
- Use as WiFi adapter chip slaved to other MCU
- Clock speed 80/160 MHz (120MHz ATSAMD51 M4)
- 3.3V
- 4MB Flash
- 64kB instruction RAM
- 96kB Data RAM (half of ATSAMD51 M4)
- Build-in led is is board D4
- Corresponds to ESP board pin2. (See dev board docs for board to chip correspondance)
- Can't activate while using REPL
- Write the following code to main.py, then
ampy -p COM6 put .\main.py
import machine import time pin = machine.Pin(2, machine.Pin.OUT) for i in range(10): pin.on() time.sleep(0.5) pin.off() time.sleep(0.5)
esptool
esptool.py -h
esptool.py read_mac
esptool.py --port COM6 erase_flash
esptool.py --port COM6 --baud 460800 write_flash --flash_size=detect 0 .\esp8266-20200911-v1.13.bin
MicroPython
Program the board via boot.py and main.py
pip3 install --upgrade adafruit-ampy
ampy -p COM6 get boot.py
ampy -p COM6 put main.py
FYI/Nifty features
- Minimizethe creation and destruction of objects to avoid fragmentation of the heap
- micropython.const() - declare a const so compiler can optimize it
- micropython.mem_info(verbose=True)
- T = tuple
- L = list
- D = dictionary
- S = string
- A = array or bytearray
- F = float
- B = function
- M = module
- h = some other value, like an integer or python object
- equals sign means the memory chunk continues (single allocation from heap)
framebuf.FrameBuffer
- The FrameBuffer class provides a pixel buffer which can be drawn upon with pixels, lines, rectangles, text and even other FrameBuffer’s. It is useful when generating output for displays.