Go Down

Topic: (Newb) processing + arduino + Servo (Read 689 times) previous topic - next topic

clipcomet

Good day to you all and thx for looking :)

I'm working on a scorpion alike robot (6 legs and 18 s3003 servos) and I got it up and running. But then I found out that you can use processing to control the arduino and that opens up a lot of new fun stuff...

But here comes my problems :(

How do I control my 18 servos from processing?? I can't get any arduino. Servo commands to work... (Really noob on this point so be gentle)


(Windows 7 x64)
(arduino mega 1280)

many thx for any help :)

PaulS

Quote
I can't get any arduino. Servo commands to work... (Really noob on this point so be gentle)

Doing what? Let me guess. You loaded a stupid Firmata sketch on the Arduino.

Well, forget that crap. Develop your own protocol. You need to send two values (binary) at a time - the servo to move and the position to move that servo to.

The Arduino can then be programmed to read two values - the servo to move and the position to move that servo to - and move the appropriate servo (arrays are nice) to the appropriate position.

Of course, sending a sync byte, too, makes it possible to detect lost data, but at a cost - 50% slower communication.

Having the Arduino send Processing a "ready" message (can be one byte) whenever it is ready keeps the Processing application from getting ahead of the Arduino.

clipcomet

#2
Jul 17, 2012, 02:26 pm Last Edit: Jul 17, 2012, 02:31 pm by clipcomet Reason: 1
Thx for the replay :) and yes I used the ferma.

I like your solution and I'm sure for you it will make a lot of sense, but for me it's like reading ¤¤¤¤¤¤¤¤¤¤ I'm way to new to understand how this works or even where to begin

i gess i can make the arduino read 4 bit (2bit for the name of the servo and 2 for the angle) if that what you where aiming at.. 

MichaelMeissner

Note, the servo library (http://arduino.cc/en/Reference/Servo) mentions some restrictions when you have more than 12 servos.

Just to be sure, I imagine you already power the servos separately with a common ground, and aren't trying to power the servos from the Arduino 5v pin.

As a trouble shooting method, I would hook each servo up one at a time until I found where it broke, rather than going full speed and try all 18 at once.

clipcomet


Note, the servo library (http://arduino.cc/en/Reference/Servo) mentions some restrictions when you have more than 12 servos.

Just to be sure, I imagine you already power the servos separately with a common ground, and aren't trying to power the servos from the Arduino 5v pin.

As a trouble shooting method, I would hook each servo up one at a time until I found where it broke, rather than going full speed and try all 18 at once.


hey Michael

yes the servos are powered by a 600w powersupply (what what i had)
if i leave Processing out of it i can control all the servo with no problem
when using more then 12 servos you cant use pins 11,12,44,45,46 ;)

clipcomet

i just had a brain wave :)

normaly i use serial to control the robot in arduino and putty....

cant i just use processing to do the same, and not change my arduino code?? (use processing to writ to serial com port direct)

PaulS

Quote
i gess i can make the arduino read 4 bit (2bit for the name of the servo and 2 for the angle) if that what you where aiming at..

Two bits for the name of the servo limits you to 4 "names" (00, 01, 10, 11 or 0, 1, 2, 3). Not near enough. You need at least 4 bits. So, you might as well use a whole byte.

Same for the angle. Two bits will allow you to move to 0, 1, 2, or 3 degrees. Not a very large range. You need a whole byte to get above 127 degrees.

PaulS

Quote
i just had a brain wave

Be careful you don't hurt yourself.  :)

Quote
normaly i use serial to control the robot in arduino and putty....

cant i just use processing to do the same, and not change my arduino code?? (use processing to writ to serial com port direct)

That's what Processing is doing now, except that the actual serial data to send is controlled by the Arduino object. On the Arduino, the reception and parsing of serial data is done by the Firmata sketch.

Since it is that sketch that does not allow you the flexibility to do what you want, it needs to be replaced.

clipcomet

thx for the replay :)

but if i can writ the serial data from Putty, then i dont understand why i need the firmata to do the same from Process??

Code: [Select]
import processing.serial.*;
Serial port;


void setup()
{
 size(500,500);
 port = new Serial(this, "COM3", 9600);
 
}

void draw()
{
 background(0,0,0);
}
 
void serialEvent (Serial port)
{
 myport.write(1);
}


cant this work for me??


edit
(com3 i normaly my port)

PaulS

Quote
but if i can writ the serial data from Putty, then i dont understand why i need the firmata to do the same from Process??

Who said that you need Firmata? You are the one that tried to use it. You don't need to, so don't.

Quote
cant this work for me??

Well, not exactly. The serialEvent() callback is called when serial data arrives on the port that the Processing application is listening to. You do not want to be pushing data in that function, unless the Arduino is sending a "ready" message.

If it is, then you should actually read the message in serialEvent() before sending data.

But, yes, that is the right idea. Just the wrong implementation.

Go Up