ESP32 Can't Use Arduino Builtin Library

I have a problem when using SoftwareSerial builtin Arduino library in ESP32 program. It says No such file or directory. I remember correctly I did use this SoftwareSerial in my program and working fine. Now I can't even compile it. Is it because I install Arduino Boards Package via Arduino IDE ver 2.0.x? Because this problem happen when I use newest Arduino IDE. And I used SoftwareSerial in ESP32 even before Arduino IDE ver 2.0.x released.

Thank you.

Usually, you don't need SoftwareSerial on ESP32, because the ESP has 3 hardware serial ports (UARTs). You should use HardwareSerial.h library instead.

If you are sure that you need SoftwareSerial on ESP32 - you can use specific ESP32 version of the library:

1 Like

I actually need 4 Serial Communication, that is why. As for espsoftwareserial, even the example code cant be compiled. it says something like no valid gpio pin. can you try that for me with Arduino IDE 2.0.3? if it work in your laptop/pc please do tell me. Thank you.

The ESP32 has 4 hardware serial ports. Most users can easily use 2 of the hardware serial ports. The 3rd serial port can be used buts its a little tricker and the 4th hardware serial port is mostly unavailable to the user.

1 Like

If the code worked on 1.x IDE versions, why do not still use it ?

1 Like

I tried. But have the same outcome in ver 2.x. It says no such file or directory. Like i said earlier, Is it because I install Arduino Boards Package via Arduino IDE ver 2.0.x? I will try reinstall it from the start to see if this will work. Thanks for your reply

Thanks for the information @Idahowalker But how SoftwareSerial work back then?

The OP may want to consider a serial expander if they NEED 4 ports,

1 Like

it seems that the IDE version has nothing to do with the problem...

Please show the code and the error message(s)

I was not present for when you said software serial on a ESP32 was working. I did not see the code nor did I see it operate. How do you expect me to know how it 'worked' then?


@b707 here the screenshot

Help us help you.

1 Like

@Idahowalker okay, i have no way to prove that it works back then. so let's stick that the program isn't working now. Thanks for your reply and suggestion.

First - please do not insert the code as screenshots in the forum!

As for the error itself - you must specify specific pins when instantiating the new SoftwareSerial object.

Softwareserial swser1(12, 34);
#include "SoftwareSerial.h"

#ifndef D5
#if defined(ESP8266)
#define D5 (14)
#define D6 (12)
#elif defined(ESP32)
#define D5 (18)
#define D6 (19)
#endif
#endif

SoftwareSerial swSer1;
SoftwareSerial swSer2;

void setup() {
	delay(2000);
	Serial.begin(115200);
	Serial.println(PSTR("\nOne Wire Half Duplex Serial Tester"));
	swSer1.begin(115200, SWSERIAL_8N1, D6, D6, false, 256);
	// high speed half duplex, turn off interrupts during tx
	swSer1.enableIntTx(false);
	swSer2.begin(115200, SWSERIAL_8N1, D5, D5, false, 256);
	// high speed half duplex, turn off interrupts during tx
	swSer2.enableIntTx(false);
}

void loop() {
	Serial.println(PSTR("\n\nTesting on swSer1"));
	Serial.print(PSTR("Enter something to send using swSer1."));
	checkSwSerial(&swSer1);

	Serial.println(PSTR("\n\nTesting on swSer2"));
	Serial.print(PSTR("Enter something to send using swSer2."));
	checkSwSerial(&swSer2);

}

void checkSwSerial(SoftwareSerial* ss) {
	byte ch;
	while (!Serial.available());
	ss->enableTx(true);
	while (Serial.available()) {
		ch = Serial.read();
		ss->write(ch);
	}
	ss->enableTx(false);
	// wait 1 second for the reply from SOftwareSerial if any
	delay(1000);
	if (ss->available()) {
		Serial.print(PSTR("\nResult:"));
		while (ss->available()) {
			ch = (byte)ss->read();
			Serial.print(ch < 0x10 ? PSTR(" 0") : PSTR(" "));
			Serial.print(ch, HEX);
		}
		Serial.println();
	}
}

that is an example program.

error :

In file included from C:\Users\envyst\AppData\Local\Temp\.arduinoIDE-unsaved20221121-25376-1i1hftg.ezoz\onewiretest\onewiretest.ino:1:0:
c:\Users\envyst\Documents\Arduino\libraries\EspSoftwareSerial\src/SoftwareSerial.h:226:20: error: enclosing class of constexpr non-static member function 'bool SoftwareSerial::isValidGPIOpin(int8_t) const' is not a literal type
     constexpr bool isValidGPIOpin(int8_t pin) const;
                    ^
c:\Users\envyst\Documents\Arduino\libraries\EspSoftwareSerial\src/SoftwareSerial.h:87:7: note: 'SoftwareSerial' is not literal because:
 class SoftwareSerial : public Stream {
       ^
c:\Users\envyst\Documents\Arduino\libraries\EspSoftwareSerial\src/SoftwareSerial.h:87:7: note:   'SoftwareSerial' has a non-trivial destructor
c:\Users\envyst\Documents\Arduino\libraries\EspSoftwareSerial\src/SoftwareSerial.h:227:20: error: enclosing class of constexpr non-static member function 'bool SoftwareSerial::isValidRxGPIOpin(int8_t) const' is not a literal type
     constexpr bool isValidRxGPIOpin(int8_t pin) const;
                    ^
c:\Users\envyst\Documents\Arduino\libraries\EspSoftwareSerial\src/SoftwareSerial.h:228:20: error: enclosing class of constexpr non-static member function 'bool SoftwareSerial::isValidTxGPIOpin(int8_t) const' is not a literal type
     constexpr bool isValidTxGPIOpin(int8_t pin) const;
                    ^
c:\Users\envyst\Documents\Arduino\libraries\EspSoftwareSerial\src/SoftwareSerial.h:230:20: error: enclosing class of constexpr non-static member function 'bool SoftwareSerial::hasRxGPIOPullUp(int8_t) const' is not a literal type
     constexpr bool hasRxGPIOPullUp(int8_t pin) const;
                    ^

exit status 1

Compilation error: exit status 1

You going to use the same pin for both RX and TX?

Hi @envyst4. I'm going to ask you to post some additional information that might help us to identify the problem.


:exclamation: NOTE: These instructions will not solve the problem. They are only intended to gather more information which might provide a clue that eventually leads to a solution.


Please do this:

  1. Select File > Preferences from the Arduino IDE menus.
  2. Check the box next to "Show verbose output during: ☐ compilation".
  3. Click the OK button.
  4. Select Sketch > Verify/Compile from the Arduino IDE menus.
  5. Wait for the compilation to fail.
  6. You will see a "Compilation error: ..." notification at the bottom right corner of the Arduino IDE window. Click the COPY ERROR MESSAGES button on that notification.
  7. Open a forum reply here by clicking the Reply button.
  8. Click the </> icon on the post composer toolbar.
    This will add the forum's code block markup (```) to your reply to make sure the error messages are correctly formatted.
    Code block
  9. Press Ctrl+V.
    This will paste the compilation output into the code block.
  10. Move the cursor outside of the code tags before you add any additional text to your reply.
  11. Click the Reply button to post the output.

In case the output is longer than the forum software will allow to be added to a post, you can instead save it to a .txt file and then attach that file to a reply here:

  1. Open any text editor program.
  2. Paste the copied output into the text editor.
  3. Save the file in .txt format.
  4. Open a forum reply here by clicking the Reply button.
  5. Click the "Upload" icon (image) on the post composer toolbar:
    image
  6. Select the .txt file you saved.
  7. Click the Open button.
  8. Click the Reply button to publish the post.

Alternatively, instead of using the "Upload" icon on the post composer toolbar as described in steps (5) - (7) above, you can simply drag and drop the .txt file onto the post composer field to attach it.

1 Like

For working with some many serial ports there is a different microcontroller that is able to to that even for 10 or 12 serial interfaces at the same time.

This microcontroller is called propeller-chip. Very different concept how the propeller-chip works than most other microcontrollers.
8 cores that can execute code in real parallel. All kind of interfaces like UART, I2C, onewire, SPI, is done by using software-drivers running in one of the cores. There is one "library" that creates four UARTS each running at 115200 baud.

You should post a detailed description of your complete project. I'm pretty sure that there are other better suited solutions to process all your data.
Which solution fits best highly depends on the details of your project.

best regards Stefan

1 Like

Is it available in the Arduino environment?

I haven't checked this. The propeller-chip has its own very easy to use IDE.
Much easier to learn than the Arduino-IDE. Much less options because special made for propeller-chip 1 and propeller-chip 2

More comfortable because each function has a different backround color
the character-set includes schematic symbols like resistors, capacitors, transistors etc.

Also a C-Compiler is available.
Main thing is its own c-like programming language called SPIN.
second advanced concept is: the assembler-language can execute ALL commands conditional depening on two flags. And as all code always runs in RAM you can even write self-modifying code that does not wear out flash.
The code runs in RAM. The binary code is stored into an external EEPROM which gets loaded into RAM at power-up.

So indeed very different than most other microcontrollers.

If you would like to have something arduino-compatible for a lot of UARTs I would take a Teensy 4.1
https://www.pjrc.com/store/teensy41.html
best regards Stefan

1 Like