-->
Page 1 of 2

Nodemcu - Arduino code - UART read

PostPosted: Thu Nov 01, 2018 1:59 pm
by Bonzo
I have spent all afternoon trying to get serial UART working on a Nodemcu using the Arduino IDE without success and have two problems both interlinked. If I can’t select the correct pins how do I know if the code is working?

Which pins to use?
I have tried TX RX ( prevents uploads of code through USB unless I disconnect them, upload the code and reconnect ).
7 & 8 redirected with -Swap which allows the code to be uploaded
Other recommendations on the internet were 0+1 2+3

What code to use; I have tried quite a few examples but unless I know I have the correct pins I do not know if the code is working!

My sensor is outputting a base 64 string five times a second and it is truncated with a CR. I am not particularly worried about this at the moment as even if I receive some gobbledygook I would be happy and can deal with it in the next stage.

Please could somebody put me out of my misery and confirm which pins I should be using and it would be helpful if I also had the simplest of sketches I had confidence in to read the output and display it in the Arduino serial monitor.

Re: Nodemcu - Arduino code - UART read

PostPosted: Thu Nov 01, 2018 5:17 pm
by btidey
The NodeMCU has a USB to UART converter on board which is connected to the UART TX and RX lines.This allows easy download from the development environment.

This means you cannot use these TX / RX lines as they are already being driven by this on board hardware.

You can use SoftwareSerial which allows any pair of GPIO to be used as additional UARTS

See https://github.com/plerup/espsoftwareserial

Note the standard Arduino SoftwareSerial can't be used.

Re: Nodemcu - Arduino code - UART read

PostPosted: Thu Nov 01, 2018 5:39 pm
by Bonzo
Thanks for the info btidy and it confirms some of my conclusions.

I did try the EspSoftwareSerial onewiretest.ino example without success. I had better look into it as by that time I was getting very confused.

Re: Nodemcu - Arduino code - UART read

PostPosted: Fri Nov 02, 2018 3:59 am
by QuickFix
Bonzo wrote:My sensor is outputting a base 64 string five times a second and it is truncated with a CR.

If you only need to output serial data (TX only), you can use the debug serial port at GPIO2; you start it with Serial1.begin(baudrate) in your code and use it as usual. :idea: