Go Down

Topic: Devantech SD21 Servo Controller and Arduino (Read 1 time) previous topic - next topic

teoxan

The SD21 Servo Controller is a very versatile Controller, able to control the speed and position of 21 Servos, keeping a 20ms refresh rate no matter how many servos you attach.

In the following example, an SD21 is connected to my Arduino Diecimilla board using the I2C Bus and the Wire library.

It's very easy to control it, and you can have up to 21 servos using only 2 pins ( SDA and SCL).

Be carefull: You must provide a separate power to the Controller ( up to 7.2V) otherwise it's not working.

For more information check the Devantech Web site.

Code: [Select]
#include <Wire.h>
#define SD21 0xc2 //SD21 I2C Address

void setup()
{
 Wire.begin();  // start I2C
 Serial.begin(9600);
}

void loop()
{
 Wire.beginTransmission(SD21>>1); // Shift the SD21 Address-We only need 7 bits
 
 // The SD21 Servo Controller can drive up to 21 Servos
 // controlling both their speed and position
 //Every Servo has three Registers-one for the Sevo ID (0 is Servo 1) and speed, and two used as Low Byte/High Byte
 // to control the position
 
 Wire.send(0); //Servo 1 ID - Speed register 0
 Wire.send(5); // Set speed of Servo 1 ( with 10 as the maximum)
 Wire.send(1); // Send High Byte to Register 1 to set the pulse
 Wire.send(1000); // Send pulse in uS ( on Hitech digital Servos range can be from 800-2200
 Wire.send(2000);// Send another pulse
  Wire.send(3); // Servo 2 ID
  Wire.send(5); // Set Speed of Servo 2
 Wire.send(1500); // Send pulse to center-position servo
 Wire.endTransmission();
 Wire.requestFrom(SD21>>1, 1 );

  while(Wire.available())
  { ; }

   int b = Wire.receive();

 }



teoxan


networm.rc


Go Up