SoftwareSerial.h esp32 S3

I am trying to build Demo_ServoMode.ino for a ESP32 S3 WROOM-1, codefrom SB Components.

This Arduino code calls sbservo.h

/*
 * Demo code for Servo Mode operation 
*/

#include <SBServo.h>

SBServo sb;

// GPIO 18 - S_RXD, GPIO 17 - S_TXD, as default.
#define S_RXD 18
#define S_TXD 17

const int ID = 0x02; // Change ID as per your Serial Servo Motor 

void setup()
{
  Serial1.begin(115200, SERIAL_8N1, S_RXD, S_TXD);
  sb.pSerial = &Serial1;
  delay(1000);
}


void loop()
{
  sb.WritePos(ID, 1000, 0, 1500);  // SERVO ID, Position, Time, Speed; => 1500 Steps/Seconds,
  delay(754);

  sb.WritePos(ID, 20, 0, 1500);  // SERVO ID, Position, Time, Speed; => 1500 Steps/Seconds,
  delay(754);

}
/*
 * SBServo.h
 * SB Servo Arduino Interface Library
 * Date: 01/01/2020
 * Author: SB Components
 */

#ifndef _SBSERVO_H
#define _SBSERVO_H

//-------Baud Rate--------
#define	SBS_1M 0
#define	SBS_0_5M 1
#define	SBS_250K 2
#define	SBS_128K 3
#define	SBS_115200 4
#define	SBS_76800	5
#define	SBS_57600	6
#define	SBS_38400	7

//	Memory Address
//-------EPROM(Read only)--------
#define SBS_VERSION_L 3
#define SBS_VERSION_H 4

//-------EPROM(Read And write)--------
#define SBS_ID 5
#define SBS_BAUD_RATE 6
#define SBS_MIN_ANGLE_LIMIT_L 9
#define SBS_MIN_ANGLE_LIMIT_H 10
#define SBS_MAX_ANGLE_LIMIT_L 11
#define SBS_MAX_ANGLE_LIMIT_H 12
#define SBS_CW_DEAD 26
#define SBS_CCW_DEAD 27

//-------SRAM(Read & Write)--------
#define SBS_TORQUE_ENABLE 40
#define SBS_GOAL_POSITION_L 42
#define SBS_GOAL_POSITION_H 43
#define SBS_GOAL_TIME_L 44
#define SBS_GOAL_TIME_H 45
#define SBS_GOAL_SPEED_L 46
#define SBS_GOAL_SPEED_H 47
#define SBS_LOCK 48

//-------SRAM(Read Only)--------
#define SBS_PRESENT_POSITION_L 56
#define SBS_PRESENT_POSITION_H 57
#define SBS_PRESENT_SPEED_L 58
#define SBS_PRESENT_SPEED_H 59
#define SBS_PRESENT_LOAD_L 60
#define SBS_PRESENT_LOAD_H 61
#define SBS_PRESENT_VOLTAGE 62
#define SBS_PRESENT_TEMPERATURE 63
#define SBS_MOVING 66
#define SBS_PRESENT_CURRENT_L 69
#define SBS_PRESENT_CURRENT_H 70
#include <SoftwareSerial.h>
#include "Serial.h"

class SBServo : public Serial
{
public:
	SBServo();
	SBServo(u8 End);
	SBServo(u8 End, u8 Level);
	virtual int WritePos(u8 ID, u16 Position, u16 Time, u16 Speed = 0);	// Write Position of a single Servo 
	virtual int RegWritePos(u8 ID, u16 Position, u16 Time, u16 Speed = 0);	// Asynchronous Write Servo Position
	virtual void SyncWritePos(u8 ID[], u8 IDN, u16 Position[], u16 Time[], u16 Speed[]);	// Write Position for multiple Servos
	virtual int PWMMode(u8 ID);	// PWM output Mode
	virtual int WritePWM(u8 ID, s16 pwmOut);	// PWM output Mode Instruction
	virtual int EnableTorque(u8 ID, u8 Enable);	// Torque control
	virtual int unLockEprom(u8 ID);	// EEPROM Unlock
	virtual int LockEprom(u8 ID);	// EEPROM Lock
	virtual int FeedBack(int ID);	// Feedback Servo Information
	virtual int ReadPos(int ID);	// Read Position
	virtual int ReadSpeed(int ID);	// Read Speed
	virtual int ReadLoad(int ID);	// Read Torque
	virtual int ReadVoltage(int ID);	// Read Voltage
	virtual int ReadTemperature(int ID);	// Read Temperature
	virtual int ReadMove(int ID);	// Read Servo moving 
	virtual int ReadCurrent(int ID);	// Read Current
private:
	u8 Mem[SBS_PRESENT_CURRENT_H-SBS_PRESENT_POSITION_L+1];
};

#endif

which then calls

#include <SoftwareSerial.h>
#include "Serial.h"

I have seen very old references to SoftwareSerial.h, but nothing at all new. How to I work around this issue these days?

Thanks

Please post a link to this code from SB Components. If there are any libraries involved, let us know how we can install them (library manager, github download, ...).

My first attempt would be to remove the #include <SoftwareSerial.h> from the second code that you did post and see where it fails to compile.

are you using SB_Serial_Servo/SBServo-Arduino at master · sbcshop/SB_Serial_Servo · GitHub ?

OK, here’s a fairly simple explanation of the problem.

Here is the link for this code

https://github.com/sbcshop/SB_Serial_Servo/tree/master/SBServo-Arduino

/*
 * Demo code for Servo Mode operation 
*/

#include <SBServo.h>

SBServo sb;

// GPIO 18 - S_RXD, GPIO 17 - S_TXD, as default.
#define S_RXD 18
#define S_TXD 17

const int ID = 0x02; // Change ID as per your Serial Servo Motor 

void setup()
{
  Serial1.begin(115200, SERIAL_8N1, S_RXD, S_TXD);
  sb.pSerial = &Serial1;
  delay(1000);
}


void loop()
{
  sb.WritePos(ID, 1000, 0, 1500);  // SERVO ID, Position, Time, Speed; => 1500 Steps/Seconds,
  delay(754);

  sb.WritePos(ID, 20, 0, 1500);  // SERVO ID, Position, Time, Speed; => 1500 Steps/Seconds,
  delay(754);

}

And here is the error that I get when I try to compile it.

In file included from /Users/ershler/Desktop/sb components/Demo_ServoMode/Demo_ServoMode.ino:5:
/Users/ershler/Desktop/sb components/Demo_ServoMode/SBServo.h:58:10: fatal error: SoftwareSerial.h: No such file or directory
58 | #include <SoftwareSerial.h>
| ^~~~~~~~~~~~~~~~~~
compilation terminated.
Alternatives for SoftwareSerial.h: []
ResolveLibrary(SoftwareSerial.h)
-> candidates: []
exit status 1

Compilation error: exit status 1

This list of files in my Arduino libraries

**This is an SB Servo Arduino Library for Interfacing Arduino and SB Servo Motors.**

# Installation
--------------------------------------------------------------------------------

## To install this library, just place this entire folder as a sub folder in your Arduino/libraries folder.

### When installed, this library should look like:

- Arduino/libraries/SBServo              (SB Servo Library Folder)
- Arduino/libraries/SBServo/SBServo.cpp     (the library implementation file)
- Arduino/libraries/SBServo/SBServo.h       (the library description file)
- Arduino/libraries/SBServo/SBSInst.cpp     (SB Servo Instruction Implementation)
- Arduino/libraries/SBServo/SBSInst.h       (SB Servo Instruction description)
- Arduino/libraries/SBServo/Serial.cpp     (SB Servo Serial Comm handle File)
- Arduino/libraries/SBServo/Serial.h       (SB Servo Serial Description file)

- Arduino/libraries/SBServo/keywords.txt (the syntax coloring file)
- Arduino/libraries/SBServo/examples     (the examples in the "open" menu)
- Arduino/libraries/SBServo/readme.txt   (this file)



Does this help explain what I am trying to do?

Thanks

There is an ESP version of SoftwareSerial that you can install from the Library Manager

EspSoftwareSerial

Nowhere in the code at that GitHub site is "SoftwareSerial.h" even mentioned, let alone #include(d). Is that the library that you actually installed?

Yes that was my underlying question in post 3.

The Serial instance variable is even hard typed to hardware serial…

Your sketch is in /Users/ershler/Desktop/sb components/Demo_ServoMode/.
A file SBServo.h is in the same directory and is used; don't ask me why. Which version of the IDE are you using?

3rd party libraries should be installed in the libraries sub directory of the sketchbook directory. It should look like

C:\USERS\BUGGE\ONEDRIVE\DOCUMENTS\ARDUINO\LIBRARIES\SBSERVO
|   keywords.txt
|   readme.txt
|   SBServo.cpp
|   SBServo.h
|   SBSInst.cpp
|   SBSInst.h
|   Serial.cpp
|   Serial.h
|
\---examples
    +---Broadcast
    |       Broadcast.ino
    |
    +---FeedBack
    |       FeedBack.ino
    |
    +---MotorMode
    |       MotorMode.ino
    |
    +---Ping
    |       Ping.ino
    |
    +---ProgramEprom
    |       ProgramEprom.ino
    |
    +---RegWritePos
    |       RegWritePos.ino
    |
    +---SyncWritePos
    |       SyncWritePos.ino
    |
    \---WritePos
            WritePos.ino

Where Arduino is the sketchbook directory (check under file → preferences).

Just like @gfvalvo I've checked the library and there is no reference to SoftwareSerial.

If you have the SBServo files in the sketch directory I suggest that you delete them, install the latest SBServo library in the correct place and try again.

I did the normal installation of the library and successfully compiled your code from post #4 for 3 different ESP32S3 boards.

Brings the question where did you get that code from? There is no Demo_ServoMode example.

I have a doubt: Isn’t the space in file name also an issue or was that just for extended utf8 characters ?

Spaces should not pose a problem; though for my own sanity I never use them in file paths :slight_smile:

I've recreated OP's setup (without the library files in the sketch directory) and it compiles.

OK - I had doubts (and as an old timer I don’t use spaces either)

I'm not really that impressed with the code. Exposing key internal variables as public is a bad practice:

public:
	unsigned long int IOTimeOut;	// Input/Output Timeout
	HardwareSerial *pSerial;	//Pointer to Serial Port
	int Err;

Instead the constructor should take a reference to a HardwareSerial (or even a Stream) object as an argument. There are also no checks to see if the user actually sets the pSerial pointer to anything valid.

Agreed - it’s not the best OO code ever

After including this version, the code does compile, but with the board that SB Component supplies, it still does not run right. I’ve had enough of their Arduino code. Although the company does supply a Python version, I think that I am going to abandon their software all together and just use code from Adafruit. I do however appreciate all the responses to my original post that I have seen.