0

I am able to send AT commands when connecting to the software through the TX/RX pins (1, 0) and the ESP01 communicates perfectly. However, as soon as I start doing that same thing with code I can't get the ESP01 to respond whatsoever. All I'm trying to do is get an OK back from the serial monitor. I changed the baudrate on the ESP01 as well as my serial monitor from 115200 to 9600, 19200 using this command:

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

Troubleshooting steps taken:

  1. Tried upping the voltage in case it wasn't getting enough current.
  2. Tried different ESP01s.
  3. Tried switching TX and RX pins.
  4. Tried using different pins on the Uno (2 and 3, 10 and 11, 7 and 8).
  5. tried changing myESP.println("AT"); to myESP.write("AT\n\r");.

Nothing works. I've done a ton of research and I haven't found anything wrong with what I'm doing, do you guys have any ideas?

#define TX 3
#define RX 2
String ssid = "*****";
String password = "******";
#include "SoftwareSerial.h"
SoftwareSerial myESP(RX,TX);
void setup() {
 pinMode(RX, INPUT);
 pinMode(TX, OUTPUT);
 myESP.begin(19200);
 Serial.begin(19200);
}
void loop() {
 myESP.println("AT");
 delay(5000);
}

Schematic is as follows: TX -> pin 3 RX -> pin 2 Vcc -> 3.3v GND -> Ground CH_PD -> Vcc

dda
1,5951 gold badge12 silver badges17 bronze badges
asked Jan 5, 2018 at 23:02

3 Answers 3

1

How about this:

void loop() {
 while(Serial.available() > 0) {
 myESP.write(Serial.read());
 }
 while(myESP.available() > 0) {
 Serial.write(myESP.read());
 }
}

That code will continue to load data to and from the software serial not just one byte. You can also use string concatenation:

String data = "";
while(Serial.available() > 0) {
 data += Serial.read();
}

Or arrays:

int data_max = 4096;
int data_size = 0;
char data[data_max];
while(Serial.available() > 0) {
 if(data_size < data_max) data[data_size++] = Serial.read();
}
answered Jan 6, 2018 at 21:44
1
  • Please explain in your answer how this solves the problem. That way future viewers know how to solve this issue and why it fixes the problem. Commented Jan 7, 2018 at 6:52
0

Alright so I figured out my issue. Here's the answer for anyone with this problem in the future.

  1. Remove pinMode(RX, INPUT); and pinMode(TX, OUTPUT);.
  2. SoftwareSerial isn't going to relay the response back, so you have to program a response in, that's why sending "AT" by itself to the serial port is pointless.
dda
1,5951 gold badge12 silver badges17 bronze badges
answered Jan 6, 2018 at 2:34
1
  • 1
    "SoftwareSerial isn't going to relay the response back"? Not clear what you were expecting, but @jdwolf's example of two while loops is the correct way to communicate from the Uno's terminal to an Uno-connected serial device. ESPs do indeed respond back and SoftwareSerial does collect that response for you. What do you mean by "you have to program a response in"? Commented Jun 7, 2018 at 11:25
-1

RX from Arduino goes to TX on EXP, and TX from Arduino goes to RX on ESP, BUT

Why not just put ESP01 in program mode and upload adruino code directly to it doing away with the AT commands

answered Jun 7, 2018 at 11:14

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.