Hello Guys. I have a project which is controlling 2 servos at the same time. I have already made a GUI via Visual studio2015 (C#) which gets some information like distance,height and width of an object from the user and calculate 2 angles( XAngle and YAngle). I put these two angles in to a string and send it via serialport1.write(myString) to arduino. Then i make a function called ReceiveData which receives the data and saves it to the string and then convert it to an integer. But the serial communication doesnt go very wel by me. If anyone can help me out controlling 2 servo's with a reliable serial com i would appreciate it. Thanks
Also it is not a good idea to use the String class in the small memory of an Arduino.
Have a look at the examples in Serial Input Basics - simple reliable ways to receive data. As you can modify the PC program the system in the 3rd example will be most reliable. There is also a parse example.
Thanks it helped. But i need to split the data because i need 2 angles (X,Y) and my angles are between 0 and 90. How can i convert the first 2 char to integers?Thanks
The first two characters of what? What follows those characters?
The usual process involves copying the first 3 characters (up to and including the separator) to another string, and then replacing the separator with a NULL. Then, atoi() is useful.
as an example if <8080> is my String(two combined angles which makes each 80 degrees) i want them to be coverted to an integer 80 each. How can i do it?
Because i need to send 2 different angles (X and Y) which its range is from 0 to 90 from pc to arduino. I wanna find a reliable way to send it and read it in arduino. plus i dont know how to convert it to an integer which makes my arduino program to control 2 servos.
sx1_9:
Because i need to send 2 different angles (X and Y) which its range is from 0 to 90 from pc to arduino. I wanna find a reliable way to send it and read it in arduino. plus i dont know how to convert it to an integer which makes my arduino program to control 2 servos.
You seem not to have read Serial Input Basics carefully. The parse example uses the technique @PaulS recommends - <80,80>. Using that system there is no confusion.
Because i need to send 2 different angles (X and Y) which its range is from 0 to 90 from pc to arduino.
So, if the first value is 9 and the second is 7, you'll send <97>?
How ARE you formatting the data to send? If you are not sending 9 and 7 as <0907>, you haven't a hope in hell of interpreting <135>. Is that 1 and 35? Or is it 13 and 5?
If you do not KNOW, then you MUST use a better means of communication.