Sony Arouje

a programmer's log

Program ESP8266 with Arduino IDE

with 4 comments

Last couple of days I was trying to setup an ESP8266 module to program using Arduino environment. By Default ESP8266 bootloaded with AT Bootloader. Initially I connected ESP to Arduino and communicated using AT Mode via WiFiESP library.

The intention of my experiments is to add internet support in my Aeroponic controller. But AT mode deals with strings and thus increase the flash size, and when I added MQTT functionality with rest of Aeroponic sketch, I almost filled the flash size of Atmega328. So I decided to look for alternative options.

One of the beauty of ESP8266 is, it has it’s own flash memory. Also the integration with Arduino IDE. This way I can write Arduino sketch and embed it into ESP8266 instead of writing it to Atmega328.

Installing ESP8266 addon to Arduino IDE.

Sparkfun have a nice post about setting up the IDE. At the end of tutorial they choose ‘Sparkfun ESP8266 Thing’, instead I selected ‘Generic Esp8266 Module’, see the screen shot below.

 esp_arduino_ide

Hardware Connection

To write Arduino sketches to ESP we need a USB TTL module. Connect the module as below.

  • ESP8266-> USB TTL
  • GND-> GND
  • TX-> RX
  • RX-> TX
  • GPIO0-> GND

I powered the ESP module from an external source, ESPs are really power hungry, I am not sure whether the USB module can give the required current.

  • ESP8266-> External power
  • VCC-> 3.3v
  • CH_PD->3.3v

Make sure you have a  common GND, for ESP, External power and USB TTL. That means connect all GNDs together. If there is no common GND then expect the unexpected, IDE will keep throwing fatal exception.

Once the sketch is uploaded, connect GPIO0 to VCC, then switch off/on the ESP module. Now the ESP will start running the sketch.

Challenges

Keep getting wdt reset message as shown below. To test I added the blink demo with a serial write. This simple program works well until I add ‘ESP8266WiFi.h’, after this header file and uploading the sketch will start throwing the below in Serial monitor.

ets Jan 8 2013,rst cause:4, boot mode:(3,6)

wdt reset
load 0x4010f000, len 1384, room 16
tail 8
chksum 0x2d
csum 0x2d
v09f0c112
~ld

I tried a lot of options to resolve this issue. First I thought the module is not receiving enough current, so I powered it with 5v. This doesn’t make any difference.

In one of ESP forums some one suggest to erase flash using ESPTool, so I setup ESPTool and issued command like

python esptool.py p com6 erase_flash

This didn’t work out either. In another forum one person suggest to write blank.bin to 0x7E000, also mentioned that some times the reset can occur because of corrupted flash. This leads me to believe that corrupted flash causing the reset. So I decided to start all over again.

As an initial step I decided to boot with default AT bootloader. Here is a great post to follow.

While trying to bootload, esptool crashes always with ‘fatal exception’. I changed my USB Serial and tried again, this time all the bootloading steps works and configured the ESP back to AT mode. Then again I tried to burn the arduino sketch via Arduino IDE and it worked really well.

So I believe the wdt reset caused by, an issue with USB Serial module or corrupted flash. Now ESP8266 is working fine without any reset.

Advertisements

Written by Sony Arouje

November 7, 2016 at 11:40 pm

Posted in Arduino

Tagged with

4 Responses

Subscribe to comments with RSS.

  1. Hi.
    I am trying to use ESP8266 with Arduino UNO R3. But I can’t sent the AT command as I am getting loop of FatalException(0) as below as soon as I connect to ESP8266 module: (Can’t make out what does this mean)

    Fatal exception 0(IllegalInstructionCause):
    epc1=0x40201364, epc2=0x00000000, epc3=0x00000000, excvaddr=0x00000000, depc=0x00000000 ets
    Jan 8 2013,rst cause:2,
    boot mode:(3,6) load 0x40100000,
    len 1856,
    room 16 tail 0
    chksum 0x63
    load 0x3ffe8000,
    len 776,
    room 8 tail 0
    chksum 0x02
    load 0x3ffe8310,
    len 552,
    room 8 tail 0
    chksum 0x79
    csum 0x79
    2nd boot version : 1.5
    SPI Speed : 40MHz
    SPI Mode : DIO
    SPI Flash Size & Map: 8Mbit(512KB+512KB)
    jump to run
    user1 @ 1000

    Following are my ESP8266 connection details:
    1. Vcc – 3.3v external supply (GND connected to GND of 3.3v and GND of 5v of Arduino)
    2. CH_PD – 3.3v
    3. GPIO0 – Tried keeping 3.3v (Same Error)
    disconnected (Same Error)
    GND (Same Error)–(Just tried. I know this will be the programming mode)
    4. Rx – Rx of Arduino UNO via voltage divider
    5. Tx – Tx of Arduino
    (Tried with exchanging Rx and TX)
    6. RST – Disconnected (Same Error)
    3.3v (Same Error)
    (Used the GND pulse to reset the ESP8266)

    I also tried connecting RESET of Arduino UNO to GND with no success ;( .

    I checked the output with all the baud rates keeping “Both NL & CR” option selected. For baud rate 115200 I am getting the above exception. For rest it showing some garbage values.

    I have uploaded bareMinimum example in the Arduino UNO to start with.

    Any suggestion, pointer will be really appreciated.

    Is my module damaged? Never used it with anything other than 3.3v though.

    Thanks.

    Manisha

    March 30, 2017 at 7:24 am

    • what you mean by
      1. Vcc – 3.3v external supply (GND connected to GND of 3.3v and GND of 5v of Arduino)

      4. Rx – Rx of Arduino UNO via voltage divider
      5. Tx – Tx of Arduino
      Do you think it should be other way like Rx to Tx and Tx to Rx?

      Sony Arouje

      March 30, 2017 at 4:07 pm

      • 1. ESP8266 Vcc connected to external 3.3 volts through batteries n voltage regulator.
        All GNDs are looped together.

        2. I read somewhere the Signal which comes from the Arduino is also 5 v so used voltage divider (level shifter) using 10k and 20k ohm resistors. And signal after 10k given to Arduino.

        I tried both way..Tx-Tx and Rx-Rx and also Tx-Rx and Rx-Tx..

        But not seems to be working.

        Sorry for that English!

        Thanks for the reply.

        Manisha

        March 31, 2017 at 5:40 am

  2. Sorry!

    Signal from 10k ohm given to ESP n not Arduino.

    Manisha

    March 31, 2017 at 5:42 am


Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: