user65860: 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--------------------");

    }


user61572: 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 < 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"));
  }
}


65860: <p>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 <a href="https://engineeringprojectshub.com/serial-communication-between-nodemcu-and-arduino" rel="nofollow noreferrer">here</a>.</p>

<p>Arduino UNO code:</p>

<pre><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);
      }
    }
</code></pre>

<p>NodeMCU code: </p>

<pre><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--------------------");

    }
</code></pre>
 61572: <p>The problem with ArduinoJson.h is that it doesn't ensure robust and reliable transfer over UART serial.</p>

<p>Instead, you should use <a href="https://github.com/PowerBroker2/SerialTransfer" rel="nofollow noreferrer">SerialTransfer.h</a> 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.</p>

<p>Here are the library's features:</p>

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

<p>Example TX Arduino Sketch:</p>

<pre><code>#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);
}
</code></pre>

<p>Example RX Arduino Sketch:</p>

<pre><code>#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"));
  }
}
</code></pre>
