Processing + Arduino Shield adapt

Hi all¡

I´m in the middle of a project where I should run a bunch of servos, the best idea was using this board : http://www.robot-r-us.com/vmchk/servo-controllers/red-back-spider-robot-48-servos-controller.html
It provides a simple Arduino code to run up to 48 servos at once, it looks like this:

#include <Servo.h>

// define global variables

int sp=1500;
int dr=5;

// define servos

Servo s00;
Servo s01;
Servo s02;
Servo s03;
Servo s04;
Servo s05;
Servo s06;
Servo s07;
Servo s08;
Servo s09;
Servo s10;
Servo s11;
Servo s12;
Servo s13;
Servo s14;
Servo s15;
Servo s16;
Servo s17;
Servo s18;
Servo s19;
Servo s20;
Servo s21;
Servo s22;
Servo s23;
Servo s24;
Servo s25;
Servo s26;
Servo s27;
Servo s28;
Servo s29;
Servo s30;
Servo s31;
Servo s32;
Servo s33;
Servo s34;
Servo s35;
Servo s36;
Servo s37;
Servo s38;
Servo s39;
Servo s40;
Servo s41;
Servo s42;
Servo s43;
Servo s44;
Servo s45;
Servo s46;
Servo s47;

void setup()
{

s00.attach(2);
s01.attach(3);
s02.attach(4);
s03.attach(5);
s04.attach(6);
s05.attach(7);
s06.attach(8);
s07.attach(9);
s08.attach(10);
s09.attach(11);
s10.attach(12);
s11.attach(13);
s12.attach(14);
s13.attach(15);
s14.attach(16);
s15.attach(17);
s16.attach(18);
s17.attach(19);
s18.attach(20);
s19.attach(21);
s20.attach(22);
s21.attach(23);
s22.attach(24);
s23.attach(25);
s24.attach(26);
s25.attach(27);
s26.attach(28);
s27.attach(29);
s28.attach(30);
s29.attach(31);
s30.attach(32);
s31.attach(33);
s32.attach(34);
s33.attach(35);
s34.attach(36);
s35.attach(37);
s36.attach(38);
s37.attach(39);
s38.attach(40);
s39.attach(41);
s40.attach(42);
s41.attach(43);
s42.attach(44);
s43.attach(45);
s44.attach(46);
s45.attach(47);
s46.attach(48);
s47.attach(49);
}

void loop()
{
s00.writeMicroseconds(sp);
s01.writeMicroseconds(sp);
s02.writeMicroseconds(sp);
s03.writeMicroseconds(sp);
s04.writeMicroseconds(sp);
s05.writeMicroseconds(sp);
s06.writeMicroseconds(sp);
s07.writeMicroseconds(sp);
s08.writeMicroseconds(sp);
s09.writeMicroseconds(sp);
s10.writeMicroseconds(sp);
s11.writeMicroseconds(sp);
s12.writeMicroseconds(sp);
s13.writeMicroseconds(sp);
s14.writeMicroseconds(sp);
s15.writeMicroseconds(sp);
s16.writeMicroseconds(sp);
s17.writeMicroseconds(sp);
s18.writeMicroseconds(sp);
s19.writeMicroseconds(sp);
s20.writeMicroseconds(sp);
s21.writeMicroseconds(sp);
s22.writeMicroseconds(sp);
s23.writeMicroseconds(sp);
s24.writeMicroseconds(sp);
s25.writeMicroseconds(sp);
s26.writeMicroseconds(sp);
s27.writeMicroseconds(sp);
s28.writeMicroseconds(sp);
s29.writeMicroseconds(sp);
s30.writeMicroseconds(sp);
s31.writeMicroseconds(sp);
s32.writeMicroseconds(sp);
s33.writeMicroseconds(sp);
s34.writeMicroseconds(sp);
s35.writeMicroseconds(sp);
s36.writeMicroseconds(sp);
s37.writeMicroseconds(sp);
s38.writeMicroseconds(sp);
s39.writeMicroseconds(sp);
s40.writeMicroseconds(sp);
s41.writeMicroseconds(sp);
s42.writeMicroseconds(sp);
s43.writeMicroseconds(sp);
s44.writeMicroseconds(sp);
s45.writeMicroseconds(sp);
s46.writeMicroseconds(sp);
s47.writeMicroseconds(sp);

sp+=dr;
if (sp>2000 || sp<1000) dr=-dr;
delay(1);
}

The problem is that the input data to move the servos is generated by Max/MSP. The communication with Arduino (Serial or OSC) it´s too painful; so I opted to use Processing to receive the OSC data from Max/MSP. Simply with 7 servos plugged to my Arduino Mega works with no problems (using ServoFirmata)

The shield´s creators says that the board is coded like an Arduino Mega anyway, I was wondering how to code in Processing to use it. I only have to declare the 48 pins and parse the data?
I was hoping to clear this matter before buying the board.

Any help will be appreciated¡
I hope I´m explaining properly, sorry about my bad english¡

The problem is that the input data to move the servos is generated by Max/MSP.

Not in that code, it isn’t.

The communication with Arduino (Serial or OSC) it´s too painful

In what way? What IS Max/MSP sending to the Arduino?

so I opted to use Processing to receive the OSC data from Max/MSP.

But, you didn’t show that code.

The shield´s creators says that the board is coded like an Arduino Mega anyway, I was wondering how to code in Processing to use it. I only have to declare the 48 pins and parse the data?

Yep. Forget using ServoFirmata, though. That doesn’t support 48 servos.

Any help will be appreciated¡
I hope I´m explaining properly, sorry about my bad english¡

Your English is fine. Your code posting is not. Please modify your post, select the code, and select the icon with the # symbol on it. Then, save the changes. I presume you didn’t really attach a servo to the smiley face pin.

Hi, Thank you for your response¡

Forget about Processing, now I´m trying to send one unique value from Max/MSP to Arduino by Serial; and then in Arduino parse them to the servos and delay them properly.
I´m starting from Communication examples; the part I don´t understand is about encoding data, Max sends an integer but Arduino gets a Byte… from the example I started encoded the entering values from 0 to 9; mapping these values to 0 to 180 (properly for servos) I get so small range. I Tried to amplify the proper range but they stop moving…

It´s a little smart iniciation, at least they move, but I need to control the degrees more properly, any ideas?
Thank you, and sorry, I´m pasting the code fine, n00b issues¡

#include <Servo.h>

// define global variables

int sp=1500;
int dr=5;

int pos = 0;
float sweep = 0;

// define servos

Servo s00;
Servo s01;
Servo s02;
Servo s03;
Servo s04;
Servo s05;
Servo s06;

void setup()
{
  Serial.begin(9600);
  
  s00.attach(13);
  s01.attach(12);
  s02.attach(11);
  s03.attach(10);
  s04.attach(9);
  s05.attach(8);
  s06.attach(7);
  
}

void loop()
{
  while (Serial.available()>0){
    
    //int sweep = Serial.read();
    int inByte = Serial.read();
    Serial.write(inByte);
    
    sweep = map(inByte, '0', '9', 0, 180);
    
    
    //if(inByte == 'a'){
      s00.write(sweep); 
      delay (200);
      s01.write(sweep);
      s02.write(sweep);
      delay(200);
      s03.write(sweep);
      delay (200); 
      s04.write(sweep);
      s05.write(sweep);
      delay(200);
      s06.write(sweep);
    
   // }
  }
<pre><code>
----------begin_max5_patcher----------
735.3ocyX0sjZBCF8Z3oHCWa2IADT5cc5iQmN6DfrZ1ERXHws1ty9t27Cfnq
.xVk5Mn4iXxImbNeeI9lqiWBeOQ3A9J3G.Gm2bcbLgzAbpa63Uf2mliElt4w
H+hm7r2B6qjj8RSXAImjJAP.p4UrcE7cxbhz76BpiZCI+cIwNodIX1FuEG9z
C7y5t9DmIY3BSG89VEEm2LzzLSLEN9R.rIXIVltkx17XkBH1AO.t9A3BPru9
Yj4oO7A3Qyff9GyLfzutE4TVKv0wd20U+XwExQo7hBBS9ARJMml9BXKoh.jb
PZNWn9xVBPPzqNPIuRdd1CNEJwOZHJILRSCn0AV1H5SQJnaFovKIraAmrZHN
YMxvIgqlaNofHD3MjyvIJow4W1n9LRSz33iF23TqRBhsMlHg3eEIDsL.fusL
BJdHFI.1QirDMaLRe1luejsYCQQOfbpPB3O006HtFlmA3kkPKUDfrllUyl2Q
x2rIeplDphIaQV289KvMDFZU.MOaGmiWJsiSkhWkjpGILbRtA.vqoinhxj2V
CQvf0Qfc12ChtS7CJqfPhuJkLVNX1fvNJBz7I564zWR.Ejb90r+PVglycMwD
kCUL0xIQKMxB+GBmKhYWQBo5ZPAJfPK1ULY8BpMMoBXMi.Z8XLUf4XoV2zzY
pqbxldjWXImNwTM5RQSTVEOppBsxPVKilsSx2W12a7QQhFmJfvCNrYIwauW7
ybVCLHNBB+b9uol9YTxwOvTvdU7+bdYyOTIlYmdIYybqieLiI36pRaVd0hZv
goOiHjTFVR4rN8AcTe1RyxHrtoexnBsoNqeW8khlnK.MwyFZz2ceT33ilW7f
FayZF4m6JsyIaD+ugC59xYoOSzcj0x.mwjxQyGb7ujMqUyGdtDs7Iom9HdJn
YkbUMr5RCA16AT+elnZDZabXZ5A+1hL3xxWIUhZLXftp.7y7JcynEt1ilZaZ
PfWE4UZS+Cc0i16t+Eva1evC
-----------end_max5_patcher-----------
</code></pre>

Is there no way to turn this stuff:

<pre><code>
----------begin_max5_patcher----------
735.3ocyX0sjZBCF8Z3oHCWa2IADT5cc5iQmN6DfrZ1ERXHws1ty9t27Cfnq
...
PfWE4UZS+Cc0i16t+Eva1evC
-----------end_max5_patcher-----------
</code></pre>

into something readable by humans, so that we can see how you are sending data?

It´s Max/MSP compressed code, it look like this:

Captura de pantalla 2012-07-26 a la(s) 11.50.01.png

Ok. Well maybe someone that knows Max/MSP will come along.

Max sends an integer but Arduino gets a Byte

Is Max sending that integer in binary or as text? If it sends 22 as a binary value, then the Arduino can receive that 2 byte value as a single byte (unless you are trying to dealt with servos that rotate more than 255 degrees) with no problem.

If Max is sending "22", then you need to fix what Max is sending, so the Arduino knows where the value ends. Otherwise, the Arduino has to deal with something like this: IfMaxissending"22",thenyouneedtofixwhatMaxissending,sotheArduinoknowswherethevalueends.

Much harder, no?

from the example I started encoded the entering values from 0 to 9; mapping these values to 0 to 180 (properly for servos) I get so small range.

I don't understand this statement. The range stays 0 to 180, if you mapped stuff correctly. The resolution goes to hell, since your step size is now 20 degrees.

Since the map function you are using has as it's from range '0' and '9', I think it is obvious that Max is NOT sending binary data.

So, you need to make Max send something after the value (like we use spaces between words), so the Arduino can read and store any serial data that arrives, until the separator arrives, at which time it can use atoi() to convert the string "114" to an int, 114) and then move the servo(s).

Max could even send something like "2:109!" to tell the Arduino to move servo 2 to 109 degrees.