I've got RR tracking an object and sending it's X position down the serial to the Arduino to move a servo. The Arduino is getting the info, but I'm not converting it to something the servos can use. I've tried a few examples I've found on the web, but nothing seems to work. RR is sending a value from 0 to 640. From what I gather RR is sending Ascii to the Arduino (I could be wrong on this). My sketch uses atoi to get an interger and maps it from 0 to 180 for the servo, but the servo just twitches wildly. I'm new to programming, so please speak slowly
Thanks
#include <Servo.h>
#define servoPin 9 // control pin for servo motor
Servo Scan; //The servo
char incomingData; // To hold value of data coming through COM port
int pos;
void setup()
{
pinMode(servoPin, OUTPUT);
Scan.attach(servoPin); //Attach servo
Serial.begin(9600);
}
void loop()
{
while(Serial.available() > 0) // Wait for data
{
incomingData = Serial.read();
int numericVal = atoi(&incomingData); //convert Ascii to interger
pos = map(numericVal, 0, 640, 0, 180); //map RoboRealm COGX position to servo range
Scan.write (pos);
//delay(10);
//Serial.print (pos);
}
}