Go Down

Topic: Software Serial library for MKR1000 (Read 4551 times) previous topic - next topic


Hi all,

Love the MKR1000 so far. I'm finding it quite a nice little board.

The roadblock I hit with my project was that the MKR1000 only has one serial port. As there was no official software serial library yet, I started to modify the NewSoftSerial library for the MKR1000. So far I have successfully been able to receive serial data up to 57600 baud, however the TX side does not seem to work. I feel like it's something simple I'm overlooking for the TX, so suggestions would be welcome.

Hopefully this helps someone until a more official library is worked out.




It may not be the answer you were looking for but its the one I am giving based on either experience, educated guess, google or the fact that you gave nothing to go with in the first place so I used my wonky crystal ball.


May 17, 2016, 06:21 pm Last Edit: May 19, 2016, 05:03 pm by MartinL
There isn't a software serial library, but fortunately you can configure the SAMD21's spare serial communciation (SERCOM) modules to obtain multiple hardware serial ports. The SAMD21 has 6 (0..5) flexible SERCOM modules that can be configured either as an I2C, SPI or Serial port. Looking at the MKR1000's "variant.cpp" file it looks as though 3 are currently in use, that's:

Sercom 0 - I2C
Sercom 1 - SPI
Sercom 5 - Serial1

That leaves Sercom 2, 3 and 4 that are free to be configured how you wish.

Here's an Adafruit article, (it's for their Adafruit Feather M0, but it uses the same SAMD21G18A processor): https://learn.adafruit.com/using-atsamd21-sercom-to-add-more-spi-i2c-serial-ports/creating-a-new-serial

The article also tells you how to configure the SERCOM modules to add additional I2C and SPI ports.

The code to set-up MKR1000's Serial2 (using SERCOM3) on digital pins 0 (TX) and 1 (RX) should go something like this:

Code: [Select]
#include <Arduino.h>                              // required before wiring_private.h
#include <wiring_private.h>

// Serial2 pin and pad definitions (in Arduino files Variant.h & Variant.cpp)
#define PIN_SERIAL2_RX       (1ul)                // Pin description number for PIO_SERCOM on D1
#define PIN_SERIAL2_TX       (0ul)                // Pin description number for PIO_SERCOM on D0
#define PAD_SERIAL2_TX       (UART_TX_PAD_0)      // SERCOM pad 0 TX
#define PAD_SERIAL2_RX       (SERCOM_RX_PAD_1)    // SERCOM pad 1 RX

// Instantiate the Serial2 class

void setup()
  Serial2.begin(115200);          // Begin Serial2
  pinPeripheral(0, PIO_SERCOM);   // Assign pins 0 & 1 SERCOM functionality
  pinPeripheral(1, PIO_SERCOM);

void loop()
  if (Serial2.available())        // Check if incoming data is available
    byte byteRead = Serial2.read();    // Read the most recent byte
    Serial2.write(byteRead);           // Echo the byte back out on the serial port

void SERCOM3_Handler()    // Interrupt handler for SERCOM3

According to Adafruit you need to include "Arduino.h". I got the code to compile without it, so it's probably unnecessary, but as I don't own a MKR1000 can't confirm whether this include can be omitted.


Awesome, thanks! Far better than using software serial. I will try this out soon.


Jun 26, 2016, 12:49 pm Last Edit: Jun 26, 2016, 02:07 pm by tkuehn
Tested and working! Thanks MartinL!

I created a test sketch with two extra serial ports if anyone needs to get started. This gives Serial (USB), Serial 1, Serial 2 and Serial 3.


Pretty cool that the MKR1000 can do this.



Sep 07, 2016, 12:34 pm Last Edit: Sep 07, 2016, 12:43 pm by AndreaRichetta
You can check also this tutorial we've created:


Awesome, thanks! Far better than using software serial. I will try this out soon.
I would like to know why you got multiple Tx and Rx defined?


Hi abdallaziz92,

The definitions are for both the TX and RX pads and pins.

The SERCOM peripheral IO is generated on 4 internal pads. These pads can then be connected to physical pins of the device, by setting the TXPO (Transmit Data Pinout) and RXPO (Receive Data Pinout) bitfields in the SERCOM's CTRLA (Control A) register.

The defines just determine what pad is connected to what pin.

Go Up