ESP8266: Difference between revisions
Brian Wilson (talk | contribs) |
Brian Wilson (talk | contribs) mNo edit summary |
||
Line 39: | Line 39: | ||
I see he probably has an ESP83266-01 module. | I see he probably has an ESP83266-01 module. | ||
The pin he calls "CH_PD" is the "Enable" pin on my ESP-12E. | * 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. | |||
* | |||
* I will put an LED on a spare GPIO. | |||
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. | 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. |
Revision as of 03:27, 29 January 2021
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 this one:
ESP8266MOD Ai-Thinker ESP-12E
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 since started using FEIT dimmers and Martin Jerry switches, both of which are Tuya devices and use ESP8266 processors as their controllers. See Home Control.
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.
Raspberry Pi connection
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.
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 flask 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.
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
- a script to put the device into flash boot.
- 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