Why is software serial so frowned upon?

Hey all...

I am using an ESP32, but it only has 2x available hardware serial ports.
I am talking to a Nextion touch-screen using a software serial link and it seems to work fine.

I was wondering why it is so frowned upon (or at least appears to be)?
This SEEMS to be working absolutely fine.
I imagine a touchscreen isn't timing critical and the Nextion does most of the hard work anyway (it hosts all the graphics).

Just wondered

Because people copy programs that use it, even though the chosen Arduino board has serial connections not being used. Also the software serial has limited speed. It will also have errors if the interrupts is uses are being use by other parts of the program.

4 Likes

Oh I totally understand the 'why would you do that' if you had spare Hardware serial ports...

Ideally, I would run this screen on a hardware serial, but I just don't have enough.

Is there an ESP32 (or variant) with 3 user available serial ports? Never looked...

The ESP32 itself has 3 'available' serial ports. One of them is used for program upload, but can be used for other stuff if you want.

Yes, I did think about using serial0.
I lose my 'debugging' ability but it would be nice to get rid of the software serial. Plus, a pain to have to keep disconnecting the screen while uploading and editing code.

Maybe a simple 'programming' switch on the PCB to switch serial lines

You probably only need to worry about a conflict on the TXPIN.

I added a GPS to a ESP32CAM, which is very short of available pins. So I used the program upload Serial port for the GPS and disabled the GPS TX pin during program upload with a switch. No big deal.

1 Like

Software Serial at 115200 on an Uno. Nyet.

Software serial incoming data at any realistic baud rate for display on 300 Neopixels on an Uno. Ummm, maybe not.

Thats well known, to me at least.

Using software serial on its own, no other interrupt stuff in the background works well enough.

But have software serial running in the background, with other program stuff running, SPI or Serial for instance and expecting received characters to be buffered correctly is where the problems can and definetly do occur.

The premise of the original post seems wrong.

Hardware serial is generally preferred over software serial because it is much less likely to cause implementation issues particularly at higher baud rates on more limited processors.

If software serial works in your application, no one is going to frown upon it. It's just another tool in the toolbox.

2 Likes

Agreed.

The waste of resources is frowned upon, when better, more efficient operations that are less likely to cause problems are ignored.

3 Likes

That then leads to the question: which of your devices most deserve hardware serial ports, or which of those devices would be the best candidate for the inferior software serial port?

Without knowing what those other devices are, it's certainly possible that the display would benefit from using a hardware serial port more than one of those other devices would be disadvantaged by using a software serial port.

Nope... the two Hardware serials are running timing critical DMX functions. The screen is only for programming and doesn't actually get used while the DMX is running.

There are actually three.

Never looked...

It is always a good idea to read the docs.

Well when I said 'user available' I meant with the pins broken out and not also used for Programming/debug.

Teensy 4.1 would be great (8 Serials), but they are a bit too physically big for my enclosure and expensive.

I think I will have to stick with using SoftwareSerial for the screen

The UARTs can be assigned to pins of your choice.

Ok then. Just the kind of thing to have included in your first post.

Arduino compatible boards based on SAMD21 chips have 5 "SERCOM" ports which can be configured to be SPI, I2C or UART (=Serial) ports. Some of these boards are small and inexpensive.

https://learn.sparkfun.com/tutorials/adding-more-sercom-ports-for-samd-boards

https://sigmdel.ca/michel/ha/xiao/seeeduino_xiao_3usarts_en.html

seeeduino_xiao_3usarts

I don't think anyone has explained that hardware serial is performed by a processor "peripheral", which is a separate section of the processor that runs on its own. Once you start it sending or receiving a byte, it will continue handling each bit automatically no matter what else is going on. So if there's a Timer0 interrupt to update millis(), the serial peripheral will pay no attention, and just continue processing the bits while the interrupt code is executing. So you can deal with the traffic one byte at a time. Software serial may have to deal with each bit, and will have to make provisions for any interrupts that might take place. So hardware serial has significant advantages over software. One of the differences will be maximum baud rate, in case that matters.

3 Likes

Why. That wasn't my question. I know my DMX functions need Hardware serial.

Those SAMD21 boards look interesting, Maybe I will grab one for a play. Thanks

We didn't know that. We are the ones you are asking for advice.

On this forum, hundreds of questions are asked every day where the question that was asked turned out not to be the question that needed an answer, because of misconceptions and ignorance on the part of those posting them. This has taught the forum members who spend time answering questions not to make assumptions about what the poster does and does not know. If they answered every question strictly as it was asked, those posting the questions would be back in a couple of days or weeks asking the question they should have asked the first time around, having wasted everybody's time, especially their own (and possibly their money too).

1 Like