serial communication on the arduino nano iot

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

This feature is offered by the Atmel SAMD21G and it is called I/O multiplexing. The microcontroller provides 6 SERCOM that you can assign to most 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)

That does mean that SERCOM0 and SERCOM1 are still available and can be used

One of the advantages of the Arduino platform is the simplification of the hadware, assigning to each microcontroller pin one of the many possible functions. You can find the various functions assigned to each pin in the variant.cpp file of each board

Focusing our attention on the SERCOM related pins we can extract the following information from the

https://github.com/arduino/ArduinoCore-samd/blob/master/variants/nano_33_iot/variant.cpp

Look at the Perip.C SERCOMx (x/PAD) and Perip.D SERCOMx (x/PAD) columns

Code

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

 

[codesyntax lang=”cpp”]

#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 here
}

[/codesyntax]

 

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

 

[codesyntax lang=”cpp”]

#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 mySeria here
}

[/codesyntax]

 

Related posts

Examples on how to optimize Arduino memory usage

MH-ET LIVE Tiny88 : an Arduino Compatible development board

Nano33 IoT and WiFi example