Blinky Arduino Zero

samd21g arduino blinky zero

Pre-requisites

Crystalless option

Create a blinky LED firmware with SAMD21G micro-controller on a custom PCB without crystal.

To ensure the blinky works with the crytalless option, you have to:

  1. Ensure the bootloader code has the crystalless option
  2. Ensure compiled code has the cyrstalless option in build.extra_flags in ~/Library/Arduino15/packages/arduino/hardware/samd/1.8.6/boards.txt on macOS or as part of options in the arduino-cli command
arduino-cli compile --fqbn arduino:samd:arduino_zero_native --build-properties build.extra_flags="-DCRYSTALLESS -D__SAMD21G18A__ {build.usb_flags}" ./

Serial

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).

Upload firmware

  Steps to upload the blinky firmware:

  1. Press the reset button twice to go into the bootloader mode
  2. Run make to upload the blinky firmware with crystalless option

Code

Download code
#define LED 13

void setup() {
  pinMode(LED, OUTPUT);

  // SerialUSB.begin(9600);
  // while (!SerialUSB) {}
  // delay(1000);

  // SerialUSB.println("Start!");
}

void loop() {
  // SerialUSB.println("HIGH");
  digitalWrite(LED, HIGH);
  delay(200);

  // SerialUSB.println("LOW");
  digitalWrite(LED, LOW);
  delay(200);
}

Makefile

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

.PHONY: default lint all flash clean

default: lint all flash clean

lint:
	cpplint --extensions=ino --filter=-legal/copyright,-whitespace/line_length,-readability/casting,-readability/todo *.ino

all:
	# This custom PCB does not have a crytal on pins PA00 and PA01
	# Hence, use -DCRYSTALLESS to replace the extra_flags in boards.txt
	arduino-cli compile --fqbn $(BOARD) --build-properties build.extra_flags="-DCRYSTALLESS -D__SAMD21G18A__ {build.usb_flags}" ./

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

clean:
	rm -r build

Prototype

A photo of the actual setup.

Blinky Arduino Zero prototype

Schematic

Wire up the hardware accordingly

Blinky Arduino Zero schematic

References