Skip to main content
3 of 3
Rollback to Revision 1

Receiving garbage value when sending a Json object from Arduino Uno to NodeMCU using SoftwareSerial

I am trying to send a Json Object from Arduino UNO to NodeMCU using SoftwareSerial. I am using Arduino IDE. I am getting garbage value on Serial monitor of NodeMCU. Tried it with different garbage values, couldn't receive data from Arduino UNO. Below is the code. PLease help. Thank you in advance. I haven't made a common ground. I have referred this webpage here.

Arduino UNO code:

    #include <SoftwareSerial.h>
    #include <ArduinoJson.h>
    SoftwareSerial s(5,6);
     
    void setup() {
    s.begin(9600);
    }

    void loop() {
     StaticJsonBuffer<1000> jsonBuffer;
     JsonObject& root = jsonBuffer.createObject();
      root["data1"] = 100;
      root["data2"] = 200;
      if(s.available()>0)
      {
       root.printTo(s);
      }
    }

NodeMCU code:

    #include <SoftwareSerial.h>
    SoftwareSerial s(D6,D5);
    #include <ArduinoJson.h>

    void setup() {
      // Initialize Serial port
      Serial.begin(9600);
      s.begin(9600);
      while (!Serial) continue;
     
    }

    void loop() {
      StaticJsonBuffer<1000> jsonBuffer;
      JsonObject& root = jsonBuffer.parseObject(s);
      if (root == JsonObject::invalid())
        return;

      Serial.println("JSON received and parsed");
      root.prettyPrintTo(Serial);
      Serial.print("Data 1 ");
      Serial.println("");
      int data1=root["data1"];
      Serial.print(data1);
      Serial.print("   Data 2 ");
      int data2=root["data2"];
      Serial.print(data2);
      Serial.println("");
      Serial.println("---------------------xxxxx--------------------");

    }