3

What I want to achieve

I want to connect to my wifi network using Arduino UNO and ESP8266 using WiFiEsp.h library over `SofwareSerial, since UNO doesn't have additional H/W serial.

What I am able to do already

I have a Mega, which I am able to connect to my wifi network(using ESP8266) using its hardware serial (RX1 and TX1), I've been following up this code example. Though it has code to deal with both cases( when H/W serial is present and when it's not) It doesn't seems to work on Software Serial on UNO, works perfectly on MEGA's H/W serial. I have made a little change in code as to set the Serial1 baudrate to 115200 as this seems to be supported by my ESP's firmware (1.54)

ERROR

[WiFiEsp] Initializing ESP module [WiFiEsp] >>> TIMEOUT >>> [WiFiEsp] >>> TIMEOUT >>> [WiFiEsp] >>> TIMEOUT >>> [WiFiEsp] >>> TIMEOUT >>> [WiFiEsp] >>> TIMEOUT >>> [WiFiEsp] Cannot initialize ESP module

What I've tried

  1. Tried running Software Serial on MEGA on pins 10,11 and 6,7 (Rx,Tx) (Same Error).
  2. Swapping Rx,Tx :P
  3. Changing pins to 10,11 instead of 6,7 on UNO
  4. Switching Baudrate to 9600 on UNO (no help)

Yeah, Not much, but it seems so straight forward I can't figure out what could go wrong. It seems like it can't communicate to ESP, but why?

  • Yes it looks like you can't talk to the ESP over Software Serial. I have seen that sort of think mentioned on here a few times. Have you tried hooking the ESP direct to your PC and see if you can read what it is saying. You baud rate of the ESP looks like 9600, even though the default is 115200. – Code Gorilla Mar 29 '17 at 12:10
  • 115200 is too fast for the uno/mega software serial. 9600 can be a problem. 57600 is usually stable. Make sure both ends use the same baud, It has to be rx>tx, tx>rx. Post the code from each. – Visual Micro Mar 29 '17 at 15:47
5

If you're going to talk to your ESP at 9600 baud - and that's about the upper limit for SoftwareSerial - you need to first change the ESP board's baud rate to 9600 baud. It is probably at 115200 right now.

You can do that with either kind of serial. Even though SoftwareSerial can't receive at 115200, it can usually transmit (Uno -> ESP) that fast. You need to send it the command:

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

If you do it with SoftwareSerial, the reply coming back from the ESP after changing its baud will be garbled because your serial terminal will still be listening at the faster speed. So at this point, change the speed of your terminal and send the command:

AT

The ESP should respond with

OK

If it does - and it probably will - you're all set and can continue using it at 9600 baud. If not, go back to 115200 baud on your serial terminal and try it again. (I've never had to do it twice).

Update:

I tried sending AT commands @ 115200, Its actually sending and receiving back well at 115200. Is this normal ?

With hardware serial, yes. The Uno's hardware UART can probably go at up to 4x that! But I've never had any luck receiving with SoftwareSerial at 115200; the most I could count on was 9600.

  • I liked your solution very much, before applying it I tried sending AT commands @ 115200, Its actually sending and receiving back well at 115200. Is this normal ? – Salim Shamim Mar 30 '17 at 12:23
  • i had a similar problem, followed the solution mention, changed the pin to 10,11 did the trick :) – Riaz Laskar Jul 1 '18 at 20:49

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.