Page 1 of 2

Unable to read serial/uart pins

PostPosted: Sat May 18, 2019 6:10 pm
by engineer-of-stuff
I am unable to read the serial pins in the NodeMCU Lua environment. I have only been able to read the USB serial port.

I have connected a serial adapter to the rx, tx, and g pins.

I have tried this code:
Code: Select alluart.on("data","\n",function(data) print("receive from uart:", data) end, 0)

I enter text in the ESplorer console and it does read that. It doesn't read anything I send over a serial adapter plugged into the rx/tx/g pins.

Code: Select alluart.write(0, "hello")

I disconnected the USB cable and powered it with the serial adapter. Nothing was sent using this code. I tried `uart.write(0,` and `uart.write(1,`.

How do I read the pin serial ports instead of the usb serial port?

Re: Unable to read serial/uart pins

PostPosted: Sun May 19, 2019 2:08 am
by schufti
that is one of the major problems of nodemcu boards.
Depending on the used usb-serial chip and the actual design you won't ever be able to use rx/tx because the chip will allways interfere (not be in standby or similar).
possible solution: remap usart to alternativ pins (gpio13/15).

Re: Unable to read serial/uart pins

PostPosted: Sun May 19, 2019 3:40 am
by Bonzo
I had a similar problem with a Nodemcu but using the Arduino IDE and ended up using the Serial.swap() function that worked. Some information on the serial here: http://arduino.esp8266.com/Arduino/vers ... rence.html

There is also the SoftwareSerial() function.

From memory it was only a problem when the USB was plugged in but that is not very useful for development!

Might be worth swapping from Lau to Arduino although you might loose some function that is Lau that is not in the Arduino IDE

Re: Unable to read serial/uart pins

PostPosted: Sun May 19, 2019 11:33 am
by engineer-of-stuff
Thanks for the help!

I'm not able to use Arduino because software serial interferes with wifi connection.

Can you explain serial swap? Lua has a similar function but I'm not sure why it's useful.