Blinky Arduino M0

Updated on 13 October 2022
dev board RobotDyn M0 mini
firmware Arduino
chip SAMD21
This tutorial is more than 1 year old. If the steps below do not work, then please check the latest versions and the documentations of the individual tools used.

Before starting

Dependancies

Ensure the following dependancies are downloaded and available:

Buy the components

Code

Download code blinky-m0.ino
void setup() {
  pinMode(LED_BUILTIN, OUTPUT);

  SerialUSB.begin(9600);
  // Blinky will not start unless serial prints are enabled
  // while (!SerialUSB) { }
  delay(100);

  SerialUSB.println("Start!");
}

void loop() {
  SerialUSB.println("HIGH");
  digitalWrite(LED_BUILTIN, HIGH);
  delay(500);

  SerialUSB.println("LOW");
  digitalWrite(LED_BUILTIN, LOW);
  delay(500);
}

Makefile

BOARD?=arduino:samd:mzero_bl
PORT := $(shell ls /dev/cu.usbmodem*)

.PHONY: default lint all flash clean

default: lint all flash clean

lint:
	cpplint --extensions=ino --filter=-legal/copyright *.ino

all:
	arduino-cli compile --fqbn $(BOARD) ./

flash:
	arduino-cli upload -p $(PORT) --fqbn $(BOARD)

clean:
	rm -r build

Prototype

A photo of the actual setup.

Blinky Arduino M0 prototype

Arduino IDE settings

Ensure the following IDE settings before flashing.

Blinky Arduino M0 Arduino IDE settings

Serial console

Serial output from the firmware.

Blinky Arduino M0 serial console

Description

Create a blinky LED with RobotDyn’s M0-Mini board which is compatible with Arduino firmware.

For serial printing, SerialUSB.println() should be used instead of Serial.println() because SerialUSB uses the Native Port, which is an emulated serial port (USB-CDC).

The following code should be used for initialising the serial so that the print statements can be viewed in the setup():

SerialUSB.begin(9600);
while (!SerialUSB) { }

Some errors on RobotDyn M0 mini board

  • Pins D2 (PA14) and D4 (PA08) are swapped
  • Pin D12 / MISO on ICSP header is PA12

References

Watch