Blank screen On The Serial Monitor

I’m trying to send a String from the ESP8266 TO an Arduino. The string is collected with a GET request and this works. BUT whenever I try to send this String to an Arduino over Serial, I get a blank screen.

This is the code for the ESP8266:

#include <ESP8266WiFi.h>;
#include <ESP8266HTTPClient.h>;
#include <SoftwareSerial.h>

HTTPClient http; 
SoftwareSerial NodeMCU(D7,D8);


const char* ssid = "dummy data";
const char* password = "dummy data";
 
void setup () {
   pinMode(D7,INPUT);
   pinMode(D8,OUTPUT);
   
   Serial.begin(9600);
   NodeMCU.begin(9600);
   
   WiFi.begin(ssid, password);
}




void sendDataToArduino() {
    
      http.begin("http://test.com/test/api/data/1"); 
      http.addHeader("Content-Type", "application/json"); 
      int httpCode = http.GET();
      String payload = http.getString(); //Get the request response payload
      NodeMCU.print("<"); 
      NodeMCU.println(payload); 
      NodeMCU.print(">"); 
      delay(1000);
    
}

 
void loop() {
 
    sendDataToArduino();
 
}

This is the code for the Arduino:

#include <ArduinoJson.h>
#include <SoftwareSerial.h>
SoftwareSerial ArduinoUno(2, 3); // RX | TX

const byte numChars = 94;
char receivedChars[numChars];
boolean newData = false;

void setup() {
  
  Serial.begin(9600);
  ArduinoUno.begin(9600);  

}


void recvWithStartEndMarkers() {
    static boolean recvInProgress = false;
    static byte ndx = 0;
    char startMarker = '<';
    char endMarker = '>';
    char rc;
 
    while (ArduinoUno.available() > 0 && newData == false) {
        rc = ArduinoUno.read();

        if (recvInProgress == true) {
            if (rc != endMarker) {
                receivedChars[ndx] = rc;
                ndx++;
                if (ndx >= numChars) {
                    ndx = numChars - 1;
                }
            }
            else {
                receivedChars[ndx] = '\0'; // terminate the string
                recvInProgress = false;
                ndx = 0;
                newData = true;
            }
        }

        else if (rc == startMarker) {
            recvInProgress = true;
        }
    }
}

void printData() {
    if (newData == true) {
        Serial.println(receivedChars);
        newData = false;
    }
}


void loop() {
    recvWithStartEndMarkers();
    printData();
    
}

I’m not sure why it won’t work. Sending data the other way around (from arduino to esp) did work.

NodeMCU.print("<"); 
      NodeMCU.println(payload); 
      NodeMCU.print(">");

is endmarker correct after println?

yes, i use the same functions to communicate from the arduino to the esp. That does work. But the other way around doesn't. No data at all in the Serial monitor

Did you cross Rx and tx ?

while (ArduinoUno.available() > 0 && newData == false) {
        rc = ArduinoUno.read();
        Serial.print(rc);  // add this to see what, if anything, is coming into the port
        if (recvInProgress == true) {

What is printed in the Uno serial monitor? Anything?

groundFungus:

while (ArduinoUno.available() > 0 && newData == false) {

rc = ArduinoUno.read();
        Serial.print(rc);  // add this to see what, if anything, is coming into the port
        if (recvInProgress == true) {




What is printed in the Uno serial monitor? Anything?

Nothing :frowning:

What do you get, from the ESP8266 code, when you print the payload that the GET request returns?

String payload = http.getString(); //Get the request response payload
Serial.println(payload):  // add a print to see what gets sent to the Uno ***************      
NodeMCU.print("<");

groundFungus:
What do you get, from the ESP8266 code, when you print the payload that the GET request returns?

String payload = http.getString(); //Get the request response payload

Serial.println(payload):  // add a print to see what gets sent to the Uno ***************     
NodeMCU.print("<");

This gives me a (json) String in the serial monitor, which is the data I want te send to the Arduino. Somehow it won’t transfer this data to my Arduino serial

Which ESP8266 board are you using?

Lolin nodemcu v3

(communication from the arduino TO the esp8266 does work, not sure how to send data back)

bidouilleelec:
Did you cross Rx and tx ?

Could you further explain what this is ?

JasperJP:
Could you further explain what this is ?

Connect :
TX ( ESP D8) to RX (Arduino pin 2)
RX ( ESP D7) to TX (Arduino pin 3)

Yes i already did that

I am trying to send a simple word FROM my esp8266 TO my Arduino.
I am not sure why this simple example doesn’t work.

These are my pin connections:

TX ( ESP D8) to RX (Arduino pin 2)
RX ( ESP D7) to TX (Arduino pin 3)

And yes I am using baud 9600 in the serial monitor.

Below you can find the code from my Arduino Mega en my NodeMcu ESP8266.

Arduino:

#include <SoftwareSerial.h>
SoftwareSerial Arduino(2,3); 

String txt;

void setup() {

  Serial.begin(9600);
  Arduino.begin(9600);  
}



void loop() {

   while (Arduino.available() > 0 ) {
        txt = Arduino.read();
        Serial.print(txt);
   }

}

ESP8266:

#include <ESP8266WiFi.h>;
#include <ESP8266HTTPClient.h>;
#include <SoftwareSerial.h>


SoftwareSerial NodeMCU(D7,D8);

 
void setup () {
   pinMode(D7,INPUT);
   pinMode(D8,OUTPUT);
   
   Serial.begin(9600);
   NodeMCU.begin(9600);
   
}


void loop() {
  
    NodeMCU.print("Hello"); 
 
}

Have a look at the examples in Serial Input Basics - simple reliable ways to receive data. There is also a parse example to illustrate how to extract numbers from the received text.

The technique in the 3rd example will be the most reliable. It is what I use for Arduino to Arduino and Arduino to PC communication.

You can send data in a compatible format with code like this (or the equivalent in any other programming language)

Serial.print('<'); // start marker
Serial.print(value1);
Serial.print(','); // comma separator
Serial.print(value2);
Serial.println('>'); // end marker

…R

More information on this issue in this post.

Why ise SoftSerial on the Mega when it has 3 extra hardware serial ports of its own ?

JasperJP:
I am trying to send a simple word FROM my esp8266 TO my Arduino.
I am not sure why this simple example doesn’t work.

These are my pin connections:

TX ( ESP D8) to RX (Arduino pin 2)
RX ( ESP D7) to TX (Arduino pin 3)

And yes I am using baud 9600 in the serial monitor.

Below you can find the code from my Arduino Mega en my NodeMcu ESP8266.

Arduino:

#include <SoftwareSerial.h>

SoftwareSerial Arduino(2,3);

String txt;

void setup() {

Serial.begin(9600);
 Arduino.begin(9600);  
}

void loop() {

while (Arduino.available() > 0 ) {
       txt = Arduino.read();
       Serial.print(txt);
  }

}




**ESP8266:**



#include <ESP8266WiFi.h>;
#include <ESP8266HTTPClient.h>;
#include <SoftwareSerial.h>

SoftwareSerial NodeMCU(D7,D8);

void setup () {
  pinMode(D7,INPUT);
  pinMode(D8,OUTPUT);
 
  Serial.begin(9600);
  NodeMCU.begin(9600);
 
}

void loop() {
 
   NodeMCU.print(“Hello”);

}

Why 2 threads for the same subject?

Robin2:
Have a look at the examples in Serial Input Basics - simple reliable ways to receive data. There is also a parse example to illustrate how to extract numbers from the received text.

The technique in the 3rd example will be the most reliable. It is what I use for Arduino to Arduino and Arduino to PC communication.

You can send data in a compatible format with code like this (or the equivalent in any other programming language)

Serial.print('<'); // start marker

Serial.print(value1);
Serial.print(’,’); // comma separator
Serial.print(value2);
Serial.println(’>’); // end marker




...R

Thank you but I have already made a project where I send data FROM my Arduino TO my ESP using seperators.

However in this project I try to send data the other way around (from ESP to Arduino). This does not work, even such a simple example. (The link that you sent doesn’t cover this)

I’ve been stuck for days :confused:

UKHeliBob:
Why ise SoftSerial on the Mega when it has 3 extra hardware serial ports of its own ?

I'm still learning about everything Arduino. How could a hardware serial port fix this problem ?