I'm very glad that I've entered Arduino world. I hope you can help me with my issue.
I'm trying the SerialServo.pde example from SoftwareServo.zip downloaded form The Software Servo page [1], I believe the software waits for user to chose between two servos by sending "A" or "B" by serial monitor interface then it waits user to enter the angle by sending a number between 0-9.
The example code seems to stuck in any "switch case loop" it enter and never continue. I've added some debug code and found that when I send "A" or "B" it does not accept any input after it. With my modified code I can only control both of the servos together.
Do the example code have any problems, Or what? I provided the original example and my modification for debugging.
When you say "refuses to accept any more input", are you saying that your debug version shows that you never enter the case'0'..'9' ? Or that the servos never move? If you enter ABA do you get ABA return?
I am not familiar with the SoftwareServo library, so I am assuming it behaves the same way as the hardware servo library. Have you tried the "normal" servo library?
Sorry I wrote "escapes" it actually stuck in the "switch case loop"
Msquare:
OK, the flaw escapes me, too.
When you say "refuses to accept any more input", are you saying that your debug version shows that you never enter the case'0'..'9' ? Or that the servos never move? If you enter ABA do you get ABA return?
debug version shows that it enter the case'0'..'9' and servos move but only if I did not press A or B. when I enter A or B it does not accept any thing afterward.
I am not familiar with the SoftwareServo library, so I am assuming it behaves the same way as the hardware servo library. Have you tried the "normal" servo library?
Thank you for trying to help. I don't think it's related to the library. anyway other codes works for moving servos but this one allow me (if it did work) to chose which one to run between the two servos.
I believe the software waits for user to chose between two servos by sending "A" or "B" by serial monitor interface
It doesn't wait. It just does nothing until that happens.
then it waits user to enter the angle by sending a number between 0-9.
No. It doesn't wait. If you enter A108, the A servo will move to 1, then 10, then 108.
Not an intelligent design, since there is no way to reset the value. If you enter A108 followed by B90, the B servo will jump to position 1089 when the 9 is read.
Also, attaching the servo every time an A or B is received is not necessary.
I've modified the code to help me debug the issue and it's like this.
Why are you now moving both servos to the same position?
Why are you using SoftwareServo?
Shitcan that awful code. Write some code to receive something like "" or "". This code can receive the information:
#define SOP '<'
#define EOP '>'
bool started = false;
bool ended = false;
char inData[80];
byte index;
void setup()
{
Serial.begin(57600);
// Other stuff...
}
void loop()
{
// Read all serial data available, as fast as possible
while(Serial.available() > 0)
{
char inChar = Serial.read();
if(inChar == SOP)
{
index = 0;
inData[index] = '\0';
started = true;
ended = false;
}
else if(inChar == EOP)
{
ended = true;
break;
}
else
{
if(index < 79)
{
inData[index] = inChar;
index++;
inData[index] = '\0';
}
}
}
// We are here either because all pending serial
// data has been read OR because an end of
// packet marker arrived. Which is it?
if(started && ended)
{
// The end of packet marker arrived. Process the packet
// Reset for the next packet
started = false;
ended = false;
index = 0;
inData[index] = '\0';
}
}
Where it says Process the packet, write some code to copy the first letter in inData, change that first letter to a space, and call atoi() on the rest of it. Move the appropriate servo, based on the copied first letter.