Hi guys,
I'm working on a little project. Basically I've got two small servos which I'm trying to control via serial.
I'm using HEX to send down my values to the Arduino.
I've got two little problems / queries though...
-
It works, however, it can be sporatic. I.e. the servos are moving but all of a sudden one of them wildly swings the wrong way.
-
This happens on other project but when I open the serial console in the Arduino IDE (or access the serial in other ways) it seems to effect the Arduino. Almost as if it's resetting it?
It doesn't seem to be the servos themselves as I've created a test sketch which cycles through the different directions. This works fine.
This is a snippet of the code which handles the Serial. Serial is set at 9600 baud (could this be causing it?)
if (Serial.available() > 0) {
inByte = Serial.read();
if (inByte == '#') {
while (pointer < 4) {
buffer[pointer] = Serial.read( ); // add the character to the buffer
pointer++; // increment the pointer
}
x = hex2dec(buffer[1]) + hex2dec(buffer[0]) * 16;
y = hex2dec(buffer[3]) + hex2dec(buffer[2]) * 16;
pointer = 0; // reset pointer;
}
}
If you're wondering what the hex2dec function does it's building on similar code from 'Getting Started with Arduino' - Getting Started with Arduino [Book].
Cheers,
James