Javadoc link

This is a MyRobotLab service to support the Adafruit 16-Channel 12-bit PWM/Servo Driver attached to an Arduino or a Raspberry PI. It can be used with any board that use the PCA9685 circuit. It is dedicated to do PWM ( Pulse Width Modulation ) and it uses the i2c protocol. Since it can do PWM it can also be used to control a Motor driver. The pins can also be used as digital output pins or analog output pins. When used as analog output pins they are not true analog, but pwm. 

Go to Adafruit product page for more descriptions on details of the driver.

Some examples of other boards that also can be used:

Adafruit 16-Channel PWM / Servo HAT for Raspberry Pi

Adafruit 16-Channel 12-bit PWM/Servo Shield for Arduino

8-Channel PWM or Servo FeatherWing Add-on For All Feather Boards

Steps to control Servo Driver using the Arduino.

  1. Attach the Arduino to the computer running MRL (USB, Bluetooth, or other serial method)
  2. Attach the servo driver to the Arduino
  3. Attach the servo to the servo driver and connect power
  4. Follow the steps on this page to install MRLComm. http://myrobotlab.org/service/Arduino  If it already has been done, you don't need to do it again. 
  5. Once uploaded, I would highly recommend restarting MRL after the upload
  6. Download the example script and execute it from the Python tab. You need to change some parameters in the script to fit your configuration. They are all docmented in the script: 

Steps to use the Servo Driver using the Raspberry PI.

  1. Attach the servo driver to the Raspberry PI
  2. Attach the servo to the servo driver and connect power
  3. Download the example script and execute it from the Python tab. You need to change some parameters in the script to fit your configuration. They are all docmented in the script: 

References

[[Adafruit16CMotorDriver.py]]

[[Adafruit16CServoDriverPi.py]]

 

Example code (from branch develop):
#########################################
# Adafruit16CServoDriver.py
# description: servo control
# categories: servo control
# more info @: http://myrobotlab.org/service/Adafruit16CServoDriver
#########################################
 
# This example shows how to use the Adafruit16CServoDriver
# It can be used with Arduino, RasPi or Esp8266_01
# From version 1.0.2316 use attach instead of setController
#
# config
port = "COM3"
# Code to be able to use this script with virtalArduino
if ('virtual' in globals() and virtual):
    virtualArduino = runtime.start("virtualArduino", "VirtualArduino")
    virtualArduino.connect(port)
# Start the Adafruit16CServodriver that can be used for all PCA9685 devices
adaFruit16c = runtime.start("AdaFruit16C","Adafruit16CServoDriver")
#
# This part of the script is for the Arduino
# Comment it out the three lines below if you don't use the Arduino
# Change COM3 to the port where your Arduino is connected
arduino = runtime.start("arduino","Arduino")
arduino.connect(port)
adaFruit16c.attach("arduino","0","0x40")
#
# This part of the script is if you use the GPOI pins of the Raspberry PI
# Uncomment the two lines below if you use the RasPi
# raspi = runtime.start("raspi","RasPi")
# adaFruit16c.attach("raspi","1","0x40")
#
# This part of the script is if you use the Esp8266_01 service
# Uncomment it the two lines below if you duse the Esp8266_01
# esp = runtime.start("esp","Esp8266_01")
# adaFruit16c.attach("esp","1","0x40")
#
# This part is common for both devices and creates two servo instances
# on port 3 and 8 on the Adafruit16CServoDriver
# Change the names of the servos and the pin numbers to your usage
thumb = runtime.start("Thumb", "Servo")
elbow = runtime.start("Elbow", "Servo")
# attach it to the pwm board - pin 3 & 8
thumb.attach(adaFruit16c,3)
elbow.attach(adaFruit16c,8)
# When this script has been executed you should be able to
# move the servos using the GUI or using python

moz4r

7 years 11 months ago

AND APROVED !

I will test it more

thank you

Mats

7 years 9 months ago

In reply to by moz4r

I finished updating and testing the Adafruit16CServoDriver today. So if you want, you can download an test in in the 'latest build'. 

attach() and detach() should be working now.

I also updated it so that setVelocity and setAcceleration can be used.

Please test and report if you find anything strange,

Hi ! I have done some test , it is better ! This is the results

If I use somewhere servo.detach() , I can't  attach anymore. But now if I restart MRL it worky again.

If I didn't use servo.detach() but I declare servo.autoAttach(1) an some sleep between servo declaration it seem works better

SCRIPT :

https://github.com/MyRobotLab/pyrobotlab/blob/master/home/moz4r/Marty/m…

Hi Moz4r

I made a change in the 'lastest build' so that it should work now. But please test again.

If you still find a problem, please provide a small script showing the problem so that I can recreate it.

/Mats

 

I can confirm that it is/was broken. I found the reason and it's correced in 1932.

I tested a servo connected to the Arduino. I also found that something is broken with the combination of Servo >= Adafruit16CServoDriver => Arduino

I need to dig into that. I hope that it's just related to the Arduino so that it still works on the RasPi.

Example configuration (from branch develop):
!!org.myrobotlab.service.config.Adafruit16CServoDriverConfig
controller: null
deviceAddress: null
deviceBus: null
listeners: null
peers: null
type: Adafruit16CServoDriver