Adafruit16CServoDriver

javadoc

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: 

https://github.com/MyRobotLab/pyrobotlab/blob/master/service/Adafruit16C...

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: 

https://github.com/MyRobotLab/pyrobotlab/blob/master/service/Adafruit16C...

References


#file : /service/Adafruit16CServoDriver.py edit raw
# PLEASE MERGE THIS FILE - SHOULD SHOW HOW TO USE ARDUINO OR RASPI BOTH !
<<<<<<< HEAD
# From version 1.0.2316 use attach instead of setController
# Start the Adafruit16CSe#rvodriver that can be used for all PCA9685 devices
=======
# Start the Adafruit16CServodriver that can be used for all PCA9685 devices
>>>>>>> master
adaFruit16c = Runtime.createAndStart("AdaFruit16C","Adafruit16CServoDriver")
#
# This part of the script is for the Arduino
# Comment it out or delete it if you use the GPIO pins of the Raspberry PI
# Change COM4 to the port where your Arduino is connected
arduino = Runtime.createAndStart("Arduino","Arduino")
arduino.connect("COM4")
<<<<<<< HEAD
# adaFruit16c.setController("Arduino","1","0x40")
adaFruit16c.attach("Arduino","1","0x40")
#
# This part creates two servo instances
=======
adaFruit16c.setController("Arduino","1","0x40")
#
# This part of the script is if you use the GPOI pins of the Raspberry PI
# Comment it out or delete it if you use an Arduino
raspi = Runtime.createAndStart("RasPi","RasPi")
adaFruit16c.setController("RasPi","1","0x40")
#
# This part is common for both devices and creates two servo instances
>>>>>>> master
# on port 3 and 8 on the Adafruit16CServoDriver
# Change the names of the servos and the pin numbers to your usage
thumb = Runtime.createAndStart("Thumb", "Servo")
elbow = Runtime.createAndStart("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


#file : /service/Adafruit16CServoDriverPi.py edit raw
# From version 1.0.2316 use attach instead of setController
# This script is if you use the GPOI pins of the Raspberry PI
raspi = Runtime.createAndStart("RasPi","RasPi")
# adaFruit16c.setController("RasPi","1","0x40")
adaFruit16c.attach("RasPi","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.createAndStart("Thumb", "Servo")
elbow = Runtime.createAndStart("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


#file : /service/Adafruit16CMotorDriver.py edit raw
# From version 1.0.2316 use attach instead of setController
# An example of how to use the Adafruit16CServoDriver to 
# drive a motor.
#
# Runtime.start("webgui", "WebGui");
arduino = Runtime.createAndStart("Arduino", "Arduino");
arduino.connect("COM3")
sleep(5)
ada = Runtime.createAndStart("Ada","Adafruit16CServoDriver")
# ada.setController(arduino,"1","0x40")
ada.attach(arduino,"1","0x40")
sleep(2)
motor01 = Runtime.createAndStart("motor01", "Motor");
motor01.setPwmPins(0,1);
motor01.attach(ada);
motor01.move(0.3);

Examples:


#file : service/Adafruit16CServoDriver.py edit raw
# PLEASE MERGE THIS FILE - SHOULD SHOW HOW TO USE ARDUINO OR RASPI BOTH !
<<<<<<< HEAD
# From version 1.0.2316 use attach instead of setController
# Start the Adafruit16CSe#rvodriver that can be used for all PCA9685 devices
=======
# Start the Adafruit16CServodriver that can be used for all PCA9685 devices
>>>>>>> master
adaFruit16c = Runtime.createAndStart("AdaFruit16C","Adafruit16CServoDriver")
#
# This part of the script is for the Arduino
# Comment it out or delete it if you use the GPIO pins of the Raspberry PI
# Change COM4 to the port where your Arduino is connected
arduino = Runtime.createAndStart("Arduino","Arduino")
arduino.connect("COM4")
<<<<<<< HEAD
# adaFruit16c.setController("Arduino","1","0x40")
adaFruit16c.attach("Arduino","1","0x40")
#
# This part creates two servo instances
=======
adaFruit16c.setController("Arduino","1","0x40")
#
# This part of the script is if you use the GPOI pins of the Raspberry PI
# Comment it out or delete it if you use an Arduino
raspi = Runtime.createAndStart("RasPi","RasPi")
adaFruit16c.setController("RasPi","1","0x40")
#
# This part is common for both devices and creates two servo instances
>>>>>>> master
# on port 3 and 8 on the Adafruit16CServoDriver
# Change the names of the servos and the pin numbers to your usage
thumb = Runtime.createAndStart("Thumb", "Servo")
elbow = Runtime.createAndStart("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's picture

tested

AND APROVED !

I will test it more

thank you

Mats's picture

Adafruit16CServoDriver

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,

moz4r's picture

Great news Mats ! thank about

Great news Mats ! thank about the work you ve done. I'm happy to test it soon on the little robot

moz4r's picture

Hi ! I have done some test ( raspy mrl 1893 )

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/ma...

Mats's picture

Attach() / Detach()

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

 

moz4r's picture

just perfect. thank you so

just perfect. thank you so much

moz4r's picture

Hi Mats ! I think setVelocity

Hi Mats ! I think setVelocity is broken on last mrl . Speed always at full speed , can you confirm ?

Mats's picture

setVelocity

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.

moz4r's picture

worky ! Thank again

worky ! Thank again