Off-the-Shelf Hacker: The Split Personality of the ESP8266 WiFi Chip
There seems to be quite a bit of confusion on when and how you use the ESP8266 WiFi chips. In this week’s Off-the-Shelf Hacker column, I’ll discuss the vafrious ways the module can be controlled by your mainboard.
The ESP8266 WiFi Module is a self-contained System-on-a-Chip (SoC) with integrated TCP/IP protocol stack. The chip provides a way to give a microcontroller access to a WiFi network, according to electronics retailer SparkFun.
When and how you’d use an Arduino is well established. If you just want to read some inputs, do a few calculations and set some outputs, the Arduino will certainly fit the bill. The ESP8266 is a bit different, in that it presents two ways of accessing its functionality, though modem software (“AT” mode) or as a stand-alone device.
Today, I’ll explain the split personality of the 8266 and why you might use each mode
“AT mode” works right out of the box. This mode makes the 8266 into an old-school telephone modem, recognizing the ancient “AT” command set model.
What’s cool about AT mode is that you simply connect it to anything that talks over a serial line, like an Arduino and send it commands to do stuff. If your Arduino sends the 8266 the text string, “AT+CWLAP,” you’ll get a reply with the list of the available access points, within range. You could join one of those access points with “AT+CWJAP=”SSID,””Password,” using the appropriate SSID and password. There are a limited number of AT commands for various tasks, so you can’t tweak every last bit of performance out of the 8266. Think of AT mode in terms of simple, easy-to-use and good enough.
Use AT mode on the 8266 to cheaply and easily attach a micro-controller to the network.
Keep in mind that AT mode works without modifying the 8266’s firmware. This is great for WiFi-enabling existing devices. At roughly $3 per module (for the ESP8266-01 model) you can hook just about anything wirelessly to the net.
As a matter of fact, the default “AT mode” is nothing more than a small standard program, that is compiled into a binary file understood by the 8266’s Tensilica Xtensa LX3 processor. The binary is then uploaded, into the 8266’s long-term memory from the factory. Everybody calls that firmware.
When we code, compile and upload a program to the 8266, we’re just modding it’s firmware. Uploading your own firmware is what standalone mode is all about.
In “standalone mode” the 8266 is a WiFi-enabled micro-controller, programmed using the Arduino IDE or one of several other languages. You don’t need to use the AT commands at all. Unless you include them in your own program, the AT commands won’t even be recognized by the 8266 anymore. Remember that they are in the default firmware loaded from the factory. You can always restore the 8266 to “AT mode” by reloading the stock firmware. No big deal.
Use a standalone 8266 as a self-contained network-connect micro-controller, with your own custom software. Think of it as an Arduino with a built-in WiFi connection.
You’ll have to decide on your own “command set” or protocol to handle communications from the “micro-controller” functions like reading inputs, doing calculations and setting outputs, to the network. With a generous amount of program space on the 8266, there’s plenty of room for both functions. The Arduino IDE ESP8266 example programs spell out many of the ways you can set up communications on the chip.
Choose Your Job
The 8266 chips offer a lot of capability in a small, inexpensive package. Use it’s “AT mode” if you need to hook up an existing micro-controller, such as the Arduino, to the network. You won’t need to modify any of it’s firmware or write any code.
Use “standalone mode” if you need an inexpensive, self-contained micro-controller with wireless capabilities. The 8266 can read inputs, do calculations and set outputs just like an Arduino. It can also act as a WiFi access point, can connect to your local LAN or host pages on it’s own built-in Web server. You’ll cut and paste bits from the example programs or write your own code to do things.
You’ll certainly find lots of uses for the 8266.
Feature Image via Pixbay