Documentation ¶
Overview ¶
Package pca9685 includes utilities to controls pca9685 module and servo motors.
More details ¶
Datasheet ¶
https://www.nxp.com/docs/en/data-sheet/PCA9685.pdf
Product page:
Example ¶
package main import ( "log" "periph.io/x/periph/conn/i2c/i2creg" "periph.io/x/periph/conn/physic" "periph.io/x/periph/experimental/devices/pca9685" "periph.io/x/periph/host" ) func main() { _, err := host.Init() if err != nil { log.Fatal(err) } bus, err := i2creg.Open("") if err != nil { log.Fatal(err) } pca, err := pca9685.NewI2C(bus, pca9685.I2CAddr) if err != nil { log.Fatal(err) } if err := pca.SetPwmFreq(50 * physic.Hertz); err != nil { log.Fatal(err) } if err := pca.SetAllPwm(0, 0); err != nil { log.Fatal(err) } servos := pca9685.NewServoGroup(pca, 50, 650, 0, 180) // This is an example of using with an Me Arm robot arm gripServo := servos.GetServo(0) baseServo := servos.GetServo(1) elbowServo := servos.GetServo(2) shoulderServo := servos.GetServo(3) gripServo.SetMinMaxAngle(15, 120) elbowServo.SetMinMaxAngle(50, 110) // Set limit of the robot arm shoulderServo.SetMinMaxAngle(60, 140) // Set limit of the robot arm // Set all in the middle in a MeArm robot arm if err := gripServo.SetAngle(90); err != nil { log.Fatal(err) } if err := baseServo.SetAngle(90); err != nil { log.Fatal(err) } if err := elbowServo.SetAngle(90); err != nil { log.Fatal(err) } if err := shoulderServo.SetAngle(90); err != nil { log.Fatal(err) } }
Output:
Index ¶
Examples ¶
Constants ¶
const I2CAddr uint16 = 0x40
I2CAddr i2c default address.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Dev ¶
type Dev struct {
// contains filtered or unexported fields
}
Dev is a handler to pca9685 controller
func NewI2C ¶
NewI2C returns a Dev object that communicates over I2C.
To use on the default address, pca9685.I2CAddr must be passed as argument.
type Servo ¶
type Servo struct {
// contains filtered or unexported fields
}
Servo individual servo from a group of servos connected to a pca9685 module
func (*Servo) SetMinMaxAngle ¶
SetMinMaxAngle change angle limits for the servo
type ServoGroup ¶
type ServoGroup struct { *Dev // contains filtered or unexported fields }
ServoGroup a group of servos connected to a pca9685 module
func NewServoGroup ¶
NewServoGroup returns a servo group connected throught the pca9685 module some pwm and angle limits can be set
func (*ServoGroup) GetServo ¶
func (s *ServoGroup) GetServo(channel int) *Servo
GetServo returns a individual Servo to be controlled
func (*ServoGroup) SetAngle ¶
func (s *ServoGroup) SetAngle(channel int, angle physic.Angle) error
SetAngle set an angle in a given channel of the servo group
func (*ServoGroup) SetMinMaxPwm ¶
func (s *ServoGroup) SetMinMaxPwm(minAngle, maxAngle physic.Angle, minPwm, maxPwm gpio.Duty)
SetMinMaxPwm change pwm and angle limits