2
votes

I am planning on moving from the old 5V Arduino Nano to the new Arduino Nano 33 IoT. I have written a functioning code for the old 5V Arduino Nano using Software Serial (SoftwareSerial.h) to communicate with a Sim800L module. The software serial library however is not found when I change the board to the new Arduino Nano 33 IoT.

I have tried finding it in the "include library" menu under "Sketch" but the library is simply not there. Given that the product is so new, I have not found any useful research to help me with this. I have the same problem with the EEPROM library.

#include <SoftwareSerial.h>
#include <EEPROM.h>

Does anyone know how to either include the SoftwareSerial.h and EEPROM.h library for the new Nano 33 IoT board of perhaps know of a new library used for the new board?

Below is the error message I get when compiling:

Sim800L_V7.1:3:12: error: SoftwareSerial.h: No such file or directory

   #include <SoftwareSerial.h>

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

compilation terminated.

exit status 1
SoftwareSerial.h: No such file or directory

Any help would be greatly appreciated Thanks

2
the RX and TX pins on Nano 33 IoT are Serial1. Nano 33 Iot is SAMD architecture. it is Arduino MKR1010 in Nano form and pinout. almost every information for MKR1010 applies to Nano 33 IoTJuraj
@Juraj, thank you for your comment!!!! That helps a lot and I will look into that.Misha
@Juraj; Just to confirm, the Tx and Rx pins are different to old Nano? ie the TX and RX on the Nano 33 IoT board are not the USB Tx and Rx?Misha
Serial is native USB of the MCU. Serial1 is SERCOM configured as UART for pins RX/TX. it is Arduino Zero in basic. Zero evolved to MKR Zero, MKR Zero to MKR 1010 and now Nano 33 IoT is a Nano versionJuraj
There is no SoftwareSerial available for your board.Masoud Rahimi

2 Answers

4
votes

There is no SoftwareSerial.h available for the Arduino Nano 33 IoT because it is not required. This board offers much more: Hardware serials that can be assigned to different pins.

This feature is offered by the micro controller Atmel SAMD21G and it is called I/O multiplexing (details available page 21 in the data sheet Atmel SAM D21E / SAM D21G / SAM D21J). The micro controller is offering 6 SERCOM that you can assign to (nearly) any pins.

Some of the SERCOM are already used by the Arduino Nano 33 IoT:

  • SERCOM2 for SPI NINA
  • SERCOM3 for MOSI/MISO
  • SERCOM4 for I2C bus
  • SERCOM5 for Serial debugging (USB)

We still have the SERCOM0 and SERCOM1.

The details of the pins assignments are described in the variant.cpp and variant.h files. As Arduino is open-source, you can easily find them on the GitHub repository for SAMD boards.

For the Arduino Nano 33 IoT, the pins assignments are described in:

By reading the variant.cpp, we understand the pin assignment and especially the link between the SAMD pin (PAxx or PBxx) and the Arduino pin.

The SAMD pins are important to make the link with the PORT Function Multiplexing of the the data sheet Atmel SAM D21E / SAM D21G / SAM D21J.

A SERCOM can be classic or alternate. In the data sheet, the classic is in the column C and the alternate is in the column D. A SERCOM is defined by its index and the pad. For example: SERCOM0/PAD[3] is also called 0.3.

Remark: The pads are defined from 0 to 3 for the RX but the TX is defined only on 0 and 2. It is an important consideration when you choose the pins to use.

For reference, see the table I used to select the SERCOM to assign.

Enough of theory, go for the solution...

Add a hardware serial on pins 5 (RX) and 6 (TX) of the Arduino Nano 33 IoT:

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

Uart mySerial (&sercom0, 5, 6, SERCOM_RX_PAD_1, UART_TX_PAD_0);

// Attach the interrupt handler to the SERCOM
void SERCOM0_Handler()
{
    mySerial.IrqHandler();
}

void setup() {
  // Reassign pins 5 and 6 to SERCOM alt
  pinPeripheral(5, PIO_SERCOM_ALT);
  pinPeripheral(6, PIO_SERCOM_ALT);

  // Start my new hardware serial
  mySerial.begin(9600);
}

void loop() {
  // Do something with mySerial...
}

Another example, add a hardware serial on pins 13 (RX) and 8 (TX) of the Arduino Nano 33 IoT:

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

Uart mySerial (&sercom1, 13, 8, SERCOM_RX_PAD_1, UART_TX_PAD_2);

// Attach the interrupt handler to the SERCOM
void SERCOM1_Handler()
{
    mySerial.IrqHandler();
}

void setup() {
  // Reassign pins 13 and 8 to SERCOM (not alt this time)
  pinPeripheral(13, PIO_SERCOM);
  pinPeripheral(8, PIO_SERCOM);

  // Start my new hardware serial
  mySerial.begin(9600);
}

void loop() {
  // Do something with mySerial...
}
1
votes

I asked the same question on the official Arduino Github project and Martino Facchin gave me the solution:

UART mySerial(digitalPinToPinName(4), digitalPinToPinName(3), NC, NC);

Note that "Uart mySerial" should be written in uppercase "UART mySerial", otherwise the compiler won't find the lib

More about the solution and core modifications: https://github.com/arduino/ArduinoCore-nRF528x-mbedos/issues/38