5

I am trying to send AT commands to ESP8266. I re-flashed ESP8266 http://imgur.com/a/J8Ueh I followed this tutorial http://remotexy.com/en/help/esp8266-firmware-update/ and I hope it re-flashed successfully as there was no error.

When I uploaded this program http://www.pastebin.com/frhZY7tD I am trying to run AT command at 9600 baud rate on serial monitor then no response..

Below is how my circuit looks like

enter image description here

#include "SoftwareSerial.h"

SoftwareSerial esp8266(2, 3); // RX, TX

void setup()
{
  Serial.begin(9600); // serial port used for debugging
  esp8266.begin(9600);  // your ESP's baud rate might be different
}

void loop()
{
  if(esp8266.available())  // check if the ESP is sending a message
  {
    while(esp8266.available())
    {
      char c = esp8266.read();  // read the next character.

      Serial.write(c);  // writes data to the serial monitor
    }
  }

  if(Serial.available())
  {
    delay(10);  // wait to let all the input command in the serial buffer
    // read the input command in a string
    String cmd = "";
    while(Serial.available())
    {
      cmd += (char)Serial.read();
    }
    // send to the esp8266
    esp8266.println(cmd); 
  }
}

Trying to execute AT command -

enter image description here

On clicking on send button then it shows empty response like below -

enter image description here

When I unplug power wire and plug it back then it prints some garbled message on serial monitor. I checked voltage on RX also, it was around 3.5V that seems also OK.

enter image description here

I am facing this issue after I flashed WiFi firmware to ESP8266 then back AT firmware. It seems that AT firmware was not flashed successfully so I tried to erase everything using below command.

esptool.py --port /dev/ttyUSB0 erase_flash

C:\Users\williams>esptool.py --port COM4 -b 9600 erase_flash
esptool.py v1.3
Connecting...................

A fatal error occurred: Failed to connect to ESP8266: Timed out waiting for pack
et header

Before execute above command, I made changes in my circuit like below :-

enter image description here

Update

I have re-flashed ESP8266 on 115200 baud rate, and uploaded empty program then it started to respond AT commands. I connected as like above only change is TX to TX and RX to RX respectively. Alright!

AT


OK
AT


OK
AT+GMR

AT version:0.50.0.0(Sep 18 2015 20:55:38)
SDK version:1.4.0
compile time:Sep 18 2015 21:46:52
OK

Well, I want to send AT commands from the Arduino serial monitor window to ESP8266 and print ESP8266 response to the command. When I upload above program then it stops to respond, same result as like empty screen this is weird. Isn't ?

  • 2
    Comments are not for extended discussion; this conversation has been moved to chat. – Nick Gammon May 13 '17 at 8:11
  • 2
    Comments on the question are for clarifying the question - not answering it. If you have an answer please post it. – Nick Gammon May 13 '17 at 8:11
  • @Nick Why did someone move my reference to another post into chat? It does not make sense there, it's not an "answer" either. Also, if you were addressing me, I did not get a notification, but you did not use at notation anyway. – handle May 14 '17 at 8:07
  • 1
    It's not particularly easy to move only some comments into chat. You can repost that particular comment if you want. As I said, comments under questions or not intended to be a lengthy question/answer session – Nick Gammon May 18 '17 at 9:39
  • What everyone else said. The first thing I though of when looking at that output was "wrong baud rate". – PaulMurrayCbr May 30 '17 at 3:53
1

The ESP's AT firmware is probably configured for a higher baud rate, 115200 is typical. SoftwareSerial only works reliably up to 9600 baud. It can transmit "reliably enough" at 115200 for you to blindly send change-baud commands, though the ESP's response will probably be garbled. So you need to either: Reduce the ESP's baud rate or use the Uno's hardware serial port for the ESP, which means giving up the Uno's terminal output and makes it a pain to reconnect your PC each time you need to update the Uno's code. I've described the process of changing the ESP's baud-rate in more detail in this answer.

Update: I'm not familiar with various AT comand-interpreter revs; my ESPs are all running with the firmware rev came on them; "AT+GMR" (show version info) replies:

AT version:0.40.0.0(Aug  8 2015 14:45:58)
SDK version:1.3.0
Ai-Thinker Technology Co.,Ltd.
Build:1.3.0.2 Sep 11 2015 11:48:04


There is no AT+CIOBAUD command listed in my ESP8266 AT Instruction Set document rev 1.5.3). The only one listed that affects baud rate - and the one I use - is:

AT+UART_DEF=<baud>,<databits>,<stopbits>,<parity>,<flowcontrol>

, or:

AT+UART_DEF=9600,8,1,0,0

for 9600 baud, 8 bits, 1 stop-bit, no parity, no flow control. You probably know, but just in case, note that you will lose communication immediately after you change the ESP's baud rate, until you then change the local baud rate to match.

Update2:

This is program pastebin.com/dquCNYJj I am not sure what wrong I am doing

That code sets SoftwareSerial to 115200 baud; it can not run fast enough to receive data at that speed.

Update 3:

Since you've updated the ESP's firmware unsuccessfully, it's hard or impossible to know what's going on. The output in your screenshot looks rather like the result of a baud mismatch between the ESP and your terminal. You need to get a clean firmware update to the ESP before you can expect it to respond correctly and rely on its output to diagnose any other problems.

Update 4:

I'm not sure if we're talking about the same thing so please forgive me if you already know this; we might be talking about (at least) three different baud-rates:

  1. The rate in use during flashing of new firmware to the ESP;
  2. The default rate that new firmware will start listening at, whenever it is booted;
  3. The actual rate used at any given time between the ESP with its new firmware and the Arduino or some other device external to the ESP.

My own experience is with using the factory-installed AT Interpreter firmware. I have never needed to update it so I don't have personal experience with (1).

(2) and (3) are programmable by the Arduino. When I first use a new ESP (or after you've just re-flashed its AT Interpreter), it will listen at a factory-default baud rate (mine have all defaulted to 115200). There are commands to change the current rate (not saved across a reboot) and/or the default baud (saved for all future sessions).

I almost always change its default rate to 9600 to use it with an Arduino software serial port. This is my initialization for a new device, using an Arduino to talk to the ESP. (Don't transmit my '#...' comments):

# Start talking at the ESP's default rate (115200 on my factory-fresh ones).
AT+RST                         # Reset
AT+UART_DEF=9600,8,1,0,0       # Default baud to 9600,N,8,1,no flow ctl
# Here, change the Arduino's port to match: 9600 in this case.
AT+CWMODE=1                    # Station mode (client)
ATE0                           # Command echo off

From now on, the ESP will wake up listening at 9600 baud, in Station Mode as a client, with no command echo.

  • I tried to change baud rate, first in my program then build then upload then same baud rate on serial monitor. For example esp8266.begin(115200); then compile then upload it then 115200 on serial monitor then executed lot of commands AT+CIOBAUD=9600 then no response simply empty everytime. I repeated same process with 9600, 38400, 57600, 74880, 115200 and on sending any command on serial monitor, it does not give any response only empty everytime – N Sharma May 13 '17 at 14:32
  • can you suggest stable AT firmware for ESP8266 which runs on 9600 baud rate ? I think it is some issue with AT firmware, installed it like C:\Users\williams>esptool.py --port COM5 --baud 57600 write_flash 0 ai-thinker- 0.9.5.2.bin – N Sharma May 13 '17 at 14:39
  • I executed suggested command but in no response, empty response :( This is my ESP8266 flash settings imgur.com/a/scfty – N Sharma May 13 '17 at 20:10
  • This is program pastebin.com/dquCNYJj I am not sure what wrong I am doing – N Sharma May 13 '17 at 20:42
  • 1
    The rate during flashing isn't what's important here - the rates used by the Arduino and the ESP during communication is. They have to be made to match (if they don't already) when you run that firmware start a communication session with the Arduino. – JRobert May 17 '17 at 12:53
1

On your last picture, you should connect the Rx of your Arduino to the Tx of your ESP8266 and vice versa.

If you did that and it doesn't work, try to upload an example sketch in order to determine if it's the code or the connexions that are problematic. I recommend that you use the WiFiScan example, since that example doesn't require to change the code or to include other libraries othet than the ones from ESP8266Community.

  • SoftwareSerial esp8266(2, 3); // RX, TX - Doesn't this line manages own ? or Do I need to use RX/TX of Arduino ? – N Sharma May 19 '17 at 9:28
0

Is it possible that this is a hardware connection issue? According to the datasheet of the ESP8266, it states that the maximum voltage input is 3.6V, but by connecting directly to the Arduino, the signal output by Arduino would be more than 3.6V. (Around 5V output)

Table

Instead of connecting directly, you might want to perform Level shifting first? (5V to 3.3V, vice versa)

(Here's the link to the ESP8266 datasheet: https://nurdspace.nl/images/e/e0/ESP8266_Specifications_English.pdf)

  • I have 3.6V on RX of ESP8266, I checked with multimeter. I made using some resistors as well I tried with 2xAA batteries but same kinda of issue and provided around 3.6 V to ESP8266 but no luck. – N Sharma May 17 '17 at 6:26
  • Have you tried sending the AT Commands via a USB-UART adapter instead? – Photon May 17 '17 at 13:25
  • I tried to connect with using putty + USB-UART, it didn't work – N Sharma May 17 '17 at 17:00
0

First of all, Please check if you are giving proper voltage and current both to ESP8266. I've seen it not working if it doesn't get proper voltage and current.

Secondly, Connect your Rx,Tx of ESP8266 to Rx,Tx of Arduino respectively. Then, try doing one thing, just upload empty sketch having empty setup() and loop() function only.

Then, open serial monitor select your baud rate (mostly either 9600 or 115200) and you are all done! Sending "AT" via serial monitor input field will show you "OK" in serial monitor response window.

  • It worked as you suggested. It is working on 115200 baud rate. When I am running my program which is in question then it is not working. I connected my circuit as like in the question. Do you have an idea why it is so ? Isn't this program is to send commands to ESP8266 and read a response of ESP8266 and print it on Serial Monitor – N Sharma May 19 '17 at 7:20
  • I have updated my question, please check it – N Sharma May 19 '17 at 17:18
  • Ok.. let me understand! You said, It worked as you suggested. So, it worked on 9600 baud rate but not on 115200 baud rate? – Rahul Rastogi May 23 '17 at 9:13
  • It worked on 115200 baud rate, when I run empty program. When I follow steps which is in my question and on same baud rate then it does not work – N Sharma May 23 '17 at 9:32
0

Try this:

/*
  Software serial multple serial test

 Receives from the hardware serial, sends to software serial.
 Receives from software serial, sends to hardware serial.

 The circuit:
 * RX is digital pin 2 (connect to TX of other device)
 * TX is digital pin 3 (connect to RX of other device)

 Note:
 Not all pins on the Mega and Mega 2560 support change interrupts,
 so only the following can be used for RX:
 10, 11, 12, 13, 50, 51, 52, 53, 62, 63, 64, 65, 66, 67, 68, 69

 Not all pins on the Leonardo and Micro support change interrupts,
 so only the following can be used for RX:
 8, 9, 10, 11, 14 (MISO), 15 (SCK), 16 (MOSI).

 created back in the mists of time
 modified 25 May 2012
 by Tom Igoe
 based on Mikal Hart's example

 This example code is in the public domain.

 */
#include <SoftwareSerial.h>

SoftwareSerial mySerial(2, 3); // RX, TX

void setup() {
  // Open serial communications and wait for port to open:
  Serial.begin(115200);
  while (!Serial) {
    ; // wait for serial port to connect. Needed for native USB port only
  }


  // Serial.println("Goodnight moon!");

  // set the data rate for the SoftwareSerial port
  mySerial.begin(115200);
  // mySerial.println("Hello, world?");
}

void loop() { // run over and over
  if (mySerial.available()) {
    Serial.write(mySerial.read());
  }
  if (Serial.available()) {
    mySerial.write(Serial.read());
  }
}
  • 1
    Explain why this code solves the problem. – gre_gor Jan 22 '18 at 14:08

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.