I am having an odd issue. I am providing my codes but I believe the problem is in the wiring which I will explain in a second.
ESP8266 CODE:
#include <SoftwareSerial.h>
SoftwareSerial s(12,14);
#include <ArduinoJson.h>
void setup() {
s.begin(9600);
Serial.begin(9600);
}
void loop() {
StaticJsonBuffer<1000> jsonBuffer;
JsonObject& root = jsonBuffer.createObject();
root["data1"] = 100;
root["data2"] = 200;
Serial.println(s.available());
if(s.available()>0)
{
root.printTo(s);
}
delay(1000);
}
ARDUINO UNO CODE:
#include <SoftwareSerial.h>
#include <ArduinoJson.h>
SoftwareSerial s(5,6);
void setup() {
// Initialize Serial port
Serial.begin(9600);
s.begin(9600);
//while (!Serial) continue;
Serial.println("START");
}
void loop() {
StaticJsonBuffer<1000> jsonBuffer;
JsonObject& root = jsonBuffer.parseObject(s);
if (root == JsonObject::invalid()){
Serial.println("JSON invalid");
Serial.println(s.available());
return;
}
Serial.println("JSON received and parsed");
Serial.print("Data 1: ");
int data1=root["data1"];
Serial.println(data1);
Serial.print("Data 2: ");
int data2=root["data2"];
Serial.println(data2);
delay(1000);
}
So the serial monitor of Arduino Uno (after I plug in both arduino and esp8266) says that s.available() = 0. Therefore, it is not recieving JSON. The weird thing is, when i take out the cables from the pins in Arduino, put them in TX and RX pins and then put them back to pins 5 and 6 everything works. When I unplug the arduino and/or ESP and plug them back in the problem repeats- s.availalbe() = 0 (until I do that weird manouver with taking out the cables and putting them back in). I believe there is something I do not understand wiring-wise. I tried connecting them (esp and uno) to the common GND but it still does not work. Does anyone have any ideas what I might be missing here?
Thanks
PS, thats the setup: wiring pic
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…