- Sat Nov 03, 2018 12:43 pm
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 https://forum.arduino.cc/index.php?topic=396450.0
Hope this helps.