Converting SoftwareSerial to HardwareSerial

So I’ve been searching around for a bit and have found minimal threads to support me on this. I have an arduino uno that I used with a library created for speech recognition. The library uses softwareserial. I’ve now bought an arduino 33 IoT which uses hardwareserial and I didn’t know. The library no longer works and I really need the size and would really like to keep the onboard gyro capabilities of the 33 IoT instead of nano. Can anyone help me with figuring out how to change this library over to Hardware Serial! I reference this library into my custom sketch.

Library Link: https://electronoobs.com/images/Arduino/tut_165/VoiceRecognitionV3-master.zip
Github Link:VoiceRecognitionV3/VoiceRecognitionV3.h at master · elechouse/VoiceRecognitionV3 · GitHub
VoiceRecognitionV3.h Code:

#if ARDUINO >= 100
 #include "Arduino.h"
#else
 #include "WProgram.h"
#endif

#include "wiring_private.h"

#include "SoftwareSerial.h"
#include <avr/pgmspace.h>

#define DEBUG

#ifdef DEBUG
#define DBGSTR(message)     Serial.print(message)
#define DBGBUF(buf, len)	Serial.write(buf, len)
#define DBGLN(message)		Serial.println(message)
#define DBGFMT(msg, fmt)	Serial.print(msg, fmt)
#define DBGCHAR(c)			Serial.write(c)
#else
#define DBG(message)
#endif // DEBUG

class VR : public SoftwareSerial{
public:
	VR(uint8_t receivePin, uint8_t transmitPin);
	
	static VR* getInstance() {
	   return instance;
	}
	
	typedef enum{
		PULSE = 0,
		TOGGLE = 1,
		SET = 2, 
		CLEAR = 3
	}io_mode_t;
	
	typedef enum{
		LEVEL0 = 0,
		LEVEL1,
		LEVEL2, 
		LEVEL3,
		LEVEL4,
		LEVEL5,
		LEVEL6,
		LEVEL7,
		LEVEL8,
		LEVEL9,
		LEVEL10,
		LEVEL11,
		LEVEL12,
		LEVEL13,
		LEVEL14,
		LEVEL15,
	}pulse_width_level_t;
	
	typedef enum{
		GROUP0 = 0,
		GROUP1,
		GROUP2,
		GROUP3,
		GROUP4,
		GROUP5,
		GROUP6,
		GROUP7,
		GROUP_ALL = 0xFF,
	}group_t;
	
	int setBaudRate(unsigned long br);
	int setIOMode(io_mode_t mode);
	int resetIO(uint8_t *ios=0, uint8_t len=1);
	int setPulseWidth(uint8_t level);
	int setAutoLoad(uint8_t *records=0, uint8_t len = 0);
    int disableAutoLoad();
	int restoreSystemSettings();
	int checkSystemSettings(uint8_t* buf);
	int recognize(uint8_t *buf, int timeout = VR_DEFAULT_TIMEOUT);
	int train(uint8_t *records, uint8_t len=1, uint8_t *buf = 0);
	int train(uint8_t record, uint8_t *buf = 0);
	int trainWithSignature(uint8_t record, const void *buf, uint8_t len=0, uint8_t *retbuf = 0);
	int load(uint8_t *records, uint8_t len=1, uint8_t *buf = 0);
	int load(uint8_t record, uint8_t *buf = 0);
	int clear();
	int setSignature(uint8_t record, const void *buf=0, uint8_t len=0);
	int deleteSignature(uint8_t record);
    
	int checkSignature(uint8_t record, uint8_t *buf);
	int checkRecognizer(uint8_t *buf);
	int checkRecord(uint8_t *buf, uint8_t *records = 0, uint8_t len = 0);
	
	/** group control */
	int setGroupControl(uint8_t ctrl);
	int checkGroupControl();
	int setUserGroup(uint8_t grp, uint8_t *records, uint8_t len);
	int checkUserGroup(uint8_t grp, uint8_t *buf);
	int loadSystemGroup(uint8_t grp, uint8_t *buf=0);
	int loadUserGroup(uint8_t grp, uint8_t *buf=0);
	
	int test(uint8_t cmd, uint8_t *bsr);
	
	int writehex(uint8_t *buf, uint8_t len);
	
/***************************************************************************/
	/** low level */
	int len(uint8_t *buf);
	int cmp(uint8_t *buf, uint8_t *bufcmp, int len  );
	void cpy(char *buf,  char * pbuf);
	void sort(uint8_t *buf, int len);
	int cleanDup(uint8_t *des, uint8_t *buf, int len);
	void send_pkt(uint8_t *buf, uint8_t len);
	void send_pkt(uint8_t cmd, uint8_t *buf, uint8_t len);
	void send_pkt(uint8_t cmd, uint8_t subcmd, uint8_t *buf, uint8_t len);
	int receive(uint8_t *buf, int len, uint16_t timeout = VR_DEFAULT_TIMEOUT);
	int receive_pkt(uint8_t *buf, uint16_t timeout = VR_DEFAULT_TIMEOUT);
/***************************************************************************/
private:
	static VR*  instance;
};


Yes, the forum can help. Minimal examples are realy all you need, it's pretty simple. Post your attempt to use hardware serial including schematic and code. Please read the forum guide so you know how to post those things correctly.

Also please describe and give links to the library you need help with.

have a look at arduino-nano-33-iot-pinout-spec-board and using-additional-serial-ports

SomeSerial!!!

This does look useful, would I be able to just implement that into the code of the library I just uploaded?

You know, something else I saw mentioned using Serial1 but how would I implement that into the code I just added into the post?

I looked at the library on GitHub. What a crappy way to write it. The class's constructor should have been written to take a reference to a Stream object and let the main code select and initialize the connection.

Yeah I'm hoping it's something I can find a way to modify it to work with my 33 IoT, otherwise I'll have to switch to the basic nano and create my own gryo and accelerometer for what I'm doing

I'd modify the library. Only problem there is if the author updates it. But, per GitHub, the last update was 7 years ago. So, probably not much chance of that.

Based off your quick glance at the library, how much work do you think that would take? I am by no means a beginner in programming, but Arduino isn't my normal structure

See the modified library published here:

I modified the library because someone wanted to use two voice recognition boards on the same Arduino and we all know that you can't easily use two SoftwareSerial ports.

Great job!
Now we are waiting for the expansion of the library for the Rasberry PI Pico and ESP32 architecture (V5 ?)

Have you tried removing this line from VoiceRecognitionV4.h?
#include <avr/pgmspace.h>

That was sufficient to use the library on ESP32.

#include "VoiceRecognitionV4.h"
VR myVR(&Serial1);

void setup()
{
  /** initialize */
  //myVR.begin(9600);
  Serial1.begin(9600);
}

void loop() {}

This is not our method!

#if !defined(ESP32) ||  !defined(ESP8266) || !defined(RP2040)
#include <avr/pgmspace.h>
#endif

This is beautiful. I was able to do everything you said and import it with no issues. However now I'm trying to get the hardware to work. Someone in that thread said it worked on their 33 IoT so I'm probably not doing something right on the wiring side or my person code side. Either way, I'm still used to uno programming. What pins on the 33 iot would I put &Serial1 and &Serial2? I need a 5v, ground, Rx and Tx. I know what to do with 5v and ground but the 2 communication pins are where I'm stuck

// Serial1
extern Uart Serial1;
#define PIN_SERIAL1_RX       (0ul)
#define PIN_SERIAL1_TX       (1ul)
#define PAD_SERIAL1_TX       (UART_TX_PAD_2)
#define PAD_SERIAL1_RX       (SERCOM_RX_PAD_3)

// Serial1
extern Uart Serial2;
#define PIN_SERIAL2_RX       (30ul)
#define PIN_SERIAL2_TX       (29ul)
#define PAD_SERIAL2_TX       (UART_TX_PAD_0)
#define PAD_SERIAL2_RX       (SERCOM_RX_PAD_1)

extern Uart SerialHCI;
#define PIN_SERIALHCI_RX (23ul)
#define PIN_SERIALHCI_TX (22ul)
#define PAD_SERIALHCI_TX (UART_TX_RTS_CTS_PAD_0_2_3)
#define PAD_SERIALHCI_RX (SERCOM_RX_PAD_1)
#define PIN_SERIALHCI_RTS (24u)
#define PIN_SERIALHCI_CTS (25u)

I added that into my code and made some changes to the code that works on my uno. It still doesn't work but I can tell I'm close. Any chance you can help me port this correctly? I have the voice module on Pin 2 and 3 of my nano IOT 33.

#include <VoiceRecognitionV4.h>
#include "wiring_private.h"

/**        
  Connection
  Arduino    VoiceRecognitionModule
   2   ------->     TX
   3   ------->     RX

*/

extern Uart Serial1;
#define PIN_SERIAL1_RX       (0ul)
#define PIN_SERIAL1_TX       (1ul)
#define PAD_SERIAL1_TX       (UART_TX_PAD_2)
#define PAD_SERIAL1_RX       (SERCOM_RX_PAD_3)

// Serial1
extern Uart Serial2;
#define PIN_SERIAL2_RX       (30ul)
#define PIN_SERIAL2_TX       (29ul)
#define PAD_SERIAL2_TX       (UART_TX_PAD_0)
#define PAD_SERIAL2_RX       (SERCOM_RX_PAD_1)

extern Uart SerialHCI;
#define PIN_SERIALHCI_RX (23ul)
#define PIN_SERIALHCI_TX (22ul)
#define PAD_SERIALHCI_TX (UART_TX_RTS_CTS_PAD_0_2_3)
#define PAD_SERIALHCI_RX (SERCOM_RX_PAD_1)
#define PIN_SERIALHCI_RTS (24u)
#define PIN_SERIALHCI_CTS (25u)

VR myVR1(&Serial1);
//VR myVR2(&Serial2);   // 2:RX 3:TX, you can choose your favourite pins.

uint8_t records[7]; // save record
uint8_t buf[64];

int led = 13;


void setup()
{
  /** initialize */
  Serial1.begin(9600); // Default baud rate for VoiceRecognitionV3 module

  //Serial.begin(115200);
  myVR1.clear();
  myVR1.load(uint8_t (2));
  Serial.print("ON");
}

void loop()
{
  int ret;
  ret = myVR1.recognize(buf, 50);
  if(ret>0)
  {
    if(buf[2]==0)
    {
      Serial.print("Heard Light");
      myVR1.load(uint8_t (2));
    }
    //printVR(buf);
  }
}




Shouldn't the module be connected to pin 0 and pin1 for communication over Serial1?

I corrected it but I still get nothing. No errors no messages nothing. I desperately need help.
New Code:

#include <VoiceRecognitionV4.h>
#include "wiring_private.h"

/**        
  Connection
  Arduino    VoiceRecognitionModule
   2   ------->     TX
   3   ------->     RX

*/

extern Uart Serial1;
#define PIN_SERIAL1_RX       (0ul)
#define PIN_SERIAL1_TX       (1ul)
#define PAD_SERIAL1_TX       (UART_TX_PAD_2)
#define PAD_SERIAL1_RX       (SERCOM_RX_PAD_3)

// Serial1
// extern Uart Serial2;
// #define PIN_SERIAL2_RX       (30ul)
// #define PIN_SERIAL2_TX       (29ul)
// #define PAD_SERIAL2_TX       (UART_TX_PAD_0)
// #define PAD_SERIAL2_RX       (SERCOM_RX_PAD_1)

extern Uart SerialHCI;
#define PIN_SERIALHCI_RX (23ul)
#define PIN_SERIALHCI_TX (22ul)
#define PAD_SERIALHCI_TX (UART_TX_RTS_CTS_PAD_0_2_3)
#define PAD_SERIALHCI_RX (SERCOM_RX_PAD_1)
#define PIN_SERIALHCI_RTS (24u)
#define PIN_SERIALHCI_CTS (25u)

VR myVR1(&Serial1);
//VR myVR2(&Serial2);   // 2:RX 3:TX, you can choose your favourite pins.

uint8_t records[7]; // save record
uint8_t buf[64];

int led = 13;


void setup()
{
  /** initialize */
  //Serial1.begin(115200); // Default baud rate for VoiceRecognitionV3 module
  Serial.begin(9600);
  myVR1.clear();
  myVR1.load(uint8_t (2));
  Serial.print("ON");
}

void loop()
{
  int ret;
  ret = myVR1.recognize(buf, 50);
  if(ret>0)
  {
    Serial.print("Heard");
    if(buf[2]==0)
    {
      Serial.print("Heard Light");
      myVR1.load(uint8_t (2));
    }
    //printVR(buf);
  }
}




I'm trying really hard to get the code to work using that library and I'm getting no errors or messages from it. I have the module connected to pin 2 and 3 on the board. Here is my code:

#include <VoiceRecognitionV4.h>
#include "wiring_private.h"

/**        
  Connection
  Arduino    VoiceRecognitionModule
   2   ------->     TX
   3   ------->     RX

*/

extern Uart Serial1;
#define PIN_SERIAL1_RX       (0ul)
#define PIN_SERIAL1_TX       (1ul)
#define PAD_SERIAL1_TX       (UART_TX_PAD_2)
#define PAD_SERIAL1_RX       (SERCOM_RX_PAD_3)

// Serial1
// extern Uart Serial2;
// #define PIN_SERIAL2_RX       (30ul)
// #define PIN_SERIAL2_TX       (29ul)
// #define PAD_SERIAL2_TX       (UART_TX_PAD_0)
// #define PAD_SERIAL2_RX       (SERCOM_RX_PAD_1)

extern Uart SerialHCI;
#define PIN_SERIALHCI_RX (23ul)
#define PIN_SERIALHCI_TX (22ul)
#define PAD_SERIALHCI_TX (UART_TX_RTS_CTS_PAD_0_2_3)
#define PAD_SERIALHCI_RX (SERCOM_RX_PAD_1)
#define PIN_SERIALHCI_RTS (24u)
#define PIN_SERIALHCI_CTS (25u)

VR myVR1(&Serial1);
//VR myVR2(&Serial2);   // 2:RX 3:TX, you can choose your favourite pins.

uint8_t records[7]; // save record
uint8_t buf[64];

int led = 13;


void setup()
{
  /** initialize */
  //Serial1.begin(115200); // Default baud rate for VoiceRecognitionV3 module
  Serial.begin(9600);
  Serial1.begin(115200);
  myVR1.clear();
  myVR1.load(uint8_t (2));
  Serial.print("ON");
}

void loop()
{
  int ret;
  ret = myVR1.recognize(buf, 50);
  if(ret>0)
  {
    Serial.print("Heard");
    if(buf[2]==0)
    {
      Serial.print("Heard Light");
      myVR1.load(uint8_t (2));
    }
    //printVR(buf);
  }
}