ESP8266

From Wildsong
Jump to navigationJump to search

2.4 GHz WiFi microcontroller module

Originally people used these as a sort of modem and serial cable without the wire. They sent data over WiFi via Hayes modem AT commands. Then someone figured out you did not need to connect a separate microcontroller. There is already one in the module.

I have a "Ai-Thinker ESP-12E", which I have successfully programmed with a blink program using PlatformIO and the ESP-PROG.

It can be programmed with the Arduino SDK, see this very helpful Instructable to get started. The story continues in this article on putting a web server on the tiny little card.

I have 5 Wemos/Lolin boards.

I have FEIT dimmers and Martin Jerry dimmers and switches, all are Tuya devices and use ESP8266 processors as their controllers. Update: the FEIT dimmers use ESP8285.

ESP12E + Pi Zero for ESP-NOW

I have an idea that I'd like to use ESP-NOW instead of WiFi on all these switches. That means I need an ESP-NOW gateway.

The ESP12E is on a Pi Zero W prototyping board right now but I have not got them hooked together yet.

Raspberry Pi connection

I am trying to set up the ESP-12E as a peripheral for a Pi Zero. The Pi will talk to Home Assistant on WiFi and to the cloud of ESP devices via the ESP-12E on ESP-NOW.

First though I need to reflash the ESP-12E. I realized that I can simply connect up the Pi Zero to program it and then leave it connected, that way anytime I need to flash new code onto it, it's already set up! Also, Over The Air reprogramming over ESP-NOW won't work, so this bypasses that issue too.

Here is an article on using a Pi to reflash an ESP8266. https://blog.3d-logic.com/2017/12/01/using-raspberry-pi-to-flash-esp8266/

He tells how to set up the Pi so that the serial port is freed up (not the console in other words). He has a diagram that references pins on some ESP that he had. I have to find it... Referring to https://randomnerdtutorials.com/esp8266-pinout-reference-gpios/ I see he probably has an ESP83266-01 module.

  • The pin he calls "CH_PD" is the "Enable" pin on my ESP-12E. It needs to be pulled up to 3.3v via a resistor.
  • RST needs to be pulled to ground.
  • I will put an LED on a spare GPIO. GPIO4 would be a good one.

My current understanding is that I will want to hold GPIO low and then reset the device by pulling down ENABLE momentarily to reboot it. This brings it up in FLASH mode. Then I should be able to send the image file to it. Espressif page on Boot Mode Selection

I wonder if I can install the tool chain on the Pi and access it remotely using Visual Studio Code? I don't want to install the entire X11 desktop on a Pi Zero. The article referenced above tells how to install and use "esptool", and how to install firmware.

Espressif firmware is available here: https://github.com/espressif The article suggests loading the NONOS_SDK (which is not being maintained) but I want to use the ESP8266_RTOS_SDK because realtime operating systems are cool! (And it's maintained.)


I'd like to add an LED on a GPIO pin so that I can track status. Neopixel? I have 9 more of those I think. They are fun. See https://www.instructables.com/ESP8266-controlling-Neopixel-LEDs-using-Arduino-ID/

Eventually I'd like the option to power off the entire ESP-12E if I want. MOSFET?

I think I will plug a mini OLED hat into the Pi so that I can put text up there.

I think that the Pi will be an MQTT client of Home Assistant. The modules out there in ESP-NOW space will probably also do MQTT so the Pi will also act as a proxy.

The Neopixel could show

  • receiving data from ESP-NOW
  • transmitting data on ESP-NOW
  • act as a night light
  • ESP-12E is sleeping

I don't know what kind of box this thing will be in yet so I don't know what other stuff I will cram into it. Motion sensor? Push button? Rotary encoder? Temp sensor? Feature creep? Yeah. Later for that.

Power

I will try powering the ESP8266 via the Pi after I confirm I can program it. I have to dig up a suitable 3.3V regulator. Must have one here somewhere! I will put a big cap to the 3.3 line to give it a little more stability.

esptool

Esptool is described here: https://github.com/espressif/esptool

It is a python program and normally just talks over a standard serial port device.

To enable the extra features I envision, I will need

  1. a script to put the device into flash boot.
  2. a script to reboot into normal mode

Flash mode:

set GPIO0 = 0
set EN = 0
sleep
set EN = 1

Normal mode:

set GPIO = 1
set EN = 0
sleep
set EN = 1

Read

  • It can read the SPI flash ID and MAC id of the chip, that could be handy.
  • It can read the existing memory so you can back up whatever is already on the chip and restore it later if you want.

Write

Use "dual flash io mode", whatever that is. (Explanation: SPI Flash Modes wiki page.

Try this.

esptool --flash_mode dio --flash-freq 40m --flash_size detect

Flash size is probably 4MB


WeMos D1 R1

WeMos D1 R1 from MPJA for $12.95, also available elsewhere for $9-10. Actually MPJA dropped the price today to $10 but you can get simpler boards for $3 or so from Amazon. I ordered 5 for $15 today.

The D1 R1 has the Arduino form factor but uses the ESP8266 as its processor.

In the Arduino IDE, select Tools->Board "WeMos R1 D1". (It's in the "ESP8266 Boards" package.) Everything I have tried to build in Examples has worked so far; blinking LEDs to WiFi to MQTT.

I built an IoT thing that uses a doppler RADAR motion sensor to detect movement and send MQTT "ON" signals to my Home Assistant. Works great.

Resources

Programming ESP8266 with Pi https://blog.3d-logic.com/2017/12/01/using-raspberry-pi-to-flash-esp8266/