SoftwareSerial.h Library not found

Hi, I am trying to collect data from a GPS using the code below. Unfortunately, I keep getting an error that I posted below the code stating the SoftwareSerial library cannot be found. I also tried downloading a SoftwareSerial library from github and still had the same issue, so I don’t know how to solve this problem.

#include <SoftwareSerial.h>
SoftwareSerial SoftSerial(2, 3);
unsigned char buffer[64];                   // buffer array for data receive over serial port
int count=0;                                // counter for buffer array
void setup()
{
    SoftSerial.begin(9600);                 // the SoftSerial baud rate
    Serial.begin(9600);                     // the Serial port of Arduino baud rate.
}
 
void loop()
{
    if (SoftSerial.available())                     // if date is coming from software serial port ==> data is coming from SoftSerial shield
    {
        while(SoftSerial.available())               // reading data into char array
        {
            buffer[count++]=SoftSerial.read();      // writing data into array
            if(count == 64)break;
        }
        Serial.write(buffer,count);                 // if no data transmission ends, write buffer to hardware serial port
        clearBufferArray();                         // call clearBufferArray function to clear the stored data from the array
        count = 0;                                  // set counter of while loop to zero 
    }
    if (Serial.available())                 // if data is available on hardware serial port ==> data is coming from PC or notebook
    SoftSerial.write(Serial.read());        // write it to the SoftSerial shield
}
 
 
void clearBufferArray()                     // function to clear buffer array
{
    for (int i=0; i<count;i++)
    {
        buffer[i]=NULL;
    }                      // clear all index of array with command NULL
}

Arduino: 1.8.13 (Windows Store 1.8.42.0) (Windows 10), Board: “Arduino NANO 33 IoT”
SimpleAccelerometer:1:10: fatal error: SoftwareSerial.h: No such file or directory

#include <SoftwareSerial.h>

^~~~~~~~~~~~~~~~~~

compilation terminated.

exit status 1

SoftwareSerial.h: No such file or directory

This report would have more information with
“Show verbose output during compilation”
option enabled in File → Preferences.

As you discovered, there is no SoftwareSerial library for the SAMD architecture of the Nano 33 IoT. However, there is no need for one. The Nano 33 IoT has an unused hardware serial port named Serial1 on pins 0 and 1, so just use that. It's also possible to get more if you need it, but you most likely don't so we won't worry about that.

Note that the Nano 33 IoT is different from the classic Nano because the serial port on pins 0 and 1 (Serial) on the classic Nano is also used for uploading sketches and other communication with the computer (e.g., Serial Monitor), so it's not really convenient to use Serial for other purposes on the classic Nano. This is why you will often see people using SoftwareSerial library with the Nano, Uno, Pro Mini, etc. But the Nano 33 IoT is different because the Serial1 serial port on pins 0 and 1 is not used for anything, so you are free to use those pins for your own purposes.

Thank You for the swift reply. So in order for me to collect data from the gps and plot it on my serial monitor in arduino or export it somewhere else, should I just delete the #include SoftwareSerial, and change all the SoftSerial in my code to Serial1 and instead of using the pins 2,3, I use the Rx and Tx pins (0 and 1) of the Nano 33 iot?

unsigned char buffer[64];                   // buffer array for data receive over serial port
int count=0;                                // counter for buffer array
void setup()
{
    Serial1.begin(9600);                 // the SoftSerial baud rate
    Serial.begin(9600);                     // the Serial port of Arduino baud rate.
}
 
void loop()
{
    if (Serial1.available())                     // if date is coming from software serial port ==> data is coming from SoftSerial shield
    {
        while(Serial1.available())               // reading data into char array
        {
            buffer[count++]=Serial1.read();      // writing data into array
            if(count == 64)break;
        }
        Serial.write(buffer,count);                 // if no data transmission ends, write buffer to hardware serial port
        clearBufferArray();                         // call clearBufferArray function to clear the stored data from the array
        count = 0;                                  // set counter of while loop to zero 
    }
    if (Serial.available())                 // if data is available on hardware serial port ==> data is coming from PC or notebook
    Serial1.write(Serial.read());        // write it to the SoftSerial shield
}
 
 
void clearBufferArray()                     // function to clear buffer array
{
    for (int i=0; i<count;i++)
    {
        buffer[i]=NULL;
    }                      // clear all index of array with command NULL
}

You got it!

How do I initialize the Rx and Tx pins of the arduino? I have my GPS code but nothing is being detected.
Below is the code that I am using. Nothing shows on the serial monitor, not even the Serial.println(“GPS Start”); line.​

#include <TinyGPS++.h>

TinyGPSPlus gps;//This is the GPS object that will pretty much do all the grunt work with the NMEA data
void setup()
{
  Serial.begin(9600);//This opens up communications to the Serial monitor in the Arduino IDE
  Serial1.begin(9600);//This opens up communications to the GPS
  Serial.println("GPS Start");//Just show to the monitor that the sketch has started
}

void loop()
{
  while(Serial1.available())//While there are characters to come from the GPS
  {
    gps.encode(Serial1.read());//This feeds the serial NMEA data into the library one char at a time
  }
  if(gps.location.isUpdated())//This will pretty much be fired all the time anyway but will at least reduce it to only after a package of NMEA data comes in
  {
    //Get the latest info from the gps object which it derived from the data sent by the GPS unit
    Serial.println("Satellite Count:");
    Serial.println(gps.satellites.value());
    Serial.println("Latitude:");
    Serial.println(gps.location.lat(), 6);
    Serial.println("Longitude:");
    Serial.println(gps.location.lng(), 6);
    Serial.println("Speed MPH:");
    Serial.println(gps.speed.mph());
    Serial.println("Altitude Feet:");
    Serial.println(gps.altitude.feet());
    Serial.println("");
  }
}

pwvsviper:
not even the Serial.println("GPS Start"); line.​

Unlike the boards with a separate USB chip like the classic Nano, Uno, and Mega, the Nano 33 IoT doesn't reset when you open Serial Monitor. So by the time you get Serial Monitor open, the Serial.print() in setup() has already printed without you being able to see it.

You can add some code to make the Arduino board wait until the serial connection has been opened before continuing with the program:

while (!Serial) {
  ; // wait for serial port to connect. Needed for native USB port only
}

But you should note that sometimes this behavior is not desirable, so be careful when you use it. For example, if you have a program that you want to be able to run without having a connection to Serial Monitor, then you definitely don't want this sort of code because it will cause your Arduino board to just hang forever in setup() and never run the sketch! In cases where you want Serial Monitor output only for debugging, you can add this wait code, then comment it out when it's no longer needed.

Okay but then should I not be able to see the readings that I’m printing in the serial monitor in the loop if only the setup is already printed before I am able to open the serial monitor?

Yes, but you'll only be getting output from loop if data is being received from the GPS. The "GPS Start" in setup() is a nice sanity check just to prove to you that the output on Serial is working.

Because I'm not receiving any data and the GPS is correctly powered as the PWR led is on, can I assume that the GPS isn't working? I tried giving it a few minutes for a cold start but the serial monitor didn't show anything.

Make sure you have an RX-TX, TX-RX connection between the GPS and the Nano 33 IoT. It's pretty common for people to think that the connection should be RX-RX, TX-TX, but this is not right because "RX" stands for "recieve" and "TX" stands for transmit. So you need to connect the receive pin to the transmit pin and vice versa.

If you just want to see exactly what is coming in on Serial1, you can use this "SerialPassthrough" sketch:

It was the Tx-Rx connection that was wrong in my circuit. Thank You so much for all the help.

You're welcome. I'm glad if I was able to be of assistance. Enjoy!
Per

This topic was automatically closed 120 days after the last reply. New replies are no longer allowed.