Go Down

Topic: Robotdyn atmega328 uno r3 + Wifi. How to use it? (Read 119 times) previous topic - next topic

John_berd

Hello everyone!

I am searching for more than a week how to use this board. I know that I need to use the dip switch and I understand how to use it. I know how to upload a sketch to the board and how to upload a sketch to the esp8266 module. But I don't know how to make them communicate. I tried to control different pins from the esp module but it doesn't do nothing. I need to get information from my board to the esp and vice versa. I'm new here! Thanks for your help!

Juraj

it is the same as with esp-01 with an ordinal Uno. you can connect the Serials (with dip switches) or use SoftwareSerial. for SoftwareSerial you must wire a pair of pins of Uno to Serial of the esp8266 with jumper wires.

the RX and TX pins of the esp8266 are on the esp8266 header near the Uno pin 0. the pinout of the header is last in this diagram
https://robotdyn.com/pub/media/0G-00005215==UNO+WiFi-R3-AT328-ESP8266-CH340G/DOCS/PINOUT==0G-00005215==UNO+WiFi-R3-AT328-ESP8266-CH340G.pdf

the Mega+WiFi is a much better option with Serial3 connected to esp8266 with dip switches
You can't write an Arduino sketch if you didn't learn programming. Not the language, but the concepts of programming - algorithms and data types.

John_berd

Thanks for you answer.
So I prefer to use deep switches. If I well understand the next step is to have AT commands response but I don't. What may I precisely have to do? Do I need to reflash the ESP? What are next steps?

Juraj

Thanks for you answer.
So I prefer to use deep switches. If I well understand the next step is to have AT commands response but I don't. What may I precisely have to do? Do I need to reflash the ESP? What are next steps?
if you switch Serial to Serial you will disconnect the ATmega from USB. so no upload, no Serial Monitor.

the esp8266 had AT firmware on it. so it is still there if you didn't upload something else
You can't write an Arduino sketch if you didn't learn programming. Not the language, but the concepts of programming - algorithms and data types.

John_berd

I don't understand, they said to upload a sketch at the bottom of this page:

https://robotdyn.com/uno-wifi-r3-atmega328p-esp8266-32mb-flash-usb-ttl-ch340g-micro-usb.html

What I did. AT commands are not responding and the led of ESP is well blinking.

load 0x4010f000, len 1384, room 16
tail 8
chksum 0x2d
csum 0x2d
vbb28d4a3
~ld
AT+CIPMUX=1
AT+CIPSERVER=1,5000
AT+CIPSTO=3600

Are AT commands so importants for esp to Arduino communication or I can manage it by another way? if Yes, how can I do?

Juraj

I don't understand, they said to upload a sketch at the bottom of this page:

https://robotdyn.com/uno-wifi-r3-atmega328p-esp8266-32mb-flash-usb-ttl-ch340g-micro-usb.html

What I did. AT commands are not responding and the led of ESP is well blinking.

load 0x4010f000, len 1384, room 16
tail 8
chksum 0x2d
csum 0x2d
vbb28d4a3
~ld
AT+CIPMUX=1
AT+CIPSERVER=1,5000
AT+CIPSTO=3600

Are AT commands so importants for esp to Arduino communication or I can manage it by another way? if Yes, how can I do?

you do that the same way like everybody else with an esp-01 wired to Serial or SoftwarSerial of Uno. many possibilities. you can use some firmware in esp8266 and a corresponding library in ATmega or write your own sketch for esp8266 and exchange data and commands with the ATmega sketch. (and sketch for esp8266 and Firmata in ATmega is an exotic option)
You can't write an Arduino sketch if you didn't learn programming. Not the language, but the concepts of programming - algorithms and data types.

John_berd

#6
Jan 17, 2019, 02:44 pm Last Edit: Jan 17, 2019, 02:47 pm by John_berd
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)

Go Up