ESP8266

From Colettapedia
Jump to navigation Jump to search

General

C-based development

Wemos Mini D1 Setup with MicroPython

  1. Install CH340 driver
  2. 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.
  3. pip install esptool
  4. download MicroPython Firmware for Generic ESP8266 module
  5. Make sure a new COM device shows up in Windows Device Manager
  6. 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

  1. pip3 install --upgrade adafruit-ampy
  2. ampy -p COM6 get boot.py
  3. 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.

WebREPL