Best I can figure the way to use the HDW serial capability for a serial display is via the serial.swap instruction. That redirects the console serial port to D7 & D8 where the display can be connected, but then the serial console is disabled.
The solution is to assign and redirect the second serial port to support the console This is supposedly done via "Serial1.begin(9600, SERIAL_8N1, SERIAL_FULL, 1)". Although the second serial port only supports Tx and not Rx, that should be satisfactory for the console port.
Unfortunately, it doesn't seem to work. I have Googled, but can't find a solution. Here is a link where I got the above serial.swap information.
Here's my code..The original console port works on D7 & D8, as expected, but nothing prints on the serial console. Any help is appreciated.
void setup() {
Serial.begin(9600);
Serial.swap(); // Serial string appears on line attached to 13(Rx2,D7) and 15(Tx2,D8)
delay(1000); // Wait for a second
Serial1.begin(9600, SERIAL_8N1, SERIAL_FULL, 1); // Set "Serial1" as debug, swap to GPIO1
Serial1.setDebugOutput(true);
}
void loop() {
Serial.println("test");
delay(1000);
}
This problem has driven me mad too! When I first used an ESP8266 I was about to give up as I wanted the serial port but it's not easily available, then I discovered Serial.swap(), so I can now use the serial port as I want to (still working on that one). That left me with no output to the serial monitor. In my case I have 2 ESP8266 boards with built in 128*32 OLED displays, so not too much of a problem, however it would be nice to be able to use both serial ports fully, and be able to use the serial monitor.
I've read, or possibly misread, the information on serial ports as per your link, and I cannot see where it says serial port 0 can be used to output to the serial monitor. Maybe it does say that and I didn't read it properly, or maybe you misread it! I hope it's me who's mistaken as I'd like to have this working too.
++Karma for finding a very useful page about the ESP8266
Finally, I also bought an MKR WiFi 1010 to give me the functionality that the ESP8266 alone lacks, although I've not done much with it yet.
My point was I wanted a complete serial port, Tx and Rx, available on an ESP8266, but couldn't get one until I discovered Serial.swap(). That is fine but leaves the serial monitor not working, unless someone can explain how to have it working and have Tx and Rx available for something else.
Don't even mention Software Serial!
Obviously I don't speak for Frank, but I though his question was close enough to what I'd been trying to do to make it worth adding my experiences.
Juraj:
why don't you simply use Serial1 as debug output? without any swapping
I guess I could do that but I would like to redirect serial1 to use the usb port to get the console data into my PC. Otherwise I need to use an rs232 to usb convertor to get the data into my PC.
This problem has driven me mad too! When I first used an ESP8266 I was about to give up as I wanted the serial port but it's not easily available, then I discovered Serial.swap(), so I can now use the serial port as I want to (still working on that one). That left me with no output to the serial monitor. In my case I have 2 ESP8266 boards with built in 128*32 OLED displays, so not too much of a problem, however it would be nice to be able to use both serial ports fully, and be able to use the serial monitor.
I've read, or possibly misread, the information on serial ports as per your link, and I cannot see where it says serial port 0 can be used to output to the serial monitor. Maybe it does say that and I didn't read it properly, or maybe you misread it! I hope it's me who's mistaken as I'd like to have this working too.
++Karma for finding a very useful page about the ESP8266
Finally, I also bought an MKR WiFi 1010 to give me the functionality that the ESP8266 alone lacks, although I've not done much with it yet.
Thanks for confirming that I'm not crazy and that this problem really exists. I thought for-sure that such a capable MCU like the Nodemcu would have decent serial capabilities. Looks like I thought wrong.
You are correct, no mention of Serial zero is mentioned in the link I posted. However, it says Serial1 uses Uart1 and "serial" uses uart0. Perhaps they should have said "serial0 instead of "serial". It also says that "serial" is mapped to GPIO1 and GPIO3, those are the ports normally used for the serial monitor. Those two ports are connected to the onboard USB facility. Hopefully, this long-winded paragraph answers your "serial port 0 to serial monitor" question.
PaulRB:
I used Serial1, in a recent project, to send commands from a Wemos Mini to a DFPlayer Mini. It wasn't hard at all. Simple as
void setup() {
Serial.begin(115200); // for serial monitor
Serial1.begin(9600); // for DFPlayer Mini
No need to use Serial.swap().
Maybe I'm missing the point of the question?
EDIT: Does this serial display require both Tx & Rx?
Yes, my serial display needs both Tx and Rx. Serial0 is the only port that has both Tx and Rx, but that port is used for the console data. While the console data can use Rx, typically only Tx is needed as I don't ever (yet) need to send data from my PC to the Nodemcu. Hence the desire to swap the console to serial1 to free serial0 for my serial display.
Ok, what you want now makes more sense to me. I was thinking the display would only need Tx, but if it's a touchscreen or has a button pad, it would need Rx too.
What display is this? Does it have any other connection types, such as i2c?
Juraj:
then combine the Serials. use TX of Serial1 and RX of Serial for a serial device. and Serial TX will write over USB to Serial Monitor.
you can create a wrapper Stream class which will hide that you use two serials
I'm kinda new at this C++ programing stuff, so I have no clue what a wrapper Stream class is or why i want to hide the serials.
Anyway I think I understand your first sentence, but I think the Rx of Serial is wired to the USB convertor that holds it high at idle. Trying to use it would cause an electrical conflict.
PaulRB:
Ok, what you want now makes more sense to me. I was thinking the display would only need Tx, but if it's a touchscreen or has a button pad, it would need Rx too.
What display is this? Does it have any other connection types, such as i2c?
It's a Nextion display that has a touch screen. It's new to me but I'm pretty sure it only has serial capability.
Nextion displays seem a lot easier to program than standard TFT displays since they have a PC tool that helps you develop screens. At least that's what it seems to me, although i know very little about either type of display.
I don't know how far you have got with it but you might have noticed my tutorial in the display's section of these fora, the one titled 'Using Nextion displays with Arduino'. I suggest you give it a try and I suggest you don't bother with the Nextion libraries.
One simple trick I have found with the ESP8266 specifically is write the code you think will send correct information to the Nextion but send it to the serial monitor instead. When you are satisfied that what is being sent is correct use Serial.swap() to send it to the correct pins for the Nextion.
I also suggest that you create a text box on the Nextion just for test data, which you can use for, well, test data to see what's happening in your program, instead of using the serial monitor.
PerryBebbington:
I don't know how far you have got with it but you might have noticed my tutorial in the display's section of these fora, the one titled 'Using Nextion displays with Arduino'. I suggest you give it a try and I suggest you don't bother with the Nextion libraries.
One simple trick I have found with the ESP8266 specifically is write the code you think will send correct information to the Nextion but send it to the serial monitor instead. When you are satisfied that what is being sent is correct use Serial.swap() to send it to the correct pins for the Nextion.
I also suggest that you create a text box on the Nextion just for test data, which you can use for, well, test data to see what's happening in your program, instead of using the serial monitor.
Thanks, I'll definitely check out your tutorial.
I already decided not to use the libraries, so it sounds like we are on the same track.
Quoting entire posts just makes the whole thread longer without adding any value to the discussion.
Usually it is obvious from the context what you are responding to. If there is a doubt, just quote a few key words of a post, or refer to someone by their forum name, for example "@PaulRB: why not quote entire posts?"