Robotdyn atmega328 uno r3 + Wifi. How to use it?

All is ok after a lot of searches I finally did it, I con now communicate in both directions between esp and arduino.

Code for ESP:

void checkInfoFromArduino()
{
bool StringReady;
String json;

while (Serial.available()){
json=Serial.readString();
StringReady = true;
}
infoAtm = json;
if (StringReady){
StaticJsonBuffer<200> jsonBuffer;
JsonObject& root = jsonBuffer.parseObject(json);
if(!root.success()) {
//Serial.println("parseObject() failed");
return ;
}
temperature = root["temperature"];
humidity = root["humidity"];
hygro[0] = root["hygro1"];
hygro[1] = root["hygro2"];
hygro[2] = root["hygro3"];
}
}

void sendInfoToArduino()
{
DynamicJsonBuffer jbuffer;
JsonObject& root = jbuffer.createObject();
root["humr"] = humidityRequired;
root["huma"] = humidityActivated;
root["hyr"] = hygroRequired;
root["hy1"] = hygroActivated[0];
root["hy2"] = hygroActivated[1];
root["hy3"] = hygroActivated[2];
root.printTo(Serial);
Serial.println();
}

Code for Arduino:

void sendInfoToESP()
{
DynamicJsonBuffer jbuffer;
JsonObject& root = jbuffer.createObject();
root["temperature"] = temperature;
root["humidity"] = humidity;
root["hygro1"] = hygro[0];
root["hygro2"] = hygro[1];
root["hygro3"] = hygro[2];
root.printTo(Serial);
Serial.println();
}

void checkInfoFromESP()
{
bool StringReady;
String jsonString ="";

if (!Serial.available())
return ;
while (Serial.available()){
jsonString =Serial.readString();
StringReady = true;
}
if (StringReady){
Serial.println(jsonString);
StaticJsonBuffer<200> jsonBuffer;
JsonObject& root = jsonBuffer.parseObject(jsonString);
if (!root.success()) {
Serial.println("Failed to parse config file");
return ;
}
humidityRequired = root["humr"];
humidityActivated = root["huma"];
hygroRequired = root["hyr"];
hygroActivated[0] = root["hy1"];
hygroActivated[1] = root["hy2"];
hygroActivated[2] = root["hy3"];
}
}

I am sending JSON objects to reed them by each others in TX and RX.

To communicate between Arduino and ESP you will need to activate deep switches 1 and 2.
To upload a sketch on ESP: 5, 6, 7.
To upload on Arduino: 3, 4.
Don't forget to change board options before uploading when switching.

To see what is transferred to ESP from Arduino: 1, 2, 3, 4.
To see what is transferred to Arduino from ESP: 1, 2, 5, 6.
(by opening serial terminal)

1 Like