Skip to content

microbit pca9685 #1

@wpsliu123

Description

@wpsliu123

I use mu editor, when I connect PCA9685 to microbit with slave address "0x41". The microbit gives me that "no module pca9685".

from microbit import sleep, i2c

import PCA9685
import servo

Initialise the PCA9685 using the default address (0x40).

#PCA9685_ADDR = 0x41
#pwm = PCA9685.PCA9685(i2c)
pwm = PCA9685.PCA9685(i2c)

Configure min and max servo pulse lengths (will need to adjust for different servos)

servo_min = 150 # Min pulse length out of 4096
servo_max = 600 # Max pulse length out of 4096:

Set frequency to 60hz, good for servos.

pwm.set_pwm_freq(60)

print('Moving servo on channel 0, press Ctrl-C to quit...')

Move servo on channel O between extremes.

pwm.set_pwm(4, 0, servo_min)
sleep(1000)
pwm.set_pwm(4, 0, servo_max)
sleep(1000)

Use servo helper class to move channel 0 by degrees

s0 = servo.Servos(i2c)
s0.position(0, 90)
sleep(1000)
s0.release(0)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions