0

Adafruit METRO M0 Express
Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.

Adafruit METRO M0 Express

by 1885 on Mon Apr 16, 2018 8:15 am

https://www.adafruit.com/product/3505
Adafruit METRO M0 Express - designed for CircuitPython - ATSAMD21G18
I just got a METRO/CircuitPython

3 QUESTION?
#1. If I use python all that is needed is to drop the code in the CIRCITPY directory ?
Right?
Here is the link I am using: https://github.com/adafruit/METROX-CircuitPython
and is the neo pixel RGBW supported with the default code?

#2. If I wish to use arduino code ( *.ino files. ) it looks like some other drivers need to be installed.
Correct?

#3 If I need to reinstall circuitpython . Is this the link:
https://github.com/adafruit/circuitpython
Has circuit python been fully installed?


I noticed the python code example:

Code: Select all | TOGGLE FULL SIZE
# Metro IO demo
# Welcome to CircuitPython 2.2.0 :)

import board
import time
import neopixel
from digitalio import DigitalInOut, Direction, Pull
from analogio import AnalogIn
import audioio
import touchio
import simpleio

# keyboard support
from adafruit_hid.keyboard import Keyboard
from adafruit_hid.keycode import Keycode

# One pixel connected internally!
dot = neopixel.NeoPixel(board.NEOPIXEL, 1, brightness=0.2)

# Built in red LED
led = DigitalInOut(board.D13)
led.direction = Direction.OUTPUT

# Analog audio output on A0, using two audio files
audiofiles = ["rimshot.wav", "laugh.wav"]

# Analog input on A1
analog1in = AnalogIn(board.A1)

# Capacitive touch on A2
touch = touchio.TouchIn(board.A2)

# Digital input with pullup on D2, D3, and D4
buttons = []
for p in [board.D2, board.D3, board.D4]:
    button = DigitalInOut(p)
    button.direction = Direction.INPUT
    button.pull = Pull.UP
    buttons.append(button)

# Servo on D5
servo = simpleio.Servo(board.D5)

# NeoPixel strip (of 16 LEDs) connected on D6
NUMPIXELS = 16
neopixels = neopixel.NeoPixel(board.D6, NUMPIXELS, brightness=0.2, auto_write=False)

# Used if we do HID output, see below
kbd = Keyboard()

######################### HELPERS ##############################

# Helper to convert analog input to voltage
def getVoltage(pin):
    return (pin.value * 3.3) / 65536

# Helper to give us a nice color swirl
def wheel(pos):
    # Input a value 0 to 255 to get a color value.
    # The colours are a transition r - g - b - back to r.
    if (pos < 0):
        return [0, 0, 0]
    if (pos > 255):
        return [0, 0, 0]
    if (pos < 85):
        return [int(pos * 3), int(255 - (pos*3)), 0]
    elif (pos < 170):
        pos -= 85
        return [int(255 - pos*3), 0, int(pos*3)]
    else:
        pos -= 170
        return [0, int(pos*3), int(255 - pos*3)]

def play_file(filename):
    print("")
    print("----------------------------------")
    print("playing file "+filename)
    f = open(filename, "rb")
    a = audioio.AudioOut(board.A0, f)
    a.play()
    while a.playing:
        pass
    print("finished")
    print("----------------------------------")
   
######################### MAIN LOOP ##############################

i = 0
while True:
  # spin internal LED around! autoshow is on
  dot[0] = wheel(i & 255)

  # also make the neopixels swirl around
  for p in range(NUMPIXELS):
      idx = int ((p * 256 / NUMPIXELS) + i)
      neopixels[p] = wheel(idx & 255)
  neopixels.show()

  # Read analog voltage on A1
  print("A1: %0.2f" % getVoltage(analog1in), end="\t")

  # use A2 as capacitive touch to turn on internal LED
  print("A2 touch: %d" % touch.raw_value, end="\t")
  if touch.value:
      print("A2 touched!", end ="\t")
  led.value = touch.value

  if not buttons[0].value:
      print("Button D2 pressed!", end ="\t")
      # optional! uncomment below & save to have it sent a keypress
      #kbd.press(Keycode.A)
      #kbd.release_all()

  if not buttons[1].value:
      print("Button D3 pressed!", end ="\t")
      play_file(audiofiles[0])

  if not buttons[2].value:
      print("Button D4 pressed!", end ="\t")
      play_file(audiofiles[1])

  # sweep a servo from 0-180 degrees (map from 0-255)
  servo.angle = simpleio.map_range(i, 0, 255, 0, 180)
 
  i = (i+1) % 256  # run from 0 to 255
  #time.sleep(0.01) # make bigger to slow down

  print("")

1885
 
Posts: 88
Joined: Sun May 24, 2009 2:12 am

Re: Adafruit METRO M0 Express

by tannewt2 on Mon Apr 16, 2018 1:18 pm

1885 wrote:https://www.adafruit.com/product/3505
Adafruit METRO M0 Express - designed for CircuitPython - ATSAMD21G18
I just got a METRO/CircuitPython

3 QUESTION?
#1. If I use python all that is needed is to drop the code in the CIRCITPY directory ?
Right?
Here is the link I am using: https://github.com/adafruit/METROX-CircuitPython
and is the neo pixel RGBW supported with the default code?

It is supported by the NeoPixel driver: https://github.com/adafruit/Adafruit_Ci ... _NeoPixel/

The third example in the README has an example for RGBW.

1885 wrote:#2. If I wish to use arduino code ( *.ino files. ) it looks like some other drivers need to be installed.
Correct?

Setup for Arduino is covered here: https://learn.adafruit.com/adafruit-met ... -ide-setup

Simply upload sketch and it will overwrite CircuitPython. To reinstall CircuitPython you can double tap to get to the bootloader and then drag the uf2 from the link below onto the drive.

1885 wrote:#3 If I need to reinstall circuitpython . Is this the link:
https://github.com/adafruit/circuitpython
Has circuit python been fully installed?


It came preinstalled if you have that file. You can update it from https://github.com/adafruit/circuitpyth ... ses/latest. Make sure to save the files from the drive first in case they get erased by the update.

tannewt2
 
Posts: 867
Joined: Thu Oct 06, 2016 8:48 pm

Re: Adafruit METRO M0 Express

by 1885 on Tue Apr 17, 2018 12:03 am

Thank you very much!

1885
 
Posts: 88
Joined: Sun May 24, 2009 2:12 am

Please be positive and constructive with your questions and comments.