0
votes

For my project i have two servos and i need to set them to the right angle every time the program loops. In order do this i use a serial usb connection and send a number to set one of the servos. But for the second servo i need to pass two numbers in one message. I was thinking about a string "X,Y" that i could send and split it between the comma on the arduino, but it seems that i can only send numbers and only 1 number at that over the serial port? How would i go about doing this.

Serial.write("90,90");//does not work...
2
The code you posted Serial.write("90,90");//does not work... is on the PC sending the commands or on the arduino? I only ask because according to your question you are sending values to the arduino. Could you post the code you use to send the commands with? Posting the code you use to receive them would also be helpful.cstrutton

2 Answers

1
votes

According to the documentation, a call such as Serial.write("90,90"); should work and will result in the given string being sent. There's no mention of the comma having some separate meaning.

You should probably check the return value.

0
votes

You can do:

Serial.write(90);
Serial.write(90);

Or:

 byte buf[] = {90, 90};
 Serial.write(buf, sizeof buf);