Over a million developers have joined DZone.

It's Time to Develop Applications for Cheap ESP8266 μC using Arduino IDE

· IoT Zone

Access the survey results 'State of Industrial Internet Application Development' to learn about latest challenges, trends and opportunities with Industrial IoT, brought to you in partnership with GE Digital.

ESP8266 is relatively new and cheap in price. It comes with an inbuilt firmware which supports serial interface and can be controlled using AT commands. Even though we can use this module to offload WiFi functionality from another micro controller or any other processor, this module is not just a serial to WiFi transceiver!
It is comprised of 
  1. 32bit 80MHz processor (Tensilica Xtensa LX3)
  2. 512KB SPI Flash (W25Q40BVNIG)
  3. RAM (64KB sram; 96KB dram)
  4. GPIO Pins
  5. WiFi tranceiver

That is fair enough to be a standalone WiFi supported μC. So we can burn our own programs onto this chip. At the moment we have 3 ways to program this module.
  1. Expressif GCC Based Toolchain (Documentation)
  2. NodeMCU Firmware (Supports Lua Scripting)
  3. Customized Arduino IDE for ESP8266
In this post, I am willing to discuss the 3rd option, how to use Arduino IDE to program ESP8266.


Software Configuration

There are already built packages under releases. Once it is downloaded and launched we have select the board and the programmer.
Tools -> Board -> Generic ESP8266 board


Tools -> Programmer -> esptool


Hardware Configuration

Now the hardware part. See below schematic for the configuration.
J1 should be connected with a USB to TTL adapter accordingly.
In order to burn Arduino sketch to the ESP8266 module S1 switch should be enabled. In other words GPIO_0 should be grounded when binaries are being uploaded to the chip.

Once it is done. Toggle power to the module and that's it! your program should be up and running on ESP8266!

For the demonstration purpose I have written a simple Arduino sketch to drive 2 LEDs using GPIO pins available on ESP8266 (ESP-01). LEDs are connected to GPIOs of the module with 220Ω resistors. See below schematic.


Arduino sketch

 
const byte GPIO_0 = 0;
const byte GPIO_2 = 2;

void setup() {
  Serial.begin(9600);
  pinMode(GPIO_0, OUTPUT);
  pinMode(GPIO_2, OUTPUT);
}

void loop() {
  blinkIt(GPIO_0);
  blinkIt(GPIO_2);
}

void blinkIt(byte pin){
  Serial.print("Blinking");  
  Serial.println(pin);
  
  digitalWrite(pin, HIGH);
  delay(300);
  digitalWrite(pin, LOW); 
  delay(1000);   
}


Result


The result would be similar to this.





Supported Arduino functions and libraries

As I mentioned earlier they have ported Arduino IDE to support ESP8266. But Arduino is basically based on AVR microcontrollers. So the people who ported Arduino IDE to support ESP8266 have rewritten lots of existing functionalists to support ESP8266. Due to that reason it doesn't support all the existing Arduino functions and modules. But it supports a lot! Let me list down things that work by the time of writing this post.



  1. Basic GPIO functions including interrupts
  2. Timing and delays
  3. Serial library
  4. WiFi shield library (ESP8266WiFi)
  5. Ticker
  6. EEPROM
  7. I2C(Wire Library) - only master mode supports at the moment
  8. SPI
  9. OneWire (with 3rd party support)
  10. mDns Responder[ESP8266mDNS] (new library)
And few other libraries. please find a complete updated list of supported libraries from their github project home.

Hope this may be helpful for you to start developments with ESP8266 with Arduino IDE.
References :
  1. ESP8266 Spec
  2. Cheap and Simple WiFi with ESP8266 for the FRDM Board
  3. HOW TO DIRECTLY PROGRAM AN INEXPENSIVE ESP8266 WIFI MODULE
  4. ESP8266 Github Wiki

The IoT Zone is brought to you in partnership with GE Digital.  Discover how IoT developers are using Predix to disrupt traditional industrial development models.

Topics:

Opinions expressed by DZone contributors are their own.

The best of DZone straight to your inbox.

SEE AN EXAMPLE
Please provide a valid email address.

Thanks for subscribing!

Awesome! Check your inbox to verify your email so you can start receiving the latest in tech news and resources.
Subscribe

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}