Interaction Design WikiElectrical Engineering

Pololu Servo Controller

Mit dem Polulu Servo Controller können bis zu 8 Servos gleichzeitig angesteuert werden. Zusätzlich können die Servos einfach mit einem externen Netzteil gespiesen werden.

Einfaches Protokoll (mit Jumper)

#include <SoftwareSerial.h>
  
// pin 6 is to receive from the controller and does not need to be connected
// pin 7 needs to be connect to the serial data input of the board
SoftwareSerial pololu(6, 7);
  
int pos = 0;
  
void setup() {
  Serial.begin(9600);
  pololu.begin(9600);
}
  
void loop() {
  Serial.println(pos);
  
  // set position for eight servos simultaneously
  for(int i=0; i<8; i++) {
    setPosition(i, pos);
  }
    
  pos++;
  if(pos >= 255) {
    pos = 0;
  }
  
  delay(10);
}
  
void setPosition(int servo, int pos) {
  pololu.write(0xFF); // write synchronization flag
  pololu.write(servo + 8); // write servo number (without +8 == 90°)
  pololu.write(pos); // write position
}

Erweitertes Protokoll (ohne Jumper)

#include <SoftwareSerial.h>
 
// pin 6 is to receive from the controller and does not need to be connected
// pin 7 needs to be connect to the serial data input of the board
SoftwareSerial pololu(6, 7);
 
int pos = 0;
 
void setup() {
  Serial.begin(9600);
  pololu.begin(9600);
}

void loop() {
  Serial.println(pos);
 
  // set position for eight servos simultaneously
  for(int i=0; i<8; i++) {
    setPosition(i, pos);
  }
   
  pos++;
  if(pos >= 255) {
    pos = 0;
  }
 
  delay(10);
}
int setPosition(int servo, int pos) {
  byte data2 = pos & B01111111; // calculate second data byte 
  byte data1 = pos >> 7; // calculate first data byte

  pololu.write(0x80); // write start byte
  pololu.write(0x01); // write device id
  pololu.write(0x04); // write absolute position command
  pololu.write((byte)servo); // write servo number
  pololu.write(data1); // write first data byte
  pololu.write(data2); // write second data byte
}