Hi guys,
I'm new here and I need help to understand and solve a little problem that maybe someone has already faced.
I'm creating a project with Arduino Mega + Esp8266 + Alexa and always when I turn on the board the Arduino Mega doesn't run while the wi-fi connection isn't connected. It's a problem because I found the Arduino MEGA to work regardless of the ESP8266 being connected to my wifi network.
YES I am using the serialprint to communicate the Esp8266 with MEGA below my code, if anyone can help me I will be grateful.
Just additional information, this code is using EspAlexa to do some commands. Esp8266
I don't see any connection between the Mega and the ESP.
Check out this project for an example of talking between arduino boards Arduino to Arduino via Serial
whenever Esp8266 writes something to the serial Arduino reads and executes. The problem is that whenever the connection is lost, the button's function doesn't work until the wifi connection comes back, and the intention is that if the wifi connection fails, the button works normally.
The serialprint from side Esp only will print "a" or "b" if I request to Alexa.
Ok in that case I would suggest you send a 'connected' 'disconnected' message to indicate to Mega the state of the WiFi.
You could shorten those to 'c' and 'd' and just extend the one char parser you have at the moment.
Hello again, just justifying that the problem does not occur because of the character that is available in Esp8266, but in waiting for the Arduino to execute the rest of the code since if that part of the code is not available, first Mega wait the serial is avaliable and after run.
Imagine if you had an LED connected and suddenly the wifi connection dropped, right away you would need to use the button to turn the LED on or off but the LED turns off and does not allow control by the button until the wi-fi connection returns. The question is why does Arduino Mega need to wait the wi-fi conexion returno to run again?
I guess it should be ignored and go back so the button can take over while the serial isn't available yet. Or am I wrong? Because if I just run the Mega without ESP8266 connection this code starts fast. I would just like to keep my button running the rest of the code in MEGA in case my Wi-Fi connection got lost.
Hello drmpf,
Thanks again for your reply. I made some test with your suggestion and the problem continue, I tested with the follow code on Arduino without read the serial monitor and when the pin from Mega is seted to connect to ESP exist a time that Mega needs to wait after run, probably Mega is waiting some conection from ESP or receive some confirmation that ESP system is Ok, but I don't know why.
I did it:
Try these sketches ESP8266_connect_disconnect.ino (2.3 KB) Mega_Serial1_Monitor.ino (476 Bytes) Uno_SoftwareSerial_Monitor.ino (589 Bytes)
and the circuit below.
The ESP8266 code ouputs + for connect and - for disconnect and has a timer that tests the disconnect every now and again.
The Mega Sketch just loops through to the UNO and the UNO loops through to the Arduino IDE monitor so you can do some debugging.
To prevent short circuits if an output is wired to an output and one side is driven high while the other side is driven low.
Typically the problem is connecting TX to TX instead of TX<->RX
Both leads have the 1K because one is to protect the TX of the mega and one is to protect the TX of the UNO.
If you check the UNO circuit you will see similar resistors leading to the D0 and D1 pins