Controlling 12 servos with I2C Servo Controller IC
Controlling 12 servos with I2C Servo Controller IC
Here is a straightforward sketch to interface with our 12 channel Servo Controller IC.
The servo controller IC easily allows you to add up to 96 servos (8x Servo Controller chips) to your Arduino project. Enough for even the most advanced robot.
- Simply connect +5V to pin 1 on the chip
- Connect 0V to pin 20 on the chip.
- Connect the I2C SDA pin from the Arduino (A4 on Uno) to the SDA pin on the servo chip (pin 13)
- Connect the I2C SCL pin from the Arduino (A5 on Uno) to the SCL pin on the servo chip (pin 11)
- Connect pullup resistors (4k7) on SCL and SDA to +5V
- Connect the servo signal wire (usually orange) to one of the servo chip SERVO outputs.
- Connect the servo power wire (usually red) to +5V
- Connect the servo ground wire (usually black) to +0V
- Connect the three address pins on the servo chip to ground
The sketch rotates each servo through its full range of motion, then pauses for short while, then repeats.
/* ** Wire Master of Hobbytronics 12 channel SERVO Controller ** Sweeps all 12 servos from one end to the other continuously ** Created 04 May 2010 ** ** This example code is in the public domain. ** www.hobbytronics.co.uk */ #include <Wire.h> const int servoslave_address=40; // I2C Address of ADC Chip void setup() { Wire.begin(); // join i2c bus (address optional for master) // Optionally set mode to standard // – comment out this section if extended mode required Wire.beginTransmission(servoslave_address); // transmit to device Wire.send(20); // servo register address 20 Wire.send(0); // send value 0 for standard mode Wire.endTransmission(); // stop transmitting delay(1); // waits } void loop() { unsigned char i,j; for(i = 127; i < 255; i++) // goes from center to full right { Wire.beginTransmission(servoslave_address); // transmit to device Wire.send(0); // servo register to start from for(j=0;j<12;j++) { Wire.send(i); // send 12 bytes of data } Wire.endTransmission(); // stop transmitting delay(1); // waits } for(i = 255; i > 0; i--) // goes from full right to full left { Wire.beginTransmission(servoslave_address); // transmit to device Wire.send(0); // servo register to start from for(j=0;j<12;j++) { Wire.send(i); // send 12 bytes of data } Wire.endTransmission(); // stop transmitting delay(1); // waits } for(i = 0; i < 127; i++) // goes from full left back to center { Wire.beginTransmission(servoslave_address); // transmit to device Wire.send(0); // servo register to start from for(j=0;j<12;j++) { Wire.send(i); // send 12 bytes of data } Wire.endTransmission(); // stop transmitting delay(1); // waits } delay(800); // waits for 0.8 seconds }