Motors
You can use both dc motors and servo motors with Stemi shield.
DC motors
Stemi shield can control up to 2 DC motors (Pumps in IOT).
Library
For simple usage DigitalIO can be used to turn it on or off, but if you want more precise control you can use PWM.
Motor is controlled with 2 pins M1(IO7, IO8) and M2(IO5/IO6). To make it spin in one direction turn on one pin and turn off the other and vice versa.
Example
digitalio_example.py
import board
from stemi.digitalio import DigitalInOut, Direction
motorA = DigitalInOut(board.IO5)
motorA.direction = Direction.OUTPUT
motorB = DigitalInOut(board.IO6)
motorB.direction = Direction.OUTPUT
# Setup motor 1
motorA.value = 0
motorB.value = 0
# Clockwise
motorA.value = 1
motorB.value = 0
time.sleep(1)
# Counter-clockwise
motorA.value = 0
motorB.value = 1
time.sleep(1)
# Off
motorA.value = 0
motorB.value = 0
time.sleep(1)
pwm_example.py
import board
from stemi.pwmio import PWMOut
pwmA = PWMOut(board.IO5, duty_cycle=2 ** 16 - 1, frequency=50)
pwmB = PWMOut(board.IO6, duty_cycle=2 ** 16 - 1, frequency=50)
# Off
pwmA.duty_cycle = 0
pwmB.duty_cycle = 0
pwmA.duty_cycle = 0 # 0% duty cycle (off)
time.sleep(1)
pwmA.duty_cycle = int((2 ** 16 - 1) / 2 ) # 50% duty cycle (half on)
time.sleep(1)
pwmA.duty_cycle = 2 ** 16 - 1 # 100% duty cycle (on)
time.sleep(1)
Servo motors
Library
Library for servos is provided by Adafruit.
Example
main.py
import board
from stemi.pwmio import PWMOut
from adafruit_motor import servo
pwm = PWMOut(board.IO10, duty_cycle=2 ** 16 - 1, frequency=50)
my_servo = servo.Servo(pwm)
my_servo.angle = 60