Home › Forums › Mayfly Data Logger › ESP8266
- This topic has 5 replies, 2 voices, and was last updated 2019-02-15 at 6:46 PM by Sara Damiano.
-
AuthorPosts
-
-
2019-02-13 at 6:55 PM #12783
Has anyone successfully connected an ESP8266 to the Mayfly? Just looking for some direction.
My end goal is to have an xBee to wifi gateway. If I can get it to work, I’ll connect the ESP to TX0/RX0 and have the xBee in the socket. Right now, I’m trying to connect an ESP8266 ESP-01 to the TX1/RX1 pins. Do the TX1/RX1 pins transmit at 3.3V? I can provide more information as to how I’ve got things connected and the code I’m trying to test.
Thank you in advance.
-
2019-02-14 at 7:26 AM #12785
All of the Mayfly pins are at 3.3V.
I’ve done a decent amount with a Mayfly and an ESP8266 using the “AT” firmware on the ESP8266. I haven’t had any problems with it.
-
2019-02-15 at 3:07 PM #12789
Sara, thank you for your response. I’m glad to hear it is possible. Here’s what I’ve got thus far.
Mayfly <—-> ESP8266 ESP-01
Rx1 <——-> Tx
Tx1 <——-> Rx
Gnd <——-> Gnd
Sw3 <——-> VCC & CH_PD12345678910111213141516171819202122232425262728293031323334353637383940414243444546// https://allaboutee.com/2014/12/27/esp8266-arduino-code-and-circuit/void setup(){Serial.begin(9600);Serial1.begin(115200); // your esp's baud rate might be differentpinMode(22, OUTPUT); // TURN SW_3 TO 3.3V https://www.envirodiy.org/topic/hcsr04-sw5/digitalWrite(22, HIGH); // TURN SW_3 TO 3.3V https://www.envirodiy.org/topic/hcsr04-sw5///Serial.print("Here we go...");}void loop(){//Serial.println("hello");if(Serial1.available()) // check if the esp is sending a message{while(Serial1.available()){// The esp has data so display its output to the serial windowchar c = Serial1.read(); // read the next character.Serial.write(c);}}if(Serial.available()){// the following delay is required because otherwise the arduino will read the first letter of the command but not the rest// In other words without the delay if you use AT+RST, for example, the Arduino will read the letter A send it, then read the rest and send it// but we want to send everything at the same time.//Serial.println("Serial.available");delay(1000);String command="";while(Serial.available()) // read the command character by character{// read one charactercommand+=(char)Serial.read();}Serial.print("Command sent to ESP= ");Serial.println(command);Serial1.println(command); // send the read character to the esp8266}}I attached a screenshot of the Serial Monitor with the results I get back from the ESP when I send AT commands to it. Do I have a baud rate issue?
To test if the ESP was working, I connected it to an Arduino UNO via an Aideepen Adapter Module. The ESP worked and the responses were as they should be.
I’ll continue to play around with my setup and see if I can figure it out. Any insight would be greatly appreciated.
Update:
The second image attached is the Serial Monitor when I changed the code to Serial1.begin(74880);Attachments:
-
2019-02-15 at 5:23 PM #12794
SOLUTION:
I changed the default baud rate on the ESP8266 from 115200 to 9600 and things started working. The AT command I used was AT+UART_DEF=9600,8,1,0,0
Here is where I found this command:
https://arduino.stackexchange.com/questions/24156/how-to-change-baudrate-of-esp8266-12e-permanentlyJust curious why the ESP8266 wasn’t working at 115200? Does the Mayfly not support this baud rate?
-
2019-02-15 at 6:35 PM #12795
Yes, I’ve had problems with the Mayfly receiving data at 115200. The Mayfly is only running at 8MHz and Atmel says the error rate at that baud and crystal combination is 8.5%. The error is a much bigger problem on the receiving end than the sending end. So the serial port monitor and the ESP8266 understand what the Mayfly is saying at 115200, but the Mayfly has a hard time hearing back from the esp at that speed. And it gets especially bad when running a program like yours that’s trying to synchronously write and read from both serial ports at the same time. So when the Mayfly said “AT” to the ESP8266, the esp actually echoed “AT” and then said “OK” but the Mayfly misheard and it got garbled into that “au?” (AT) and “C?j5” (OK). After AT+RST you’ll always see some junk because the ESP8266 prints out some notes when it boots at a different baud rate than it’s normal talk speed.
So.. in short:
– If you just want to talk to the ESP8266 and don’t care about what it says back, you’re fine doing just as you are– If you want to talk to the ESP and can handle listening to it in your program without simultaneously printing it to Serial, you’re probably also alright, but somethings might be garbled
– If you want to talk to the ESP and echo its responses and make sure they’re always correct, you need to slow the ESP down.
To change the baud rate of the ESP8266: (for 9600, 8N1)
“AT+UART_DEF=9600,8,1,0,0” -
2019-02-15 at 6:46 PM #12796
Oops. Sorry. I’d typed that and didn’t see your response. But yes, slowing down the ESP8266 is the way to go if you want to make sure everything is heard correctly.
-
-
AuthorPosts
- You must be logged in to reply to this topic.