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--------------------");
}
I haven't made a common ground.
-- they maybe you should? majenko.co.uk/blog/importance-sharing-grounds – Majenko♦ Apr 26 '20 at 11:04