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')
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)
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)
After re-mapping to REPL rsMsg prints "None", but after the REPL prompt it prints "Hello/n"?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