Go Down

Topic: Robotdyn atmega328 uno r3 + Wifi. How to use it? (Read 2137 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)

CitrusGo

Hi

I am a "newbie" and I am stuck. I just purchased the Robodyn R3 Uno wifi. I can find sketches to put on the ESP8266 to connect to the internet and send numbers to Favoriot web page.  I can load scripts onto the ATMega328 to read a DHT11 temperature and humidity sensor.  I want to read sensors attached to the pins and then send out the data to the internet (e.g. favoriot or php page). I found a tutorial that loaded a sketch onto the ESP8266 that suppose to read a DHT11 and then send it out to favoriot, it did send numbers out out to favoriot, but it was unable to read the DHT11 sensor, it just read "0" (https://github.com/LintangWisesa/RobotDyn_UnoWiFi_Favoriot
).  I did set the dip switches to  1-2 On 3-7 Off to connect the ESP8266 to the ATmega328.

I understand you were able to communicate between the ATmega328 and the ESP8266.  I read there are two ways

(a) connect the RX and TX pins of the ATmega328 and the ESP8266 with jumper leads.

     1) I thought drop down resistors/module must be used between TX of ATmega328 to RX of  ESP8266
      to drop voltage from 5 to 3 v, is this correct?
      2) If I do what is in (1) I guess I can send AT commands to control the Wifi?
      3) If I do what is in (1) does any one know of sketches that can read a sensor from the ATmegae
     238 (e.g. DHT11) and then send the readout it to the ESP to eventually do a POST to a php page or
     favoriot?
(b) use code to communicate bewteen the ATmega328 and the ESP8266
    (1) is see in the code provided was able to send some data to the ESP8266, but then how to you then make is do a POST with this code?

Thank you

Juraj

Hi

I am a "newbie" and I am stuck. I just purchased the Robodyn R3 Uno wifi. I can find sketches to put on the ESP8266 to connect to the internet and send numbers to Favoriot web page.  I can load scripts onto the ATMega328 to read a DHT11 temperature and humidity sensor.  I want to read sensors attached to the pins and then send out the data to the internet (e.g. favoriot or php page). I found a tutorial that loaded a sketch onto the ESP8266 that suppose to read a DHT11 and then send it out to favoriot, it did send numbers out out to favoriot, but it was unable to read the DHT11 sensor, it just read "0" (https://github.com/LintangWisesa/RobotDyn_UnoWiFi_Favoriot
).  I did set the dip switches to  1-2 On 3-7 Off to connect the ESP8266 to the ATmega328.

I understand you were able to communicate between the ATmega328 and the ESP8266.  I read there are two ways

(a) connect the RX and TX pins of the ATmega328 and the ESP8266 with jumper leads.

     1) I thought drop down resistors/module must be used between TX of ATmega328 to RX of  ESP8266
      to drop voltage from 5 to 3 v, is this correct?
      2) If I do what is in (1) I guess I can send AT commands to control the Wifi?
      3) If I do what is in (1) does any one know of sketches that can read a sensor from the ATmegae
     238 (e.g. DHT11) and then send the readout it to the ESP to eventually do a POST to a php page or
     favoriot?
(b) use code to communicate bewteen the ATmega328 and the ESP8266
    (1) is see in the code provided was able to send some data to the ESP8266, but then how to you then make is do a POST with this code?

Thank you
the board has the MCUs wired together RX to TX with level conversion. use the DIP switches.
https://robotdyn.com/uno-wifi-r3-atmega328p-esp8266-32mb-flash-usb-ttl-ch340g-micro-usb.html#description
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.

CitrusGo

Thanks for your reply Juraj.

I first wish to review what I understand from previous posts, I am a learner so I need someone to review my interpretation of information - please correct me.  Then I have questions for I wish to send AT commands


------------------------------------------------------------------------------------------
My interpretation to be checked, I could be wrong;

There are two ways to connect the ATmega 328 to the ESP8266 on the Robodyn Uno WiFi R3.

A) ON BOARD SERIAL CONNECTION:
directly through the on-board serial connection by setting the dip switches 1 and 2 "on". You are able to see the transfer of data from Arduino on the serial monitor on your PC by additionally setting dip switches 3 and 4 "on"; or  see the transfer of data from ESP by additionally setting dip switches 5 and 6 "on". You can not set 3,4,5,6 on all at the same time; only 3,4 or 5,6.


To send a string from Atmega to ESP "root.printTo(Serial);" is used. An object "root" is made to hold the json object which holds the data in a type of array

 DynamicJsonBuffer jbuffer;
 JsonObject& root = jbuffer.createObject();
root["temperature"] = temperature; //

To send a string from Atmega or ESP to each other "  Serial.println(jsonString);" is used

and to listen and read a string on either end

while (Serial.available()){
   json=Serial.readString();
   StringReady = true;
  }


B) EXTERNAL RX TX WIRED CONNECTION
Connecting RX and TX pins of the ATmega328 and the ESP8266 with jumper leads. I also used a voltage divider when connecting the Tx pin of the AT328 to the Rx pin of the ESP because the ESP reads 3.3v and the Tx of the ATmega328 sends out a 5v signal, so best to reduce its voltage. I tested the divider and I read 3.16v.


End of review to be checked
------------------------------------------------------------------------

I wish to start with simple "hello world" communication to try method (A) and progress step by step. My next step in the next days will be to try and make a more simplified version of the Jogn Berd code and send back and forth set variables on a "delay" and see if I can watch it if it works.  If anyone has one already then please send it.

I did try (B) method using an external pin connections described in ; https://www.instructables.com/id/Arduino-Esp8266-Post-Data-to-Website/  . I did try the initial test and send the ATcommand "AT" through the serial monitor and did not get a response of "OK".  So I assumed it did not work.   My aim is to make a POST to a php page as described in tutorial link provided above or to a cloud data website (e.g. favoriot).

I think to achieve my goal I will firstly try and send AT commands directly from the ATmega to the ESP. I can follow and understand the example code of the POST, but I can not get the the AT commands to work either in method A or B.  I did put sketches onto the ESP and then put empty ones, so perhaps I accidentally erased a special sketch is already loaded onto the ESP to read AT commands, if so please advise me.  I also read that I might need to flash the ESP firmware ( https://community.blynk.cc/t/robotdyn-uno-wifi/14607/3 ). I did try different baud rates (9600, 57600, 115200).

I assume a POST can be made using the John Berd code and when ever the the ESP detects data via "while ( Serial.available()){"  it will then send it via extra POST code, but then it might become tricky to put the ESP to sleep and wake it up, perhaps it is better to have full control from the Atmega end?

Please provide some further mentoring and assistance.

ballscrewbob

@CitrusGo
Do not cross post.
The other topic has been removed.

It may not be the answer you were looking for but its the one I am giving based on either experience, educated guess, google or the fact that you gave nothing to go with in the first place so I used my wonky crystal ball.

Juraj

B) EXTERNAL RX TX WIRED CONNECTION
Connecting RX and TX pins of the ATmega328 and the ESP8266 with jumper leads. I also used a voltage divider when connecting the Tx pin of the AT328 to the Rx pin of the ESP because the ESP reads 3.3v and the Tx of the ATmega328 sends out a 5v signal, so best to reduce its voltage. I tested the divider and I read 3.16v.

this is useful only with SoftwareSerial in ATmega. so not RX/TX but SoftwareSerial pins (for example 6 and 7)
you can test without level conversion. the esp8266 can tolerate 5 V TTL serial communication.

on RX/TX it is the same as the on-board connection so wiring for nothing
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.

CitrusGo

Jurai

Thank you.  I managed to send some numbers back and forth by using the onboard RX/TX connection, but had a few hiccups and will put code for critique as soon as I iron out the minor issues.

I wish to also learn how to send AT commands from the Atmega328 to the ESP8266.  I was unable to do it a few days ago by typing in "AT" in the serial console.  Does there need to be a sketch in the ESP to accept the AT commands from the ATmega and then send the response back to the ATmega?  I read on tutorials I type in "AT" and I should get back "OK".

Juraj

did you try to upload a esp8266 sketch to esp8266? it would delete the AT firmware
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.

CitrusGo

Thank you for your response, your assistance is helping me a lot.

Yes I did upload a sketch to ESP and overwrote any sketches originally on the ESP8266. 

I can not find a forum post or tutorial that discusses a sketch to load onto the ESP to enable it to accept AT commands.  I have found posts that discusses flashing the ESP with firmware.  Do I have to flash the ESP with firmware again every time I load a different sketch on it to make it read AT commands again, or do I just upload a special "AT command" reading sketch on the ESP.  Please provide any links to what I have to do and the requires sketches?

Go Up