Hi,
I have a problem connecting Mega with Servo control 32 New version 3.2 for 32 servos. I need to control 20 servos via UART. I don't know how to proceed. I have +5V, GND, RX on pin 0, TX on pin 1.
Servo shield does not communicate.
Any advice?
Well, that's news to me. I am a beginner. So far I have controlled the servos using a library.
Is this a command? for example: #11P1500T500D500
This one is put into Serial.print ?
Because the sketch uses SoftwareSerial on those pins ?
The Mega has 4 hardware UARTs so there is no need to use SoftwareSerial. Just use Serial1, Serial2 or Serial3 on their associated Tx and Rx pins and keep Serial on pins 0 and 1 for debugging using the Serial monitor and uploading the code to the Mega
As to getting the value of a variable into the print command, assuming that you want to send #14 followed by the value of P then the value of T followed by Carriage Return and Linefeed, you could either print the values separately like this
//need to print #32P1500T100\r\n
char buffer[50]; //plenty of room for the outtput string (this is NOT a String !)
int servoNum = 32; //values to put in the string
int position = 1500;
int speed = 100;
void setup()
{
Serial.begin(115200);
snprintf(buffer, sizeof(buffer), "#%dP%dT%d\r\n", servoNum, position, speed);
Serial.print(buffer);
//let's change the values
servoNum = 10;
position = 1400;
speed = 200;
snprintf(buffer, sizeof(buffer), "#%dP%dT%d\r\n", servoNum, position, speed);
Serial.print(buffer);
}
void loop()
{
}