More microcontrollers, ESP8266, Raspberry Pi A+

ESP8266 size comparisonI have been working on electronics a bit more, I thought I would write up what I have been working on.

Most recently I have been working with NodeMCU on the ESP8266. The goal is to have a “captive wlan” with a message board. The ESP8266 is a neat little 80mhz microcontroller that costs about $4 and uses about 60ma of power @ 2.5-3.5v and perhaps most importantly, has a fairly strong 2.4ghz wifi antenna attached. It also has about 3.4MB of avalible flash memory, although that’s over shadowed by the meager ~64KB of RAM. It can run as an AP (wifi access point) or a client, or both at the same time, doing one of many things, such as a wifi bridge, or create a chain of wifi bridges.

NodeMCU is interesting in that it runs a version of Lua, so I have been learning that. This is psuedo-embedded programming so things like “web server” have big chunks of http protocol hard-coded in to the program itself, hard-coded exceptions, etc etc. There are no ini, xml, config files since everything in this tiny world of 96KB-RAM is purpose built – there are no multi-taskers here – variables take up too much space. I definitely see why someone ported the ESP8266 over to the Arduino environment.

So the plan is to attach the ESP8266 running NodeMCU, and then also have a DNS server that points all requests back to the webserver that’s also running locally. Luckily someone has already begun the first step and written that, here’s the github link. He’s using a custom firmware with the DNS stuff turned on. It looks like he’s using 0.9.5 which uses about 16KB more ram, and they’ve added this feature in 0.9.6, but he hasn’t reconciled the differences as of this writing.

Anyways, it seems like it should be fairly straightforward to rip out the basic html games, and replace it with a sort of form post method, which then writes to the top of a file, and then the “server” reads from the top of the file and feeds it in to a CSS-formatted “wall” of sorts. And then also probably a cleanup script that moves older posts to a 2.html, and every 10KB or so worth of text, adds an additional N.html, and if N-100 exists, delete n-100.html.

The ultimate idea would be to have an ESP8266 running off of a 26650 or pair of 18650s, charged via a 5v 500ma solar panel facing south, with a 5v->4.2 lipo/li ion charging circuit (with 2.7v cut-out), and then an LDO down to 3.3v regulated. Supposedly the ESP8266 will run for 1-2 days on an 18650 and you only need about 3 hours of direct sunlight to fully charge the 18650, so I am thinking a 4000mah 26650 should last 2 full days between charges.

Anyways, it’s a neat idea. A self contained, anonymous, community message board that is self powered. The whole thing could fit inside of a waterproof junction box with a neodymium magnet, and then put a blob of epoxy on the back so it becomes permanent and stick it to the back of an east-facing street sign, so that the solar panel is west-facing. Given 1000 charge-discharge cycles it could, in theory last between three and six years.

I was able to flash the ESP8266 over the weekend, I’ve become quite proficient at it. I wrote a thank you note over at the ESP8266 forum. It turns out if you over-volt any part of the ESP8266 it has bad effects on the NAND flash memory (winbond 4mb module) and scrambles the data and also the firmware. Re-flashing the old AI Thinker 0.9.5 SDK firmware seemed to fix most of the problems. Apparently if you are not able to send data, but you’re getting garbage data back from the ESP8266, that means you should just go ahead and flash, even if you can’t decode the data (I tried all available baud rates, no luck). Flashing firmware direct over serial and pulling pins high/low to the power rail(s) was a new experience for me. I definitely feel much closer to the hardware now than I ever did with an Arduino.

Flashing the ESP8266 with NodeMCU 0.9.6

Anyways this is what I wrote, for future generations:

Anyways, this is what worked for me.

I am flashing direct from a raspberry pi A+ (3.3v serial logic level) to an ESP-12

This is what worked for me, building on top of your instructions. You’ll have to make sure you have esptool and picocom installed, which probably requires pySerial.

Rpi GPIO 14 (pin 08) -> esp GPO RX
Rpi GPIO 15 (pin 10) -> esp GPO TX
Rpi GND (pin 06) -> esp GND

VCC -> 3.3v power source
VCC -> GPO CH_PD (*)

GND -> GND power source

To flash
Disconnect VCC -> 3.3v power source
Disconnect VCC -> GPO CH_PD (*)
Connect GND -> GPIO 0
VCC -> 3.3v power source

Run “sudo python –port /dev/ttyAMA0 write_flash 0×00 nodemcu-master-7-modules-2015-09-06-22-54-05-integer.bin”

IMMEDIATELY (~0.5 seconds) Connect VCC -> GPO CH_PD (*)

Should flash
Disconnect VCC -> 3.3v power source
Disconnect GND -> GPIO 0
Connect VCC -> 3.3v power source

Run “sudo picocom /dev/ttyAMA0 –b 9600 –omap crcrlf –imap crcrlf ”

I was NOT able to re-flash NodeMCU 0.9.6 over top of itself. I had to reflash the AI Thinker 0.9.5 SDK (stock) firmware. Reflashing the old AI Thinker 0.9.5 SDK firmware “revived” a bunch of previously “bricked” ESPs.

I will have to get in to how POST messages work, as they have to be manually handled by the Lua script. That’s a task for tomorrow. And then also coming up with CSS to frame everything with. I found some example code I think I can leverage off of and go from there.

I did manage to fry one of my ESP8266, on my HP dual power supply the knobs allow you to go from 0-20v, and the knobs rotate in the opposite direction as the analog voltage meter sweeps. As I went to test to see how the ESP8266 recovers from voltage cutout, I dialed it to “0″, and was agape when I saw the needle bury at 20v instead of 0v. oops. To my suprise, I was able to massage it back to life and flash it a couple of times, but every time I tried writinga 56kb file to the NAND memory, it would corrupt and become unresponsive. Maybe I can set it up as a temp sensor or something. Who knows.

This is the death scream of a serial device when you accidentally feed 20 volts directly in to it’s puny 3 volt brain. ( “AhhA!!)!!!!!1ù” ) RIP #ESP8266  I was able to reflash it and get it to boot, but the flash memory wouldn’t hold for very long. I think the NAND is more voltage-sensitive than the CPU.

This is the death scream of a serial device being overvolted

One idea I had for a temp sensor was, since with NodeMCU you can modify the SSID so easily, read the temp sensor, and set the SSID as something like “T_85F_H_54P” where 85F is the temp and 54P is the relative humidity. That way anyone within broadcast range can check the temp without having to login to the device. I guess you could encode another 24 bytes of information in the MAC address too but that’s not human readable.

Oh right, I’ve been using my Raspberry Pi A+ to talk to the ESP8266. The Pi and the ESP both have 3.3v logic level so no converter is necessary, just the RX, TX pins and a common ground. I’ve been using picocom to monitor the serial output, and a combination of esptool to burn firmware, and then luatool and nodemcu-uploadertool to upload files. I like luatool because you handle the serial port in the commandline rather than digging around in the .py file to set it, but the uploadertool supports unlimited(?) file size (largest I’ve done is I think 100kb?) and more importantly multi-file upload. It’s not nearly as fancy as the ESP SDK on windows, but I like that I can talk to the Pi and the ESP over wifi from anywhere in the house, and I’m not tied to a workbench somewhere with the ESP’s fairly fragile flashing setup (I’m just using breadboard and jumpers).

I also have a Raspberry Pi based robot using bluetooth and wifi and motor controller on a modified Shrimpbot chasis. I will have to put up a seperate post about that when I get a chance.

This entry was posted in computing, linux, Mechanical, robot and tagged , , , , , , . Bookmark the permalink.

Leave a Reply

Your email address will not be published. Required fields are marked *


You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>