Shop OBEX P1 Docs P2 Docs Learn Events
Serial Communication Between WX-ESP8266 Module and Arduino Nano — Parallax Forums

Serial Communication Between WX-ESP8266 Module and Arduino Nano

Hey all,

I'm currently working on a project that involves the use of a WX ESP8266 with an Arduino Nano. Currently I'm unable to read the data being sent by the Wifi module to the Arduino. Both the Arduino and the WX ESP8266 have a baud rate of 115200. The data we are getting is garbage. Are there any tutorials for using the WX-ESP8266 Wifi module with Arduino Nano? (AVR specifically, not PropC).

Thanks in advance!

Comments

  • Here is some sample code that works on my Bufferfly board. It has 3 serial devices which it seems the Nano does not. So I assume you are using soft serial to communicate with the WX WiFi module.

    On the web page for the WX WiFi make sure under settings that "Serial Commands (aka CMD):" is enabled and saved to flash.

    Then the following Arduino code should work except since you only have one serial device you will have to use soft serial for Serial1.
    #include <Arduino.h>
    #include <Wire.h>
    
    
    // WiFi Commands
    
    #define JOIN    0xEF
    #define CONNECT 0xE4
    #define CLOSE   0xE8
    #define LISTEN  0xE7
    #define REPLY   0xE5
    #define POLL    0xEC
    #define RECV    0xE9
    #define SEND    0xEA
    #define CHECK   0xEE
    #define SET     0xED
    #define CMD     0xFE
    
    char Buffer[1024];
    int Pos;
    char Status;
    
    void WXCheck(char *Environment)
    {
      Serial1.write(CMD);
      Serial1.write(CHECK);
      Serial1.print(Environment);
      Serial1.write('\r');
    
      delay(1000);
      Pos = 0;
      while (Serial1.available() > 0)
      {
        Buffer[Pos++] = Serial1.read();
        Buffer[Pos] = 0;
      }
    
      Status = ' ';
      if (Buffer[0] == CMD)
      {
        Status = Buffer[2];
      }
    }
    
    void setup() {
      delay(5000);
      
      Serial.begin(115200);
      Serial1.begin(115200);
    
      Serial.println("Starting");
      
      WXCheck("version");
    
      Serial.print("Status: ");
      Serial.println(Status);
      Serial.print("Version: ");
      Serial.println(&Buffer[4]);
    }
    
    void loop() {
      // put your main code here, to run repeatedly:
    
    }
    

    This should return the version number of your WX WiFi board as seen on the home page.

    Mike
  • iseries wrote: »
    Here is some sample code that works on my Bufferfly board. It has 3 serial devices which it seems the Nano does not. So I assume you are using soft serial to communicate with the WX WiFi module.

    On the web page for the WX WiFi make sure under settings that "Serial Commands (aka CMD):" is enabled and saved to flash.

    Then the following Arduino code should work except since you only have one serial device you will have to use soft serial for Serial1.
    #include <Arduino.h>
    #include <Wire.h>
    
    
    // WiFi Commands
    
    #define JOIN    0xEF
    #define CONNECT 0xE4
    #define CLOSE   0xE8
    #define LISTEN  0xE7
    #define REPLY   0xE5
    #define POLL    0xEC
    #define RECV    0xE9
    #define SEND    0xEA
    #define CHECK   0xEE
    #define SET     0xED
    #define CMD     0xFE
    
    char Buffer[1024];
    int Pos;
    char Status;
    
    void WXCheck(char *Environment)
    {
      Serial1.write(CMD);
      Serial1.write(CHECK);
      Serial1.print(Environment);
      Serial1.write('\r');
    
      delay(1000);
      Pos = 0;
      while (Serial1.available() > 0)
      {
        Buffer[Pos++] = Serial1.read();
        Buffer[Pos] = 0;
      }
    
      Status = ' ';
      if (Buffer[0] == CMD)
      {
        Status = Buffer[2];
      }
    }
    
    void setup() {
      delay(5000);
      
      Serial.begin(115200);
      Serial1.begin(115200);
    
      Serial.println("Starting");
      
      WXCheck("version");
    
      Serial.print("Status: ");
      Serial.println(Status);
      Serial.print("Version: ");
      Serial.println(&Buffer[4]);
    }
    
    void loop() {
      // put your main code here, to run repeatedly:
    
    }
    

    This should return the version number of your WX WiFi board as seen on the home page.

    Mike

    Hi Mike,

    Thanks a lot, this worked like a charm.
Sign In or Register to comment.