So do i even need to send the commas? So i am sending 5 sensor values, once it reads those it store them in a buffer? but then how do i access them and move the servos with them?
Yes, you need to send the commas. If you didn't, how would you know where one value ended and the next began. Here is a string of servo values. Move your servos to the correct positions:
125678011
Now, here is another string:
125,67,8,0,11
The second string allows you to know where to break it, using strtok() to get tokens. With the tokens, you can call atoi() to get integer values that the servos can be moved to.
So luckily i was reading this over and i saw that there was more code that you posted. code doesnt seem to be very mobile friendly. I added in the servo part and everything. does this look good? do i need the flash(); function if im going to send at 9600?
#include <Servo.h>
Servo myservo1; // create servo object to control a servo
Servo myservo2;
Servo myservo3;
Servo myservo4;
Servo myservo5;
Servo myservo6;
Servo myservo7;
// how much serial data we expect before a terminator
const unsigned int MAX_INPUT = 100;
const char TERMINATOR = '/';
const char STARTER = '.';
void setup ()
{
Serial.begin(9600);
myservo1.attach(2); //middle
myservo2.attach(3); //thumb
myservo3.attach(4); //ring
myservo4.attach(5); //pinky
myservo5.attach(6); //pointer
myservo7.attach(7); //swivel
} // end of setup
int middle, thumb, ring, pointer, rotation;
// here to process incoming serial data after a terminator received
void process_data (char * data)
{
// convert strings into numbers:
middle = atoi (strtok (data, ","));
thumb = atoi (strtok (NULL, ","));
ring = atoi (strtok (NULL, ","));
pointer = atoi (strtok (NULL, ","));
rotation = atoi (strtok (NULL, ","));
myservo1.write(middle);
myservo2.write(thumb);
myservo3.write(ring);
myservo4.write(ring);
myservo5.write(pointer);
myservo7.write(rotation);
// for now I am displaying what I got ...
Serial.print ("middle = ");
Serial.println (middle);
Serial.print ("thumb = ");
Serial.println (thumb);
Serial.print ("ring = ");
Serial.println (ring);
Serial.print ("pointer = ");
Serial.println (pointer);
Serial.print ("rotation = ");
Serial.println (rotation);
} // end of process_data
void loop()
{
static char input_line [MAX_INPUT];
static unsigned int input_pos = 0;
if (Serial.available () > 0)
{
char inByte = Serial.read ();
switch (inByte)
{
case TERMINATOR: // end of text
input_line [input_pos] = 0; // terminating null byte
// terminator reached! process input_line here ...
process_data (input_line);
// reset buffer for next time
input_pos = 0;
break;
case STARTER:
// reset buffer
input_pos = 0;
break;
default:
// keep adding if not full ... allow for terminating null byte
if (input_pos < (MAX_INPUT - 1))
input_line [input_pos++] = inByte;
break;
} // end of switch
} // end of incoming data
// do other stuff here like testing digital input (button presses) ...
} // end of loop
So does everything look good in that code then? It's still not working the receiving LED comes on but in the serial monitor of the receiving side there is nothing.
It just slows it down so you can get all 5 values at the same time. Because i am using 9600 i believe i do. This is just what i understood from the pictures a few pages back and your website.
I am using an arduino for all this also. Now should i just power these servos with the 5v and gnd from the arduino or something else? When i power it with the arduino it powers then restarts then repeats all that. I have a 7.2v 2200mah lipo battery that im using for all this. I am also powering the xbee too.
I certainly would not power them from the Arduino 5V line. That goes through a voltage regulator that is not designed to handle that amount of current. I assume (hope) you are using some kind of motor board to actually drive the motors. That should be independently powered, not from the Arduino's 5V line.
I made a custom shield that i have the digital lines from the arduino tied to then the power from the lipo battery. I have common grounds connected also. Should this work?
should i just power these servos with the 5v and gnd from the arduino or something else?
Certainly you should have the grounds common. I agree with that. And from the battery I would run a wire to the Arduino's "power in" socket (so it gets voltage regulated). And also direct from the battery to the motor shield.
So i fallowed this diagram and it works fine one thing with the code is that it is really jumpy and random. The fingers do move when i move mine but there is a weird delay and the servos are pretty much always moving no matter if i flex my hand or not. We are really close!!!