So you're a Noob? Post your questions here until you graduate! Don't be shy.

User avatar
By btidey
#78991 It sounded like OP wanted to receive serial data.

Note that even though normal TX is connected to internal USB converter you can use it as the test output for the second serial. So by coupling it to the SoftwareSerial RX then any Serial.print should get received by the SoftwareSerial UART. Of course you can just loop the software uart TX and RX but it just removes one variable from the equation while testing.
User avatar
By Bonzo
#78996 I Had another go this morning without success. A colleague confirmed the sensor is outputting data and it looked like the Nodemcu was sending some data back although I am not asking it to.

As btidy confirmed I only need to read as the sensor firmware is outputting the data continuously - I suppose I can disconnect the Nodemcu TX wire as it is not required.

I tried espSoftwareSerial along with Serial1 and seemed to have the most promising result with Serial.swap() and will have another go with that next week. The code I have is just reading one character so I will need to modify it to read a "line" which will be another challange.

Once I have some working code I will go back and try some of the other methods again.

Thank you for the input.
User avatar
By Good Science For You
Bonzo wrote: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.

I found that the NodeMCU 12 Esp 8266 works fine for both send and receive on the TX RX pins, without any switching of pins using code or "Softwareserial.h" . Here is what you need to do. If you only have one serial output to the other device then keep it simple and use the TX RX pins. The other pin (GPIO2) available is only TX so you cannot see what is happening on the serial monitor with responses. Unplug, upload. plug back in. Less than one second of "work".

If you are communicating with an Arduino or any of the 5V devices, use a logic level converter from 3.3 to 5V and make it so it plugs in or use dip switches so you can disconnect it in order to upload. I just put two six pin headers on to plug in (for use) and out while uploading. Once the code is uploaded you can both connect the logic level converter to the Arduino (or whatever you are using) and the serial monitor on the computer, because what the serial shows is what the arduino or whatever you are connected to is sending. Then you can see what the other device is sending to the ESP.

On the other device, if it is an arduino you can select different pins for TX RX and use them Mega has plenty.

What code variables are you sending? If you need to send instructions to make functions work, just use a "switch" and single chars sent to the switch. I found that trying to send multiple characters and such is too complicated and unnecessary. To get things to happen just keep it simple. If you send an "a" then this function(); happens. Send a "b", that(); function happens, or any single char and you can do massive multiple things. Serial.write('a'); keeps from sending confusing data. It only sends the "a" and nothing else. Serial.println('a'); sends two extra characters. line feed and carriage return. 13 and 10 ASCII.

I am new also to this ESP about one month of struggle, but because of my tenacity, electronics background, and need, I learn fast. One of the things that screwed me up was the baud rate between devices. Simple but deadly mistake. TX must go to RX of the other device. In my project now, I am running between three devices. The Mega gets information from the ESP (from wifi) and sends it to an UNO with pullup resistors and TTL (keep it simple) logic as needed.

If you need to send multiple characters and decipher them then there is a great tutorial
Hope this helps.
User avatar
By Bonzo
#79061 Thank you for the info Good Science.

I finally have something working; the main problem was an incompetent programmer - myself :oops:

I persuaded a experienced programmer to come over and take a look and my main problem was only reading one character; anyway that is now sorted.

I am using the Serial.swap() command but had some hiccups - at one point the swap was out of sinc and it was sending the data to the sensor and crashing it.

Put a delay after the swap - delay(100) seems to short and I am currently using delay(500)

Depending what you are doing before calling the swap you may need to put a delay before it as well. I was loosing a Serial.print()

Currently the sensor and serial monitor are both on the same baudrate

I can now send and receive the data over pins 7 & 8 to the sensor and power the project and see the serial output through the USB connector.