Metro express M0

Please tell us which board you are using.
For CircuitPython issues, ask in the Adafruit CircuitPython forum.

Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.
Locked
User avatar
EdCantillo
 
Posts: 3
Joined: Tue Nov 08, 2022 3:49 pm

Metro express M0

Post by EdCantillo »

Hi Adafruit tech support,

I have a metro express M0 running circuitpython version 7.3.3
I installed adafruit-circuitpython-metro_m0_express-en_US-7.3.3.uf2
I updated the libraries using the lib bundle adafruit-circuitpython-bundle-7.x-mpy-20221107.zip

I am getting the following error
Traceback (most recent call last):
File "main.py", line 42, in <module>
AttributeError: 'module' object has no attribute 'Servo'

here's the code in main.py
# Servo on D5
servo = simpleio.Servo(board.D5)

Can some please provide some assistance with this issue
Thank you.
Ed Cantillo

User avatar
mikeysklar
 
Posts: 13936
Joined: Mon Aug 01, 2016 8:10 pm

Re: Metro express M0

Post by mikeysklar »

You want to use Adafruit_Motor now not simpleio.

You will need to copy over the library and import it in the code.py

This guide will help.

https://learn.adafruit.com/circuitpytho ... thon-servo

Code: Select all

# SPDX-FileCopyrightText: 2018 Kattni Rembor for Adafruit Industries
#
# SPDX-License-Identifier: MIT

"""CircuitPython Essentials Servo standard servo example"""
import time
import board
import pwmio
from adafruit_motor import servo

# create a PWMOut object on Pin A2.
pwm = pwmio.PWMOut(board.A2, duty_cycle=2 ** 15, frequency=50)

# Create a servo object, my_servo.
my_servo = servo.Servo(pwm)

while True:
    for angle in range(0, 180, 5):  # 0 - 180 degrees, 5 degrees at a time.
        my_servo.angle = angle
        time.sleep(0.05)
    for angle in range(180, 0, -5): # 180 - 0 degrees, 5 degrees at a time.
        my_servo.angle = angle
        time.sleep(0.05)

User avatar
EdCantillo
 
Posts: 3
Joined: Tue Nov 08, 2022 3:49 pm

Re: Metro express M0

Post by EdCantillo »

thank you for the reply much appreciated.

Actually I am trying to the main.py working. this was included after I installed the 7.3.3

it would be nice to have the sample code that came with the Adafruit Metro M0 express.

thank you
-Ed

User avatar
mikeysklar
 
Posts: 13936
Joined: Mon Aug 01, 2016 8:10 pm

Re: Metro express M0

Post by mikeysklar »

The sample code I provided above is what you would populate a main.py file with to control a stepper.

I’m not sure what the exact sample code that is currently shipping on the Metro M0 Express. My guess would be a basic blink example like this:

Code: Select all

 // the setup function runs once when you press reset or power the board
void setup() {
  // initialize digital pin 13 as an output.
  pinMode(13, OUTPUT);
}

// the loop function runs over and over again forever
void loop() {
  digitalWrite(13, HIGH);   // turn the LED on (HIGH is the voltage level)
  delay(1000);              // wait for a second
  digitalWrite(13, LOW);    // turn the LED off by making the voltage LOW
  delay(1000);              // wait for a second
}
https://learn.adafruit.com/adafruit-met ... nk-2854174

Locked
Please be positive and constructive with your questions and comments.

Return to “Metro, Metro Express, and Grand Central Boards”