NodeMCU to NodeMCU serial I/O issue.

General discussions and questions abound development of code with MicroPython that is not hardware specific.
Target audience: MicroPython Users.
Post Reply
MMliam
Posts: 121
Joined: Mon May 07, 2018 1:08 pm

NodeMCU to NodeMCU serial I/O issue.

Post by MMliam » Tue Jul 19, 2022 2:43 pm

Remapped TxD0(GPIO1) to TxD2(GPOI15), and RxD0(GPIO3) to RxD2(GPIO13)
Swapped Tx & Rx line between Sender & Receiver
ledFlasher(arg) is a wait; flashes on/off 10 times; arg = on/off timing (secs)

UPDATE: Skip to the bottom, to the loop-back test that failed; no sense in going NodeMCU to NodeMCU if even the loop-back fails.


Relevant SENDER code:

Code: Select all

from machine import UART

uart=UART(0, 9600, tx=machine.Pin(15), rx=machine.Pin(13)) # Set to TxD2 & RxD2

uart.write('Hello/n/r') #Tried 'Hello/n', 'Hello/r/n'; no receive.

uart=UART(0, 115200, tx=machine.Pin(1), rx=machine.Pin(3)) # Return to TxD0 & RxD0
uart.write('\nwrite REPL is back')
print('\nprint REPL is back')
Presumably, the sender has sent Hello with terminators; it does return to REPL.

Relevant RECEIVER code:

Code: Select all

from machine import UART

uart=UART(0, 9600, tx=machine.Pin(15), rx=machine.Pin(13)) # Set to TxD2 & RxD2

msgRecv = None
while msgRecv == None:
#    if not uart.any()==0:
    msgRecv = uart.read() #Also tried 'uart.readline()
    ledFlasher(0.1)
ledFlasher(0.3)
The receiver never falls thru the while-loop; never receives any data.
What am I doing wrong?

Second, possibly related issue. Wiring the NodeMCU together affects the hardware boot on the NodeMCU; needs to be pressed several times before it finally boots-up. Disconnecting and they boot normally.

LOOP-BACK TEST:
Tried a code variation with a loop-back: jumpered TxD2 to RxD2 of one NodeMCU.

Code: Select all

from machine import UART

uart=UART(0, 9600, tx=machine.Pin(15), rx=machine.Pin(13), bits=8, parity=None, stop=1, timeout=5000) # Set to TxD2 & RxD2

srMsg = 'Hello/n'
uart.write(srMsg) #Tried 'Hello/n', 'Hello/r/n'; no receive.
srMsg = uart.readline()

uart=UART(0, 115200, tx=machine.Pin(1), rx=machine.Pin(3)) # Return to TxD0 & RxD0

uart.write('\nwrite REPL is back')
print('\nprint REPL is back')
print(srMsg)
REPL RESULT:
Trying TxD2 & RxD2

write REPL is back
print REPL is back
None
MicroPython v1.19.1-espnow-6-g44f65965b on 2022-07-09; ESP module with ESP8266
Type "help()" for more information.
>>> Hello/n
After re-mapping to REPL rsMsg prints "None", but after the REPL prompt it prints "Hello/n"?

tepalia02
Posts: 99
Joined: Mon Mar 21, 2022 5:13 am

Re: NodeMCU to NodeMCU serial I/O issue.

Post by tepalia02 » Wed Jul 20, 2022 3:27 am

Hi, have you tried the code without the remapping? If you just use TxD0 and RxD0, does your code work?

MMliam
Posts: 121
Joined: Mon May 07, 2018 1:08 pm

Re: NodeMCU to NodeMCU serial I/O issue.

Post by MMliam » Wed Jul 20, 2022 3:45 am

Coincidentally, I was just considering forgetting the mapping. However, I seem to remember reading about a conflict with REPL if the IDE is connected. I have a delay built into the software to allow an interruption and return to REPL. I'm going to try running from boot without the IDE, and see if I can at least get the loop-back to work.

Also, it would be great if I could use I2C, but from what I understand microPython lacks the structure to support an ESP device as a slave.

MMliam
Posts: 121
Joined: Mon May 07, 2018 1:08 pm

Re: NodeMCU to NodeMCU serial I/O issue.

Post by MMliam » Wed Jul 20, 2022 1:03 pm

tepalia02,

Here's what happens when I don't map the TxD0/RxD0 pins, but connect a loop-back.
I have the program initially go to a wait loop flashing the led for 10secs; this allows me to regain control thru Cntr-C, and return to REPL.
The program next initializes "uart" and tries uart.write, after the write it goes to uart.readline. If it receives it's own message [recvMsg not "None"] it flashes the LED fast.
Program Code:

Code: Select all

ledFlasher() # 10 second delay
print('\nFirst Flash Complete')

from machine import UART
uart = UART(0)
uart.write('Hello World\n')
recvMsg = uart.readline()
if not recvMsg == None:
    ledFlasher(0.1)
print(recvMsg)

With the loop-back jumper in place, here's the output[in part].
it apparently does receive it's own message as the LED flashes fast, but it doesn't print the message sent, and it keeps re-booting itself:
First Flash Complete
Hello World
b'3'

MicroPython v1.19.1-espnow-6-g44f65965b on 2022-07-09; ESP module with ESP8266
Type "help()" for more information.
>>>
>>> First Flash Complete
Traceback (most recent call last):
File "<stdin>", line 1
SyntaxError: invalid syntax
>>> Hello Worldb'3'
Traceback (most recent call last):
File "<stdin>", line 1
SyntaxError: invalid syntax
>>>
>>> MicroPython v1.19.1-espnow-6-g44f65965b on 2022-07-09; ESP module with ESP8266
Traceback (most recent call last):
File "<stdin>", line 1
SyntaxError: invalid syntax
>>> Type "help()" for more information.
Traceback (most recent call last):
File "<stdin>", line 1
SyntaxError: invalid syntax
>>> >>>
Traceback (most recent call last):
File "<stdin>", line 1
SyntaxError: invalid syntax
>>> >>> First Flash Complete
Traceback (most recent call last):
File "<stdin>", line 1
SyntaxError: invalid syntax
>>> Traceback (most recent call last):
Traceback (most recent call last):
File "<stdin>", line 1
SyntaxError: invalid syntax
>>> File "<stdin>", line 1
Traceback (most recent call last):
File "<stdin>", line 1
IndentationError: unexpected indent
>>> SyntaxError: invalid syntax
Traceback (most recent call last):
File "<stdin>", line 1
SyntaxError: invalid syntax
>>> >>> Hello Worldb'3'
As you can see REPL doesn't like the loop-back.

Post Reply