8

I have an Arduino UNO and HUZZAH ESP8266 module. I need to send data between Arduino UNO and ESP module via Software Serial. Right now I have the ESP module write data and Arduino UNO display data, but not working. When I run the Arduino UNO and open its Serial Monitor, nothing is printed using below source code.

  1. ESP8266 RX PIN connected to Arduino UNO PIN 2.
  2. ESP8266 TX PIN connected to Arduino UNO PIN 3.
  3. Using the FTDI cable that came with HUZZAH ESP8266 to power this module. I just individually connected the RX and TX pins to the ARDUINO PIN 2 and 3 as mentioned above.

Any ideas what why not working? Below is code for both modules. Thanks,

Arduino UNO

#include <SoftwareSerial.h>

SoftwareSerial ESPserial(2, 3); // RX | TX

void setup(void){
  //Start hardware Serial communication
  Serial.begin(115200);

  //Start the software serial for communication with the ESP8266 component
  ESPserial.begin(57600);  

}


void loop(void){



if (ESPserial.available()){
  Serial.println("ESP available!!!");
  Serial.println(ESPserial.read());
}


}

HUZZAH ESP8266

#include <ESP8266WiFi.h>

#include <SoftwareSerial.h>

SoftwareSerial ESPserial(2, 3); // RX | TX

void setup(void){
  //Start the software serial for communication with the Arduino UNO component
  ESPserial.begin(57600);

  //TODO: setup Wifi
}


void loop(void){
   ESPserial.write("This message generated by ESP module.");
   delay(500);
}
4
  • What is the Arduino Pin 2 ?
    – Rrz0
    Commented Jan 6, 2018 at 20:22
  • RX on the Arduino should be connected to TX on the esp and vice versa, looks like you have RX connected to RX...
    – Ron Beyer
    Commented Jan 6, 2018 at 20:24
  • The Arduino pin 2 is digital.
    – Marquinio
    Commented Jan 6, 2018 at 20:24
  • @Marquinio yes but is it TX or RX?
    – Rrz0
    Commented Jan 6, 2018 at 20:26

3 Answers 3

4

Make sure that:

  1. RX pin on the Arduino UNO is connected to the TX pin on the ESP8266.
  2. TX pin on the Arduino UNO is connected to the RX pin on the ESP8266.
  3. Baud rate should be set to the same value from both the Arduino and ESP8266.

I don't know about your arduino but looking at this schematic, your RX and TX should be swapped.

enter image description here

2
  • This is a very common mistake which at first may not seem obvious.
    – John Smith
    Commented Jan 6, 2018 at 21:05
  • 3
    Yes this fixed my problem. The ESP now gets data which seems to be in bytes. I will try to figure out how to send/read readable strings, but thats another story. My electronics knowledge is very limited, thanks.
    – Marquinio
    Commented Jan 7, 2018 at 0:28
2

Adding to the above answer. UNO's TX is at 5V , while ESP8266 's RX is at 3.3V, as it is a 3.3V module. So its better to use a resistive divider to bring UNO' TX to 3.3V and then feed to ESP's RX, instead of directly connecting them eachother.

1
  • 1
    And conversely, the 3.3V TX pin of the ESP8266 is usually enough to drive the Uno's 5V RX pin.
    – linhartr22
    Commented Jan 12, 2018 at 2:21
0

//ESP

#include "SoftwareSerial.h"

SoftwareSerial ArduinoUno(D2,D3); //Rx, Tx

void setup() {

Serial.begin(9600);

ArduinoUno.begin(4800);

pinMode(D2, INPUT);

pinMode(D3, OUTPUT);

}

void loop() {

}

/******************************************************************************/

//UNO

#include "SoftwareSerial.h"

SoftwareSerial ArduinoUno(3,2); //Rx, Tx

void setup() {

Serial.begin(9600);

ArduinoUno.begin(4800);

}

void loop() {

  if(ArduinoUno.available() > 0){

    //float val = ArduinoUno.parseFloat();

    Serial.println(ArduinoUno.read());

  }

  delay(30);

}
1
  • format your code properly (CTRL+K)
    – MichaelT
    Commented Mar 2, 2019 at 11:24

Your Answer

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

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