Adafruit M4 boards

The Adafruit Metro M4, Adafruit ItsyBitsy M4, and Adafruit Feather M4 are each based on the ATSAMD51 ARM Cortex M4 microcontroller running at 120 MHz, but with different physical form factors.

Each board provides 512 KB flash and 192 KB RAM. The boards also include a separate 2 MB SPI DataFlash chip which is used by uLisp to allow you to save the Lisp image using (save-image).

These are currently recommended as the fastest platforms supporting uLisp. For example, the Arduino Zero runs the Tak benchmark in 10 secs, and the Adafruit ItsyBitsy takes 4.1 secs; see Performance.

Adafruit Metro M4

The Adafruit Metro M4 is the same size as the original Arduino Uno, and so can take a range of Arduino shields.

MetroM4.jpg

LEDs

The Adafruit Metro M4 has a red LED connected to the digital pin 13 which you can flash with the following program:

(defun blink (x)
  (pinmode 13 t)
  (digitalwrite 13 x)
  (delay 1000)
  (blink (not x)))

Run it by typing:

(blink t)

Pin 13 can also be used as an analogue pin, so you can pulsate the red LED slowly on and off with the program:

(defun pulse ()
  (let (down)
    (loop
     (dotimes (x 256) 
       (delay 5) 
       (analogwrite 13 (if down (- 255 x) x)))
     (setq down (not down)))))

Run it by typing:

(pulse)

Exit from either program by entering ~.

Adafruit ItsyBitsy M4

The Adafruit ItsyBitsy M4 is the smallest of the three boards, the same size as Adafruit's other ItsyBitsy boards.

ItsyBitsy.jpg

LEDs

The Adafruit ItsyBitsy M4 also has a red LED connected to the digital pin 13 which you can flash with the following program:

(defun blink (x)
  (pinmode 13 t)
  (digitalwrite 13 x)
  (delay 1000)
  (blink (not x)))

Run it by typing:

(blink t)

Pin 13 can also be used as an analogue pin, so you can pulsate the red LED slowly on and off with the program:

(defun pulse ()
  (let (down)
    (loop
     (dotimes (x 256) 
       (delay 5) 
       (analogwrite 13 (if down (- 255 x) x)))
     (setq down (not down)))))

Run it by typing:

(pulse)

Exit from either program by entering ~.

DotStar RGB LED

The Adafruit ItsyBitsy M4 has a DotStar (APA102) RGB LED mounted on the board. For more information about DotStar LEDs see Driving DotStar RGB LEDs.

Here's a program to set the LED to an arbitrary colour and brightness:

First we define variables for the clock and data pins; these are connected to Arduino pins 8 (data) and 6 (clock):

(defvar clk 6)
(defvar data 8)

Here's a routine to send a byte to the display, MSB first, toggling the clock pin after each bit:

(defun send (byte)
  (dotimes (i 8)
    (digitalwrite clk 0)
    (digitalwrite data (logand (ash byte (- i 7)) 1))
    (digitalwrite clk 1)))

Finally here's the function to send the appropriate stream of bits to the LED to define its colour and brightness:

(defun dotstar (bri blue green red)
(pinmode clk t) (pinmode data t) (mapc send (list 0 0 0 0 (logior bri #xe0) blue green red #xff)))

To set the LED evaluate:

(dotstar bri blue green red)

where bri is the brightness (from 0 to 31), and blue, green, and red are the colour components, from 0 to 255. For example, this sets the LED to magenta (blue+red) at low brightness:

(dotstar 1 255 0 255)

Adafruit Feather M4

The Adafruit Feather M4 is the same size as Adafruit's Feather range of boards, with its own family of matching shields.

Although I haven't had a chance to test one of these, it should be identical in behaviour to the Arduino Metro M4.