Hello,
For people who managed to make a serial intereaction between an arduino and an ESP8266 :
I would need some help about an issue I have : for an unknow reason it seems that serial flow from arduino to ESP is stuck (while flow from ESP to arduino is working finely)
System description :
This is a very basic wiring between an arduino Mega and an ESP01 (the tiny version with 8 pins).
The ESP01 is acting as a network adapter and hold a simple webserver.
The arduino is managing a few sensors.
The arduino will also be able to switch relay according to plannings.
The system can be accessed (using http) to get the sensors state. (ESP01 side holding the server)
I need to do communication between arduino and Esp to do some synchronization (example : Arduino send the sensors values to Esp , and Esp send the current timestamp (for planning application)
In my test settings I have :
- An arduino Mega with Serial1 connected to Serial of ESP01 (RX -> TX , TX -> RX with a tension divider -i currently have no logical level converter to do the 5V -> 3.3V-)
- I'm using the Serial0 of Mega to monitor
Sketch (found on internet) :
void setup() {
// initialize both serial ports:
Serial.begin(9600);
Serial1.begin(9600);
}
void loop() {
// read from port 1, send to port 0:
if (Serial1.available()) {
int inByte = Serial1.read();
Serial.write(inByte);
}
// read from port 0, send to port 1:
if (Serial.available()) {
int inByte = Serial.read();
Serial1.println("TEST");
Serial1.write(inByte);
}
}
On the ESP side I have following code :
setup =>
self.uart = UART(0,9600)
self.uart.init(9600, bits=8, parity=None, stop=1)
loop =>
if self.uart.any():
LOG("Something incoming")
line = self.uart.readline()
if line is not None:
LOG("Received :")
LOG(line)
Note that I'm not using Arduino IDE to program ESP01, I do it standalone using the micropython firmware.
What is happening when I connect both devices.
If I log on Serial0 of Arduino, I'm correctly seeing everything I print (using print function) but cannot see any data I type (and should be sent to ESP) except when i do a CTRL-C, then all my data appears on the serial console :
Example below :
- "Loop" and number is a print done on ESP also as ESP+SYNC...
- I typed toto+EOL , then CTRL-C and see that "TEST" appear (see sketch) with each letter of "toto"
Loop
20400
Loop
20208
Refreshing ntp
ESP+SYNC+{ "epoch": 1608916455 }
Loop
19216
Loop
19024
Loop
18832
Traceback (most recent call last):
File "main.py", line 10, in
File "Core.py", line 166, in run
KeyboardInterrupt:
MicroPython v1.12 on 2019-12-20; ESP module with ESP8266
Type "help()" for more information.
TEST
Traceback (most recent call last):
File "", line 1, in
NameError: name 'TEST' isn't defined
tTEST
Traceback (most recent call last):
File "", line 1, in
NameError: name 'tTEST' isn't defined
oTEST
Traceback (most recent call last):
File "", line 1, in
NameError: name 'oTEST' isn't defined
tTEST
Traceback (most recent call last):
File "", line 1, in
NameError: name 'tTEST' isn't defined
oTEST
Traceback (most recent call last):
File "", line 1, in
NameError: name 'oTEST' isn't definedTEST
Traceback (most recent call last):
File "", line 1, in
NameError: name 'TEST' isn't defined
Do you know why apparently arduino is holding all serial data to send it in 1 packet only when i hit CTRL-C (or maybe esp is holding them ... i don't know)
Many thanks,
Olivier