I have this servo shield to allow me to power multiple servos without overloading arduino: https://www.amazon.com/gp/product/B0797JK4RW/ref=oh_aui_search_detailpage?ie=UTF8&psc=1
But it requires different code to control the servo than the standard.
Is there a way to use XOD with this type of shield?
Here’s an example of the arduino code to control the motor:
- #include <Wire.h>
- #include <Adafruit_PWMServoDriver.h>
- Adafruit_PWMServoDriver pwm1 = Adafruit_PWMServoDriver(0x40);
- Adafruit_PWMServoDriver pwm2 = Adafruit_PWMServoDriver(0x41);
- void setup() {
- Serial.begin(9600);
- Serial.println(“16 channel PWM test!”);
- pwm1.begin();
- pwm1.setPWMFreq(1600); // This is the maximum PWM frequency
- pwm2.begin();
- pwm2.setPWMFreq(1600); // This is the maximum PWM frequency
- }
and another example:
#include <Wire.h>
#include <Adafruit_PWMServoDriver.h>
// called this way, it uses the default address 0x40
Adafruit_PWMServoDriver pwm = Adafruit_PWMServoDriver();
// you can also call it with a different address you want
//Adafruit_PWMServoDriver pwm = Adafruit_PWMServoDriver(0x41);
// you can also call it with a different address and I2C interface
//Adafruit_PWMServoDriver pwm = Adafruit_PWMServoDriver(&Wire, 0x40);
//You need to play with these values. Write angle 0 and adjust SERVOMIN number until it reaches to 0 angle and you should not hear buzzing
//Also adjust SERVOMAX value in the same fasion.
#define SERVOMIN 125 // this is the ‘minimum’ pulse length count (out of 4096)
#define SERVOMAX 550 // this is the ‘maximum’ pulse length count (out of 4096)
void setup() {
Serial.begin(9600);
Serial.println(“8 channel Servo test!”);
pwm.begin();
pwm.setPWMFreq(60); // Analog servos run at ~60 Hz updates
delay(10);
}
void loop() {
//You can put upto 16 servos. But you have to calibrate them first.
//myServo_write(servo_number, angle )
for(int i=0; i<=180; i++)
{
myServo_write(0, i); // change in one degree requires some time so put 10ms dekat fir one degree step.
delay(10);
}
delay(500);
for(int i=180 i>=0; i–)
{
myServo_write(0, i); // change in one degree requires some time so put 10ms dekat fir one degree step.
delay(10);
}
delay(500);
}
void myServo_write(int servo_number, int angle)
{
if(servo_number>180)
servo_number=180;
if(servo_number<0)
servo_number=0;
int pulse=map(servo_number, 0, 180, SERVOMIN, SERVOMAX);
pwm.setPWM(servo_number, 0, pulse);
}