For the last 6 months or so there's been a buzz in the underground hacker/maker/IoT community about a crazy new component that started to appear on AliExpress, and more recently on Ebay: the ESP8266, or its most common variant the ESP-01. At first the excitement was that for $5 we could get a simple to use, wifi board that could be easily hooked up to Arduino projects.
That was exciting, but as the community started to decipher the data sheets (available only in Chinese!) they realised it wasn't just a wifi board - it was controlled by a moderately powerful CPU, which included a boot loader that could refresh the firmware as easily as an Arduino. For $3 (current price!) the ESP01 provides a fully programmable embedded controller with wifi! By comparison the official Arduino Wifi shield is $70 (without host CPU), and other Arduino wifi solutions aren't much cheaper (for some reason Wifi is one area that the Arduino hasn't really competed well).
Once it became clear that it was possible to reprogram the ESP01, a port of Gcc quickly emerged, then someone packaged it into an Arduino plugin and developed Arduino compatable libraries. Adafruit now make a nice board using the chip, and are also supporting the Arduino IDE.
The ESP still isn't quite there yet in terms of either hardware or software - the hardware still needs bit of hacking together, and the software isn't quite optimised enough to run on the chip, but its real close, and we can expect the ESP to hit prime time over the next 12 months.
With that in mind I ordered a few and started experimenting with Sniff. There's still a way to go, but here's a summary of progress to date.
First of, some basics you need to know: The chip itself is the ESP8266. There are various boards available, typically known as ESP-01, ESP-02, ESP-03 etc... The only differences between these are the physical connections - which pins are accesable, and the type of connections used. The ESP01 has very limited pins exposed, but they standard 0.1" jumper spacing. The ESP201 has more pins available, and is a good choice, but the ESP01 is much more common and so cheap (£3.20 for two including shipping) its the place everyone starts. Most of the other boards require some serious soldering to use, so you're on your own with them. Avoid the ESP-05 unless you simply want a wifi bridge, as it looks pin friendly (it is) but isn't reprogrammable.
ESP01 Hardware
The ESP01 is tiny! It's about 2cm by 1cm, which makes it a bit fiddly to work with. For a start there's no room for the board to label the connections! Fortunately this diagram makes things pretty clear:
There are 8 pins exposed.
Gnd/Vcc are pretty obvious, but Vcc needs to be 3.3v, and it needs a relatively hefty supply (250mA) to drive the wifi, so don't try powering it of an Arduino. Some people have had success with the regulators built into USB/serial adapters, but others report that they're unreliable. I wired up a separate 3.3v regulator (complete boards to do this cost pennies on ebay).
3.3v is also pretty important for the serial. You need a 3.3v USB/serial adapter, and connect that to the UTXD and URXD pins to communicate with your computer (remember to connect the GND too, but not the Vcc). Don't use a 5V adapter (or connect these directly to a 5V arduino) or bad things might happen.
CH_PD is for powering down the board to save power - we don't care so connect it to 3.3v. RST can reset the board when its connected to 0v, but was can just leave it unconnected. It's possible to connect it to some of the lines on the Serial adapter to automatically reset the board, but I left it disconnected, and manually power cycle the board when needed.
This leaves GPIO0 and GPIO2. These are free for for you to use for your own hardware. That is a bit limited, but there's plenty you can do with just a couple of pins. If you need more then look at the ESP201. The important thing to know is that we can put the board into programming mode by connecting GPIO0 to GND when we power up/reset the chip.
It's quite possible to get all of this working with a load of jumper cables, but I wired up a dev system on protoboard. It includes the 3.3v regulator, a socket for a 3.3v ftdi usb/serial adapter, 3pin servo style headers on GPIO0 and 2, and a push to make reset button to ground GPIO0 for programming.
The ESP01 is socketed, so I can use this to easily program the board, then potentially install it in another circuit. To program I just power off the board, press the button and power on, then download the code from the computer.
Arduino Software
Now we need some software. The most up to date versions of the ESP8266 tools are available from ESP8266.com - the community site which is developing them. However things are moving fast and sometimes you need a more stable target. Adafruit are repackaging snapshots of the code, and adding support for their own boards, so you can find instructions for installing their version of the ESP tools on their website. Sniff is currently using the 1.6.2 version of the Adafruit Arduino ESP tools - newer versions might not work just yet. If you're reading this in the future, check the release notes for your version of Sniff to see which version of Arduino ESP is best.
You should now be able to fire the Arduino software and compile the standard blink example on an ESP01: Just plug everything in, select "generic ESP", and change the led pin to 2, and connect an LED(with resistor) to pin 2. Power down the ESP01, connect gpio0 to gnd, and power it back on. You can then disconnect the gpio0-gnd connect: it only needs to be connected at reset, and the board will stay in programming mode as long as you need it.
Then press download in the Arduino IDE, and it should just download and go!
Sniff
If you've got this far you're home free! Just setup Sniff as normal. If you're on Unix/Mac it will find the serial port (it will say its an Arduino - thats OK!). On Windows you'll need to type
export ARDUINODEV=COM3
or whichever COM port its been assigned.
Then just take the blink example, set the pin to 2, reset the board into programming mode, then compile and download it:
esp-sniff blink.sniff
Sniff should "just work" on the ESP as it does on an Arduino... There are some gotcha's however PWM isn't yet supported in the Adafruit Arduino software (it should be in the next release), and the current Arduino tools aren't particularly efficient - the generated code is far bigger than it needs to be. This is also expected to improve in the next Adafruit update. In the mean time, you're going to run out of memory quickly... sorry... it should get better!
With Sniff specifically digital inputs and digital outputs work. Analog input isn't possible on the ESP01, but should be possible on other ESP8266 boards. Analog output should work when Adafruit update their codebase. i2c works - it uses pins 0 and 2 simply because that's all that's available on the ESP01. SPI isn't possible with the ESP01 because there simply aren't enough pins. In future hardware SPI should be possible for the ESP201, but its a work in progress.
The key selling point of the ESP01 of course is its built in wifi. Sniff plays nice with the rest of the ESP libraries, so that the WIFI will power up and connect when Sniff code is running but we currently don't have any way to access it from Sniff yet. Once the ESP toolset stabalises and becomes efficient enough to make it viable we'll be able to get this working!
Conclusions
The ESP8266 isn't quite ready for prime time yet, but its getting lots in nominations for "best newcomer". It's price and wifi support mean that it will be a big hit in the DIY "Internet of Things" space. Over the next few months, expect the tools to mature further to improve stability, features and code size. Also expect a rash of boards like the DigiSpark Oak. I'm sure someone will put an ESP in an Uno form factor before long!
We wanted to get Sniff running on these boards as soon as possible. Right now they're quite a bit more work and more limited than a simple Arduino solution, but imagine connecting a ds18b20 to gpio2 (tested and working!). Once the wifi is sorted, you can build a wifi enabled thermometer for less than £3!!!! Put one in each room and map out the heat movement in your house for a fraction of the cost of current systems! That IS exciting.
No comments:
Post a Comment