Using 4 ch motor + 16 servo shield for Arduino by doit.am

Thread Starter

deepakdpadhi

Joined Sep 29, 2018
19
Hey guys, so i have this shield (imgs and schematic in pdf attached), that i bought for a mobile robot arm project. So I contacted the manufacturers (doit.am) asking them for the libraries to control the servo and motor pins. They said there are no libraries required as the servos operate on IIC or some such thing. Please help me out.
I have used arduinos with multiple sensors, shields and libraries but don't know how to do this. Any documentation/code examples would also be well appreciated.
 

Attachments

djsfantasi

Joined Apr 11, 2010
5,841
The attached datasheet mentions WiFi, Bluetooth but not I2C. What’s in common is that all are serial protocols.

Usually in this case, there are a set of control commands. Yet the datasheet makes no mention of what these commands may be.

With the information you have, I have no idea how to use that board.

I always use this shield in my animatronics. Similar application to yours.
 

djsfantasi

Joined Apr 11, 2010
5,841

Thread Starter

deepakdpadhi

Joined Sep 29, 2018
19
Here’s a link to the library and a tutorial on using the Adafruit board.

At the worst, the Adafruit board isn’t overly expensive IMHO
Well, it was provided by a professor :) . I tried the library and ran the example code servo. Since it didn't run the servo even when i plugged into the 0th channel, i checked all 3 pins for the servo. Seemed like the vs and gnd pins were alright but the pwm pin wasn't giving any values.

Code:
#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);

// Depending on your servo make, the pulse width min and max may vary, you
// want these to be as small/large as possible without hitting the hard stop
// for max range. You'll have to tweak them as necessary to match the servos you
// have!
#define SERVOMIN  150 // this is the 'minimum' pulse length count (out of 4096)
#define SERVOMAX  600 // this is the 'maximum' pulse length count (out of 4096)

// our servo # counter
uint8_t servonum = 0;

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

// you can use this function if you'd like to set the pulse length in seconds
// e.g. setServoPulse(0, 0.001) is a ~1 millisecond pulse width. its not precise!
void setServoPulse(uint8_t n, double pulse) {
  double pulselength;

  pulselength = 1000000;   // 1,000,000 us per second
  pulselength /= 60;   // 60 Hz
  Serial.print(pulselength); Serial.println(" us per period");
  pulselength /= 4096;  // 12 bits of resolution
  Serial.print(pulselength); Serial.println(" us per bit");
  pulse *= 1000000;  // convert to us
  pulse /= pulselength;
  Serial.println(pulse);
  pwm.setPWM(n, 0, pulse);
}

void loop() {
  // Drive each servo one at a time
  Serial.println(servonum);
  for (uint16_t pulselen = SERVOMIN; pulselen < SERVOMAX; pulselen++) {
    pwm.setPWM(servonum, 0, pulselen);
  }

  delay(500);
  for (uint16_t pulselen = SERVOMAX; pulselen > SERVOMIN; pulselen--) {
    pwm.setPWM(servonum, 0, pulselen);
  }

  delay(500);

  servonum ++;
  if (servonum > 7) servonum = 0;
}
I used an mg 996r servo on the 0th channel and then used a multimeter to measure the voltage on the pwm pin. Any ideas for what else i could do to troubleshoot?
The only parts of the code I don't understand are the ones using I2C
 

djsfantasi

Joined Apr 11, 2010
5,841
The loaded library is in control. Which means you cannot directly the servo with PWM. You send a PWM command; the library overwrites it.

Use the library procedures. Once you’ve set up the board and I2C, the library procedures do what you want.

What’s happening is that you and the library are fighting for control. And the library is winning. Every time.
 

Thread Starter

deepakdpadhi

Joined Sep 29, 2018
19
Alright guys, here's the complete reply, with some precautions for future users.
The shield can be used via the library available at https://learn.adafruit.com/16-channel-pwm-servo-driver/using-the-adafruit-library.
(Shoutout to @djsfantasi ).
NOTE : One of the main things to ensure is that the 5v power supply for the servos must be separate from that of the arduino, as it messes up the servos somehow.
The motors can be powered via the given slots on the shield. All you have to do is supply the DIR and PWM values to the 1st 8 available arduino pins (after pin 0 and 1, ie, 2-9). It is pretty easy to figure out which pin controls which channel.
NOTE: Since the motor pins are available via male headers stacked very close together, i would suggest using female headers/jumper wires before connecting them to your motors. I burned my 1st shield's motor driver due to the +ve and -ve ending up shorted together.

Thanks for the replies everyone and best of luck to you guys reading this.
 
Top