Tuesday, April 28, 2015

Connect ESP8266 (WiFi module) to Arduino Due

Just to prove the connection between Arduino Due (TX3/RX3) and ESP8266 WiFi module, electrically and logically. Because both Arduino Due and ESP8266 work on 3.3V, so no voltage converter is needed.

ESP8266 GND - Due GND
ESP8266 VCC - Due 3.3V
ESP8266 TX - Due RX3
ESP8266 RX - Due TX3
ESP8266 CH_PD - Due pin 53 (always HIGH)

The test program on Arduino Due simple redirect the received data from RX to TX3, and from RX3 to TX. Such that we can use Serial Monitor of Arduino IDE (TX/RX) to send command to ESP8266 (TX3/RX3). It act as a USB-Serial cable functionally. Pin 53 always High, such that the ESP8266 always NOT Power Down.



int LED = 13;
boolean LEDst = false;

//always high
int CH_PD_8266 = 53;

void setup() {
  Serial.begin(9600);
  Serial3.begin(9600);
  pinMode(LED, OUTPUT);
  digitalWrite(LED, LEDst);
  pinMode(CH_PD_8266, OUTPUT);
  digitalWrite(CH_PD_8266, HIGH);
}

void loop() {
  while (Serial.available() > 0) {
    char a = Serial.read();
    Serial3.write(a);
  }
  
}

void serialEvent3() {
  while (Serial3.available() > 0) {
    char a = Serial3.read();
    Serial.write(a);
    ToggleLED();
  }
}

void ToggleLED(){
  digitalWrite(LED, LEDst = !LEDst);
}




Next:
- Arduino Due + ESP8266 - to Join AP

22 comments:

  1. Hello, this is great information, however I am stuck trying to get a response back from AT commands, I am also unsure how the function serialEvent3 is ever to run, is this correct that the function sits there with no calls to it in the example code?

    ReplyDelete
  2. Hello friend, You must change in serial monitor options to "NEW LINE" for sending command to ESP.

    ReplyDelete
  3. (help!) in my case apper this message:

    ]p
    D! +ÿ &hœL C R hz
    �’KÒ
    ۻ

    ReplyDelete
  4. Hello, I can't to sent AT or AT+RST. I open serial monitor before run code to auduino Mega 2560 it show "0 ]
    ; �D,ร… �I�B�� |zpมย &�’K๒*��". Help me please, I need to know IP esp8266.

    ReplyDelete
    Replies
    1. or: Open Serial Monitor - press on-board RESET button of Arduino.
      Make sure both Serial Monitor and Arduino set in same baud rate.

      Delete
    2. Some of the ESP8266 come set to 115200 baud rate as default. I got the same thing you did and changing serial monitor to 115200 and code to 115200 fixed it. Also had to set serial monitor option to " Both NL&CR"

      Delete
  5. why do I send AT commands + RST appear \: cc ¥ ÿ and not send AT commands to get more please help me

    ReplyDelete
    Replies
    1. try other baud rate. May be firmware of other version have different baudrate.

      Delete
  6. Hi,
    I am getting "exit status 1
    'Serial3' was not declared in this scope" while trying to Verify the code snippet.

    Can you please help?

    ReplyDelete
  7. Great Information. But In my case appear no response.

    ReplyDelete
  8. THE ARDUINO IS UNABLE TO SEND THE OMMANDS EVEN IF HANGED THE BAUD RATES

    ReplyDelete
  9. NOTHING IS HAPPENING BAUD ARE IS OK CONNECTIONS AE OK BUT NOTHING WORK PLEASE HELP ME

    ReplyDelete
  10. Hi,
    Can you please help me,
    i want connect multiple sensor output to arduino duo and transmit all sensor data to wifi using ESP8266 generic module,
    How can i do that,

    Thanks for advance

    ReplyDelete
  11. i get an error when input " AT+CWMODE". what happen?
    Thanks a lot

    Ready
    AT+GMR

    AT version:1.1.0.0(May 11 2016 18:09:56)
    SDK version:1.5.4(baaeaebb)
    Ai-Thinker Technology Co. Ltd.
    Jun 13 2016 11:29:20
    OK
    AT+CWMODE


    ERROR
    AT+CWMODE?+CWMODE


    ERROR
    AT+CIPSR


    ERROR

    ReplyDelete
  12. can you tell me ardiuno mega and Esp-12 which library is used for communication between them?

    ReplyDelete
    Replies
    1. In this post, the test program on Arduino Due simple redirect the received data from RX to TX3, and from RX3 to TX. Such that we can use Serial Monitor of Arduino IDE (TX/RX) to send command to ESP8266 (TX3/RX3). No any library needed.

      Delete
  13. i have been wasting my time for 2 fucking days and today i came to know that 74880 baud rate is the rate for ESP8266 and no other baud rate will work.

    ReplyDelete
  14. Hello! Thanks a lot for this post! It worked for me when I put serialEvent3(); inside loop instead of the while in there. But I'm still having trouble with connecting the module over the WiFi. I'm not sure if I need to do anything else. When I type the command AT+RST it shows all that stuff until "jump to run user1". After that the module starts printing unreadable stuff for every new command I type. Do you have any idea about what this could be?

    Thanks a lot for the post again!

    ReplyDelete