I have a servo motor (http://robokits.download/documentation/RMCS220x_DCServo_Driver.pdf). I wrote a code in Arduino to rotate it in some defined angles and position. Code is given below:
#include <SoftwareSerial.h>
// software serial #1: RX = digital pin 10, TX = digital pin 11
// I have Arduino Uno so I created extra RX and TX to send and receive data.
// Becuase using inbuilt RX0 and TX0, I was unable to transfer data to motor
// and get feedack in PC
SoftwareSerial serial1(10, 11);
void setup()
{
Serial.begin(9600);
serial1.begin(9600);
}
void loop()
{
if (Serial.available() > 0)
{
delay(5);
serial1.println(Serial.readString());
}
if (serial1.available() > 0)
{
delay(5);
Serial.println(serial1.readString());
delay(5);
}
}
Using this code what I am able to do is, in terminal I enter some value say "G400" or "R821" etc. and motor rotate accordingly. But, this is not my aim. I don't want to put values manually, instead I used matlab script which give me some angle after calculations. I have to send this value to motor. Say, after calculations, matlab gives 26.4 degree, then I have input value to motor 26.4/0.2 = 132 counts i.e. "G132". Value changes every time for next calculation it may be 40 degree. What should be the coding for this in Arduino as well as in MATLAB.
Thanks.