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 &lt;SoftwareSerial.h&gt;
    #include &lt;ArduinoJson.h&gt;
    SoftwareSerial s(5,6);

    void setup() {
    s.begin(9600);
    }

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


NodeMCU code: 

    #include &lt;SoftwareSerial.h&gt;
    SoftwareSerial s(D6,D5);
    #include &lt;ArduinoJson.h&gt;

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

    }

    void loop() {
      StaticJsonBuffer&lt;1000&gt; jsonBuffer;
      JsonObject&amp; 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--------------------");

    }
The problem with ArduinoJson.h is that it doesn't ensure robust and reliable transfer over UART serial.

Instead, you should use SerialTransfer.h to automatically packetize and parse your data for inter-Arduino communication without the headace.The library is installable through the Arduino IDE and includes many examples.

Here are the library's features:


  This library:
  
  
  can be downloaded via the Arduino IDE's Libraries Manager (search "SerialTransfer.h")
  works with "software-serial" libraries
  is non blocking
  uses packet delimiters
  uses consistent overhead byte stuffing
  uses CRC-8 (Polynomial 0x9B with lookup table)
  allows the use of dynamically sized packets (packets can have payload lengths anywhere from 1 to 254 bytes)
  can transfer bytes, ints, floats, and even structs!!
  


Example TX Arduino Sketch:

#include "SerialTransfer.h"

SerialTransfer myTransfer;

void setup()
{
  Serial.begin(115200);
  Serial1.begin(115200);
  myTransfer.begin(Serial1);
}

void loop()
{
  char buff[] = "hi";

  myTransfer.txObj(buff, sizeof(buff));
  myTransfer.sendData(sizeof(buff));
  delay(100);
}


Example RX Arduino Sketch:

#include "SerialTransfer.h"

SerialTransfer myTransfer;

void setup()
{
  Serial.begin(115200);
  Serial1.begin(115200);
  myTransfer.begin(Serial1);
}

void loop()
{
  if(myTransfer.available())
  {
    char buff[40];
    
    myTransfer.rxObj(buff, sizeof(buff));
    
    Serial.println("New Data: ");
    Serial.write(buff, sizeof(buff));
    Serial.println();
  }
  else if(myTransfer.status &lt; 0)
  {
    Serial.print("ERROR: ");

    if(myTransfer.status == -1)
      Serial.println(F("CRC_ERROR"));
    else if(myTransfer.status == -2)
      Serial.println(F("PAYLOAD_ERROR"));
    else if(myTransfer.status == -3)
      Serial.println(F("STOP_BYTE_ERROR"));
  }
}