Does anyone know if you can use a PWM servo shield with XOD?

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:

  1. #include <Wire.h>
  2. #include <Adafruit_PWMServoDriver.h>
  • Adafruit_PWMServoDriver pwm1 = Adafruit_PWMServoDriver(0x40);
  1. Adafruit_PWMServoDriver pwm2 = Adafruit_PWMServoDriver(0x41);
  • void setup() {
  1. Serial.begin(9600);
  2. Serial.println(“16 channel PWM test!”);
  • pwm1.begin();
  1. pwm1.setPWMFreq(1600); // This is the maximum PWM frequency
  • pwm2.begin();
  1. pwm2.setPWMFreq(1600); // This is the maximum PWM frequency
  2. }

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);
}

1 Like

Hello!

It’s not quite trivial to implement as the support will require some C++ knowledge. But it is possible to create a wrapper around the Adafruit’s library. If you know the C++ basics see Making your own nodes section in XOD docs.

1 Like

As I understand it the “normal” way is to build your own custom nodes mimicking the functions of the adafruit PWM server “driver” using the various xod\i2c component nodes. You should have the source code to the adafruit “driver” to guide you. I recently bought a different PWM shield that uses the same chip too but not got a specific need for it yet just thought that looks powerful and cheap might find a use for it eventually :grin: Don’t forget to publish your new nodes if you manage it :smile: Hope you have fun hacking yourself a new node or two!

Hi willwheelernyc
This may help?

1 Like