I used the Micro Serial Servo Controller (MSSC) with Arduino
to build three dancing matryoshkas. The response
of the MSSC is satisfyingly quick to synchronize
the puppets to a tune (I took a Russian punk rock song)
To create the beat I used an external pushbutton connected
to an input of the Arduino. Ideally, this should create an
interrupt on the Arduino, but there is a problem
in connection with the library SoftwareSerial.h.
Once you use Arduino interrupts the timing does
not work properly any more and SoftwareSerial.h
cannot produce correct serial bytes.
I put a note about it on the arduino forum, maybe it will be solved
later.
arduino.cc/cgi-bin/yabb2/YaB … 8516/13#13
To overcome this problem I used an external Flip-Flop which
catches the signal from the button and must be reset from
Arduino once it took the signal.
Furthermore to turn the puppets to back and front I used
three lever switches.
I do not recommend using the regular Pins 0 and 1 used for serial
communication. You need them usually for debugging and controlling
your program. Better is to use the software serial. You can use the
following code framework
/*
Pololu Template Program
It allows to set servos interactively.
by Hannes Hassler
based on examples by Tom Igoe, David Mellis and Heather Dewey-Hagborg
and on the contribution from Adam (nexisnet) in Thread
'https://forum.pololu.com/t/arduino-pololu-micro-serial-8-servo-controller/613/1&highlight=arduino'
discussing mostly between Adam, Phil and Zagrophyte
written: 20 Oct 2008
*/
#include <SoftwareSerial.h>
#define reset 7
#define rxPin 6
#define txPin 5
// set up a new serial port
SoftwareSerial mySerial = SoftwareSerial(rxPin, txPin);
void setup() {
// define pin modes for tx, rx, led pins:
pinMode(rxPin, INPUT);
pinMode(txPin, OUTPUT);
pinMode(reset, OUTPUT);
resetPololu();
mySerial.begin(9600);
Serial.begin(9600);
}
void resetPololu() {
digitalWrite(reset, LOW);
delay(100);
digitalWrite(reset,HIGH);
}
void send2Pololu(int servo, int angle) {
//maxRightAngle 4850
//minLeftAngle 1100
unsigned char buff[6];
unsigned int temp;
unsigned char pos_hi,pos_low;
//Convert the angle data into two 7-bit bytes
temp=angle&0x1f80;
pos_hi=temp>>7;
pos_low=angle & 0x7f;
//Construct a Pololu Protocol command sentence
buff[0]=0x80; //start byte
buff[1]=0x01; //device id
buff[2]=0x04; //command number
buff[3]=servo; //servo number
buff[4]=pos_hi; //data1
buff[5]=pos_low; //data2
//Send the command to the servo controller
for(int i=0;i<6;i++){
mySerial.print(buff[i]);
}
}
void loop() {
static int v = 0;
static int servo = 0;
static int angle = 0;
static char ch;
static int left=1000;
static int right=3000;
if (Serial.available()) {
ch = Serial.read();
/*
To set a specific servo interactively you
can use the folling scheme (type in the Serial port entry)
to select servo No 3, type : 3s
to set servo angle to 2000 : 2000a
to activate the servo respectively : d
set selected servo to its left value : l
set left value to 1100 : 1100L
set selected servo to its right value : r
set right value to 4500 : 4500R
reset Pololu : z
(reset pin 7 must be connected to reset pin of Pololu)
*/
switch(ch) {
case '0'...'9':
v = v * 10 + ch - '0';
break;
case 's':
Serial.print("servo:");
Serial.println(v);
servo=v;
v = 0;
break;
case 'a':
Serial.print("angle:");
Serial.println(v);
angle=v;
v = 0;
break;
case 'd':
Serial.print("set servo No:");
Serial.print(servo);
Serial.print(" angle:");
Serial.println(angle);
send2Pololu(servo, angle);
break;
case 'l':
send2Pololu(servo,left);
break;
case 'L':
left=v;
Serial.print("left:");
Serial.println(v);
v=0;
break;
case 'r':
send2Pololu(servo,right);
break;
case 'R':
right=v;
Serial.print("right:");
Serial.println(v);
v=0;
break;
case 'z':
resetPololu();
break;
}
}
}