예제 #1
0
 def _drive(self, terminal):
     device = self._devices.get(terminal, None)
     if not isinstance(device, PWMOut):
         device = PWMOut(self._seesaw, terminal)
         device.frequency = 1000
         self._devices[terminal] = device
     return device
예제 #2
0
 def _servo(self, terminal, servo_class):
     device = self._devices.get(terminal, None)
     if not isinstance(device, servo_class):
         pwm = PWMOut(self._seesaw, terminal)
         pwm.frequency = 50
         device = servo_class(pwm)
         self._devices[terminal] = device
     return device
예제 #3
0
 def __init__(
     self,
     address: int = 0x5E,
     i2c: Optional[I2C] = None,
     spi: Optional[SPI] = None,
     cs: Optional[Pin] = None,
     dc: Optional[Pin] = None,
 ):
     displayio.release_displays()
     if i2c is None:
         i2c = board.I2C()
     if spi is None:
         spi = board.SPI()
     if cs is None:
         cs = board.D5
     if dc is None:
         dc = board.D6
     self._ss = Seesaw(i2c, address)
     self._ss.pin_mode_bulk(self._button_mask, self._ss.INPUT_PULLUP)
     self._ss.pin_mode(8, self._ss.OUTPUT)
     self._ss.digital_write(8, True)  # Reset the Display via Seesaw
     self._backlight = PWMOut(self._ss, 5)
     self._backlight.duty_cycle = 0
     display_bus = displayio.FourWire(spi, command=dc, chip_select=cs)
     self.display = ST7735R(display_bus,
                            width=160,
                            height=80,
                            colstart=24,
                            rotation=270,
                            bgr=True)
예제 #4
0
 def _motor(self, terminals, motor_class):
     device = self._devices.get(terminals, None)
     if not isinstance(device, motor_class):
         device = motor_class(*(PWMOut(self._seesaw, terminal)
                                for terminal in terminals))
         self._devices[terminals] = device
     return device
 def __init__(self, address=0x5E, i2c=None, spi=None):
     if i2c is None:
         i2c = board.I2C()
     if spi is None:
         spi = board.SPI()
     self._ss = Seesaw(i2c, address)
     self._backlight = PWMOut(self._ss, 5)
     self._backlight.duty_cycle = 0
     displayio.release_displays()
     while not spi.try_lock():
         pass
     spi.configure(baudrate=24000000)
     spi.unlock()
     self._ss.pin_mode(8, self._ss.OUTPUT)
     self._ss.digital_write(8, True)  # Reset the Display via Seesaw
     display_bus = displayio.FourWire(spi,
                                      command=board.D6,
                                      chip_select=board.D5)
     self.display = ST7735R(display_bus,
                            width=160,
                            height=80,
                            colstart=24,
                            rotation=270,
                            bgr=True)
     self._ss.pin_mode_bulk(self._button_mask, self._ss.INPUT_PULLUP)
예제 #6
0
cpx_audio = audioio.AudioOut(board.A0)


def play_file(wavfile):
    with open(wavfile, "rb") as f:
        wav = audioio.WaveFile(f)
        cpx_audio.play(wav)
        while cpx_audio.playing:
            pass


#################### 4 Servos
servos = []
for ss_pin in (17, 16, 15, 14):
    pwm = PWMOut(ss, ss_pin)
    pwm.frequency = 50
    _servo = servo.Servo(pwm)
    _servo.angle = 90  # starting angle, middle
    servos.append(_servo)

# Which servos to actuate for each number
counting = [[3], [2], [3, 2], [1], [1, 3], [1, 2], [3, 2, 1], [0], [0, 3],
            [0, 2], [0, 3, 2], [0, 1], [0, 3, 1], [0, 2, 1], [0, 3, 2, 1]]

play_file(introfile)

while True:
    if not switch.value:
        continue
예제 #7
0
buttona = DigitalInOut(board.BUTTON_A)
buttona.direction = Direction.INPUT
buttona.pull = Pull.DOWN

buttonb = DigitalInOut(board.BUTTON_B)
buttonb.direction = Direction.INPUT
buttonb.pull = Pull.DOWN

BOTTOM_SENSOR = 2
TOP_SENSOR = 3
seesaw.pin_mode(BOTTOM_SENSOR, seesaw.INPUT_PULLUP)
seesaw.pin_mode(TOP_SENSOR, seesaw.INPUT_PULLUP)

# Create one stepper motor using the 4 'drive' PWM pins 13, 43, 12 and 42
pwms = [
    PWMOut(seesaw, 13),
    PWMOut(seesaw, 43),
    PWMOut(seesaw, 12),
    PWMOut(seesaw, 42)
]
for p in pwms:
    p.frequency = 2000
stepper_motor = stepper.StepperMotor(pwms[0], pwms[1], pwms[2], pwms[3])

pixels = neopixel.NeoPixel(board.NEOPIXEL, 10, brightness=1)
pixels.fill((0, 0, 0))


def rainbow():
    pixels.fill((20, 0, 0))
    time.sleep(0.05)
예제 #8
0
# Create seesaw object for Circuit Playground Express to talk to Crickit
i2c = I2C(board.SCL, board.SDA)
seesaw = Seesaw(i2c)

led = DigitalInOut(board.D13)  # Set up Red LED
led.direction = Direction.OUTPUT

button_A = DigitalInOut(board.BUTTON_A)  # Set up switch A
button_A.direction = Direction.INPUT
button_A.pull = Pull.DOWN

# Create servos list
servos = []
for ss_pin in (17, 16):  # Only use 2 servos, append , 15, 14 if using 4
    pwm = PWMOut(seesaw, ss_pin)
    pwm.frequency = 50
    _servo = servo.Servo(pwm, min_pulse=600, max_pulse=2500)
    _servo.angle = 90  # starting angle, middle
    servos.append(_servo)


def servo_front(direction):
    if direction > 0:
        index = 50
        while index <= 100:
            servos[1].angle = index
            time.sleep(0.040)
            index = index + 2
    if direction < 0:
        index = 100
예제 #9
0
import time
from busio import I2C
from adafruit_seesaw.seesaw import Seesaw
from adafruit_seesaw.pwmout import PWMOut
from adafruit_motor import motor, servo
from digitalio import DigitalInOut, Direction, Pull
import board

print("Mag Neat-o!")

# Create seesaw object
i2c = I2C(board.SCL, board.SDA)
seesaw = Seesaw(i2c)

# Create one motor on seesaw PWM pins 22 & 23
motor_a = motor.DCMotor(PWMOut(seesaw, 22), PWMOut(seesaw, 23))
# Create another motor on seesaw PWM pins 19 & 18
motor_b = motor.DCMotor(PWMOut(seesaw, 19), PWMOut(seesaw, 18))

# Create servo object
pwm = PWMOut(seesaw, 17)  # Servo 1 is on s.s. pin 17
pwm.frequency = 50  # Servos like 50 Hz signals
my_servo = servo.Servo(pwm)  # Create my_servo with pwm signa
my_servo.angle = 90


def smooth_move(start, stop, num_steps):
    return [(start + (stop - start) * i / num_steps) for i in range(num_steps)]


buttona = DigitalInOut(board.BUTTON_A)
import time
import busio
import board
from adafruit_seesaw.seesaw import Seesaw
from adafruit_seesaw.pwmout import PWMOut
from adafruit_motor import servo
import adafruit_lsm9ds0

# Setup hardware
i2c = busio.I2C(board.SCL, board.SDA)

sensor = adafruit_lsm9ds0.LSM9DS0_I2C(i2c)
seesaw = Seesaw(i2c)

# Create servo objects
pwm1 = PWMOut(seesaw, 17)
pwm1.frequency = 50
servo1 = servo.Servo(pwm1, min_pulse=500, max_pulse=2500)

# Center the servo
servo1.angle = 90

while True:
    # Read the accel
    x, y, z = sensor.acceleration

    # Clip the value
    if y < -10:
        y = -10
    if y > 10:
        y = 10
예제 #11
0
from adafruit_seesaw.pwmout import PWMOut
from adafruit_motor import servo
import neopixel
import board

# create accelerometer
i2c1 = I2C(board.ACCELEROMETER_SCL, board.ACCELEROMETER_SDA)
lis3dh = adafruit_lis3dh.LIS3DH_I2C(i2c1, address=0x19)
lis3dh.range = adafruit_lis3dh.RANGE_8_G

# Create seesaw object
i2c = I2C(board.SCL, board.SDA)
seesaw = Seesaw(i2c)

# Create servo object
pwm = PWMOut(seesaw, 17)    # Servo 1 is on s.s. pin 17
pwm.frequency = 50          # Servos like 50 Hz signals
my_servo = servo.Servo(pwm) # Create my_servo with pwm signal

# LED for debugging
led = DigitalInOut(board.D13)
led.direction = Direction.OUTPUT

# two buttons!
button_a = DigitalInOut(board.BUTTON_A)
button_a.direction = Direction.INPUT
button_a.pull = Pull.DOWN
button_b = DigitalInOut(board.BUTTON_B)
button_b.direction = Direction.INPUT
button_b.pull = Pull.DOWN
# For the QT Py RP2040, QT Py ESP32-S2, other boards that have SCL1/SDA1 as the STEMMA QT port.
# import busio
# i2c = busio.I2C(board.SCL1, board.SDA1)
arcade_qt = Seesaw(i2c, addr=0x3A)

# Button pins in order (1, 2, 3, 4)
button_pins = (18, 19, 20, 2)
buttons = []
for button_pin in button_pins:
    button = DigitalIO(arcade_qt, button_pin)
    button.direction = digitalio.Direction.INPUT
    button.pull = digitalio.Pull.UP
    buttons.append(button)

# LED pins in order (1, 2, 3, 4)
led_pins = (12, 13, 0, 1)
leds = []
for led_pin in led_pins:
    led = PWMOut(arcade_qt, led_pin)
    leds.append(led)

while True:
    for led_number, button in enumerate(buttons):
        if not button.value:
            for cycle in range(0, 65535, 8000):
                leds[led_number].duty_cycle = cycle
                time.sleep(delay)
            for cycle in range(65534, 0, -8000):
                leds[led_number].duty_cycle = cycle
                time.sleep(delay)
예제 #13
0
class DummyAudio:
    def play(self, f, loop=False):
        pass

    def stop(self):
        pass

    def mute(self, mute):
        pass


i2c = board.I2C()
ss = Seesaw(i2c, 0x5E)
spi = board.SPI()
displayio.release_displays()
while not spi.try_lock():
    pass
spi.configure(baudrate=24000000)
spi.unlock()
ss.pin_mode(8, ss.OUTPUT)
ss.digital_write(8, True) # reset display
display_bus = displayio.FourWire(spi, command=board.D6, chip_select=board.D5)
display = displayio.Display(display_bus, _INIT_SEQUENCE, width=160, height=80,
                            rowstart=24)
del _INIT_SEQUENCE
buttons = GamePadSeesaw(ss)
audio = DummyAudio()
backlight = PWMOut(ss, 5)
backlight.duty_cycle = 0
예제 #14
0
import audioio
import microcontroller
import board
import time

i2c = I2C(board.SCL, board.SDA)
ss = Seesaw(i2c)

print("Yanny or Laurel data logging!")

LOOKATPERSON = 90
LOOKLEFT = 60
LOOKRIGHT = 120

#################### 1 Servo
pwm = PWMOut(ss, 17)
pwm.frequency = 50
myservo = servo.Servo(pwm)
myservo.angle = LOOKATPERSON  # introduce yourself

#################### 2 buttons w/2 LEDs
BUTTON_1 = 2
BUTTON_2 = 3
LED_1 = 8
LED_2 = 9

# Two buttons are pullups, connect to ground to activate
ss.pin_mode(BUTTON_1, ss.INPUT_PULLUP)
ss.pin_mode(BUTTON_2, ss.INPUT_PULLUP)
# Two LEDs are outputs, on by default
ss.pin_mode(LED_1, ss.OUTPUT)
# switch
switch = DigitalInOut(board.SLIDE_SWITCH)
switch.direction = Direction.INPUT
switch.pull = Pull.UP

# We need some extra captouches
touch2 = touchio.TouchIn(board.A2)
touch3 = touchio.TouchIn(board.A3)

# LED for debugging
led = DigitalInOut(board.D13)
led.direction = Direction.OUTPUT

# Create drive (PWM) object
INFRARED_LED_SS = 13
my_drive = PWMOut(seesaw, INFRARED_LED_SS)  # Drive 1 is on s.s. pin 13
my_drive.frequency = 1000  # Our default frequency is 1KHz

CAPTOUCH_THRESH = 850

# Commands, each 8 bit command is preceded by the 5 bit Init sequence
Init = [0, 0, 0, 1, 0]  # This must precede any command
Calibrate = [1, 0, 1, 0, 1, 0, 1, 1]  # the initial calibration
Up = [1, 0, 1, 1, 1, 0, 1, 1]  # Move arms/body down
Down = [1, 1, 1, 1, 1, 0, 1, 1]  # Move arms/body up
Left = [1, 0, 1, 1, 1, 0, 1, 0]  # Twist body left
Right = [1, 1, 1, 0, 1, 0, 1, 0]  # Twist body right
Close = [1, 0, 1, 1, 1, 1, 1, 0]  # Close arms
Open = [1, 1, 1, 0, 1, 1, 1, 0]  # Open arms
Test = [1, 1, 1, 0, 1, 0, 1, 1]  # Turns R.O.B. head LED on
예제 #16
0
파일: crickit_test.py 프로젝트: eiselekd/hw
from board import SCL, SDA
import busio
from adafruit_seesaw.seesaw import Seesaw
from adafruit_seesaw.pwmout import PWMOut
from adafruit_motor import servo

#from analogio import AnalogOut
#import board

i2c_bus = busio.I2C(SCL, SDA)
ss = Seesaw(i2c_bus)
pwm1 = PWMOut(ss, 17)
pwm2 = PWMOut(ss, 16)
pwm3 = PWMOut(ss, 15)
pwm4 = PWMOut(ss, 14)

pwm1.frequency = 50
pwm2.frequency = 50
pwm3.frequency = 50
pwm4.frequency = 50

S1 = servo.Servo(pwm1)
S2 = servo.Servo(pwm2)
S3 = servo.Servo(pwm3)
S4 = servo.Servo(pwm4)

servos = (S1, S2, S3, S4)

CRCKIT_NUM_ADC = 8
CRCKit_adc = (2, 3, 40, 41, 11, 10, 9, 8)
예제 #17
0
import board

i2c = I2C(board.SCL, board.SDA)
ss = Seesaw(i2c)

print("Crickit demo!")

# use the CPX onboard switch to turn on/off (helps calibrate)
switch = DigitalInOut(board.SLIDE_SWITCH)
switch.direction = Direction.INPUT
switch.pull = Pull.UP

#################### 4 Servos
servos = []
for ss_pin in (17, 16, 15, 14):
    pwm = PWMOut(ss, ss_pin)
    pwm.frequency = 50
    _servo = servo.Servo(pwm)
    _servo.angle = 90  # starting angle, middle
    servos.append(_servo)

#################### 2 DC motors
motors = []
for ss_pin in ((22, 23), (18, 19)):
    pwm0 = PWMOut(ss, ss_pin[0])
    pwm1 = PWMOut(ss, ss_pin[1])
    _motor = motor.DCMotor(pwm0, pwm1)
    motors.append(_motor)

servos[0].angle = 180
예제 #18
0
from adafruit_seesaw.pwmout import PWMOut
from adafruit_motor import servo, motor
import audioio
from busio import I2C
import random
import board
import time
import gc

i2c = I2C(board.SCL, board.SDA)
ss = Seesaw(i2c)

print("Feynbot demo!")

#################### 1 Servo
pwm = PWMOut(ss, 17)
pwm.frequency = 50
myservo = servo.Servo(pwm)
myservo.angle = 180   # starting angle, highest

#################### 2 Drivers
drives = []
for ss_pin in (13, 12):
    _pwm = PWMOut(ss, ss_pin)
    _pwm.frequency = 1000
    drives.append(_pwm)

#################### Audio files
wavfiles = ["01.wav", "02.wav", "03.wav", "04.wav", "05.wav"]
a = audioio.AudioOut(board.A0)
예제 #19
0
# Tilt signal LED
led = DigitalInOut(board.D13)
led.direction = Direction.OUTPUT
led.value = False

# i@c: accelerometer and CRICKIT
i2c = busio.I2C(board.SCL, board.SDA)
sensor = adafruit_lsm9ds0.LSM9DS0_I2C(i2c)
seesaw = Seesaw(i2c)

# UART
uart = busio.UART(board.TX, board.RX, baudrate=115200)

# Servos
pwm1 = PWMOut(seesaw, 17)
pwm1.frequency = 50
servo1 = servo.ContinuousServo(pwm1, min_pulse=500, max_pulse=2500)

pwm2 = PWMOut(seesaw, 16)
pwm2.frequency = 50
servo2 = servo.ContinuousServo(pwm2, min_pulse=500, max_pulse=2500)

# Stop the servos
servo1.throttle = SERVO1_ZERO_ADJUST
servo2.throttle = SERVO2_ZERO_ADJUST


def adjust(original, op, value):
    """Return an adjusted value based on the original, the operation,
       and the supplied value"""
예제 #20
0
from board import SCL, SDA
import busio
from adafruit_seesaw.seesaw import Seesaw
from adafruit_seesaw.pwmout import PWMOut
from adafruit_motor import servo

#from analogio import AnalogOut
#import board

i2c_bus = busio.I2C(SCL, SDA)
ss = Seesaw(i2c_bus)
pwm1 = PWMOut(ss, 17)
pwm2 = PWMOut(ss, 16)
pwm3 = PWMOut(ss, 15)
pwm4 = PWMOut(ss, 14)

pwm1.frequency = 50
pwm2.frequency = 50
pwm3.frequency = 50
pwm4.frequency = 50

S1 = servo.Servo(pwm1)
S2 = servo.Servo(pwm2)
S3 = servo.Servo(pwm3)
S4 = servo.Servo(pwm4)

servos = (S1, S2, S3, S4)

CRCKIT_NUM_ADC = 8
CRCKit_adc = (2, 3, 40, 41, 11, 10, 9, 8)
예제 #21
0
buttona = DigitalInOut(board.BUTTON_A)
buttona.direction = Direction.INPUT
buttona.pull = Pull.DOWN

buttonb = DigitalInOut(board.BUTTON_B)
buttonb.direction = Direction.INPUT
buttonb.pull = Pull.DOWN

BOTTOM_SENSOR = 2
TOP_SENSOR = 3
seesaw.pin_mode(BOTTOM_SENSOR, seesaw.INPUT_PULLUP)
seesaw.pin_mode(TOP_SENSOR, seesaw.INPUT_PULLUP)

# Create one stepper motor using the 4 'drive' PWM pins 13, 43, 12 and 42
pwms = [PWMOut(seesaw, 13), PWMOut(seesaw, 43), PWMOut(seesaw, 12), PWMOut(seesaw, 42)]
for p in pwms:
    p.frequency = 2000
stepper_motor = stepper.StepperMotor(pwms[0], pwms[1], pwms[2], pwms[3])

pixels = neopixel.NeoPixel(board.NEOPIXEL, 10, brightness=1)
pixels.fill((0,0,0))


def rainbow():
    pixels.fill((20,0,0))
    time.sleep(0.05)
    pixels.fill((20,20,0))
    time.sleep(0.05)
    pixels.fill((0,20,0))
    time.sleep(0.05)
seesaw = Seesaw(i2c)

# built in CPX button A
button = DigitalInOut(board.BUTTON_A)
button.direction = Direction.INPUT
button.pull = Pull.DOWN

# NeoPixels
pixels = neopixel.NeoPixel(board.A1, 10, brightness=0)
pixels.fill((0, 0, 250))

# Analog reading from Signal #1 (ss. #2)
foot_pedal = AnalogInput(seesaw, 2)

# Create one motor on seesaw PWM pins 22 & 23
motor_a = motor.DCMotor(PWMOut(seesaw, 22), PWMOut(seesaw, 23))
motor_a.throttle = 0


def map_range(x, in_min, in_max, out_min, out_max):
    # Maps a number from one range to another.
    mapped = (x - in_min) * (out_max - out_min) / (in_max - in_min) + out_min
    if out_min <= out_max:
        return max(min(mapped, out_max), out_min)
    return min(max(mapped, out_max), out_min)


# Get the audio file ready
wavfile = "unchained.wav"
f = open(wavfile, "rb")
wav = audioio.WaveFile(f)
예제 #23
0
# Use the signal port for potentiometer w/switch
MORECOW = 2  # A switch on Signal #1
SWITCH = 3  # A potentiometer on Signal #2
# Add a pullup on the switch
seesaw.pin_mode(SWITCH, seesaw.INPUT_PULLUP)

# Servo angles
BELL_START = 60
BELL_END = 75
MOUTH_START = 95
MOUTH_END = 105

# Create servos list
servos = []
for ss_pin in (17, 16):  #17 is labeled 1 on CRICKIT, 16 is labeled 2
    pwm = PWMOut(seesaw, ss_pin)
    pwm.frequency = 50  #must be 50 cannot change
    _servo = servo.Servo(pwm, min_pulse=400, max_pulse=2500)
    servos.append(_servo)
# Starting servo locations
servos[0].angle = BELL_START
servos[1].angle = MOUTH_START

# For the fog machine we actually use the PWM on the motor port cause it really needs 5V!
fog_off = PWMOut(seesaw, 22)
fog_off.duty_cycle = 0
fog_on = PWMOut(seesaw, 23)
fog_on.duty_cycle = 0

# Audio playback object and helper to play a full file
a = audioio.AudioOut(board.A0)
from busio import I2C
from adafruit_seesaw.seesaw import Seesaw
from adafruit_seesaw.pwmout import PWMOut
from adafruit_motor import motor
import board
import time

# Create seesaw object
i2c = I2C(board.SCL, board.SDA)
seesaw = Seesaw(i2c)

# Create one motor on seesaw PWM pins 22 & 23
motor_a = motor.DCMotor(PWMOut(seesaw, 22), PWMOut(seesaw, 23))
motor_a.throttle = 0.5  # half speed forward

# Create drive (PWM) object
my_drive = PWMOut(seesaw, 13)  # Drive 1 is on s.s. pin 13
my_drive.frequency = 1000  # Our default frequency is 1KHz

while True:

    my_drive.duty_cycle = 32768  # half on
    time.sleep(0.8)

    my_drive.duty_cycle = 16384  # dim
    time.sleep(0.1)

    # and repeat!
wavefiles = [file for file in os.listdir("/") if file.endswith(".wav")]
print("Audio files found: ", wavefiles)

# Create seesaw object
i2c = I2C(board.SCL, board.SDA)
seesaw = Seesaw(i2c)

led = DigitalInOut(board.D13)
led.direction = Direction.OUTPUT

# Servo angles
MOUTH_START = 100
MOUTH_END = 90

# 17 is labeled SERVO 1 on CRICKIT
pwm = PWMOut(seesaw, 17)
# must be 50 cannot change
pwm.frequency = 50
my_servo = servo.Servo(pwm)
# Starting servo locations
my_servo.angle = MOUTH_START

# Audio playback object and helper to play a full file
a = audioio.AudioOut(board.A0)


def play_file(wavfile):
    print("Playing", wavfile)
    with open(wavfile, "rb") as f:
        wav = audioio.WaveFile(f)
        a.play(wav)