hiya!
Tx to Jasch, David, Alex, Adrian, Martin, Thomas and other who had help on getting some code done to make the arduino a servo controller (to be used from puredata). here is a basic example that i havent been succesful in running correctly my servos move in a very nerrvous way when connected to 2 pins from the digital outputs, is wierd but if i change the .pde code to pins 5 and 6 and connect the servos to pin 2 and 3 i get to move the servos, same thing applies in the opposite way if i define pins 2 and 3, then those are dead when i move some numbers in the pd patch, but when connected to pins 5 and 6 in the board i get again some nervous/noisy electricity flowing.. til it breaks like when theres a shortcout...yea mon' im a newbee and simply I dont understand why this doesnt work?, plis see the image there is a way how i connect them but theres always that fault that breaks the port connection, i get a message saying that the board was disconnected.
so if anyone could help test this code and report back, i will greatly appreciate it.
merci
/a
/* Servo Motors
* ------------
*
* This program controls 2 servo motors through sending commands over
* the serial port. The motors will be connected to pins 2 and 3. It
* motors will be controlled with a single byte. The first nibble will
* control the motor, while the second will control the postion. Thus
* each motor will have 16 positions.
*
*
* (cleft) 2006 David Cuartielles for K3, Sweden
* http://www.arduino.cc
*
* @idea: T. Igoe, J. Gray
* @code: T. Igoe, J. Gray, D. Cuartielles
* @PD patch: jasch http://www.jasch.ch/ mods by D. Cuartielles y Alex Posada
*
*/
int servoPinL = 2; // Control pin for servo motor - L
int servoPinR = 3; // Control pin for servo motor - R
int pulseL = 0; // Amount to pulse the servoL
int pulseR = 0; // Amount to pulse the servoR
int delayValueMax = 20000; // the 2 millisecond maxiumum pulse range for the servo
int delayValue = 20000; // the actual value the code should wait, determined later
int analogValue = 0; // the value returned from the analog sensor
int analogPin = 0; // the analog pin that the sensor's on
char c, servoNumber, servoValue;
void setup(void)
{
pinMode(servoPinL, OUTPUT); // Set servo pins as an output pins
pinMode(servoPinR, OUTPUT);
pulseL = 1000; // Set the motor position values to the minimum
pulseR = 1000;
beginSerial(9600);
}
void loop(void)
{
c = serialRead();
if (c != -1)
{
servoNumber = (c & 0x80) >> 7; // servo ID is in high bit in high nibble
servoValue = (c & 0x7F); // servo angle is in low 7 bit
if (servoNumber == 0) pulseL = (servoValue*8) + 1000; // make a pulse 1000-2000 us
else if (servoNumber == 1) pulseR = (servoValue*8) + 1000; // make a pulse 1000-2000 us
// print values on the screen
// for a terminal window
//printString("\n\r Numer: ");
//printInteger(servoNumber%2);
//printString(" - Value: ");
//printInteger(servoValue);
// print values on the screen
// for debugging in PD
serialWrite(c);
}
digitalWrite(servoPinL, HIGH); // Turn the L motor on
delayMicroseconds(pulseL); // Length of the pulse sets the motor position
digitalWrite(servoPinL, LOW); // Turn the L motor off
digitalWrite(servoPinR, HIGH); // Turn the R motor on
delayMicroseconds(pulseR); // Length of the pulse sets the motor position
digitalWrite(servoPinR, LOW); // Turn the R motor off
delayValue = delayValueMax - pulseL - pulseR; // determine how much time you have before the 20 ms is over...
delayMicroseconds(delayValue); // 20 millisecond delay is needed between pulses to keep the servos in sync
}
the pd patch is this one:
#N canvas 754 69 493 628 10;
#X floatatom 179 166 5 0 0 0 - - -;
#X obj 159 239 print;
#X obj 160 216 spigot;
#X msg 179 189 1;
#X msg 209 188 0;
#X obj 181 85 key;
#X floatatom 25 52 3 0 0 0 - - -;
#X obj 25 26 keyname;
#X symbolatom 68 52 10 0 0 0 - - -;
#X obj 25 77 bng 15 50 10 0 empty empty empty 0 -6 0 8 -262144 -1 -1
;
#X floatatom 180 110 5 0 0 0 - - -;
#X obj 179 139 comport 3 9600;
#X obj 275 110 float;
#X obj 275 87 bng 15 250 50 0 empty empty empty 0 -6 0 8 -262144 -1
-1;
#X floatatom 289 60 5 0 0 0 - - -;
#X msg 341 34 1;
#X msg 342 53 2;
#X msg 342 72 3;
#X msg 342 92 4;
#X msg 342 111 5;
#X msg 342 130 6;
#X msg 343 149 7;
#X msg 343 168 8;
#X msg 343 188 9;
#X msg 343 207 11;
#X msg 342 226 12;
#X msg 343 245 13;
#X msg 343 265 14;
#X msg 343 284 15;
#X floatatom 148 339 5 0 0 0 - - -;
#X floatatom 205 339 5 0 0 0 - - -;
#X text 138 321 servoID;
#X text 207 321 value;
#X obj 148 391 * 16;
#X obj 148 437 +;
#X obj 205 391 t b f;
#X obj 148 470 s to_comport;
#X obj 55 137 r to_comport;
#X floatatom 73 182 5 0 0 0 - - -;
#X obj 138 182 bng 15 250 50 0 empty empty empty 0 -6 0 8 -262144 -1
-1;
#X connect 2 0 1 0;
#X connect 3 0 2 1;
#X connect 4 0 2 1;
#X connect 5 0 10 0;
#X connect 6 0 9 0;
#X connect 6 0 11 0;
#X connect 7 0 6 0;
#X connect 7 1 8 0;
#X connect 10 0 11 0;
#X connect 11 0 3 0;
#X connect 11 0 0 0;
#X connect 12 0 11 0;
#X connect 13 0 12 0;
#X connect 14 0 12 1;
#X connect 14 0 13 0;
#X connect 15 0 12 1;
#X connect 16 0 12 1;
#X connect 17 0 12 1;
#X connect 18 0 12 1;
#X connect 19 0 12 1;
#X connect 20 0 12 1;
#X connect 21 0 12 1;
#X connect 22 0 12 1;
#X connect 23 0 12 1;
#X connect 24 0 12 1;
#X connect 25 0 12 1;
#X connect 26 0 12 1;
#X connect 27 0 12