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 ¶
_, 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 ¶
- Constants
- type Dev
- func (d *Dev) CreatePin(channel int) (gpio.PinIO, error)
- func (d *Dev) RegisterPins() error
- func (d *Dev) SetAllPwm(on, off gpio.Duty) error
- func (d *Dev) SetFullOff(channel int) error
- func (d *Dev) SetFullOn(channel int) error
- func (d *Dev) SetPwm(channel int, on, off gpio.Duty) error
- func (d *Dev) SetPwmFreq(freqHz physic.Frequency) error
- func (d *Dev) UnregisterPins() error
- type Servo
- type ServoGroup
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.
func (*Dev) RegisterPins ¶
RegisterPins makes PWM channels available as PWM pins in the pin registry
Pin names have the following format: PCA9685_<HexAddress>_<channel> (e.g. PCA9685_40_11)
func (*Dev) SetFullOff ¶
SetFullOff sets PWM duty to 0%.
This function uses the dedicated bit to reduce bus traffic.
func (*Dev) SetFullOn ¶
SetFullOn sets PWM duty to 100%.
This function uses the dedicated FULL_ON bit.
func (*Dev) SetPwmFreq ¶
SetPwmFreq set the PWM frequency.
func (*Dev) UnregisterPins ¶
UnregisterPins remove all previously created pin handles of this device from the GPIO registry
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 through 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