Hello Im a new Arduio user, im using Arduino Due board and receiving CAN-Signals which I convertet firstly into Strings in order to split them. Now that I put those Strings into the right order, I want to convert them into Int16_t values. Hier is the point where Im having problems. Tried with String1.toInt() and its taking only the first character of the String1! Tried with String1.substring(0,5).toInt() still not working(reading still only the first character). Tried also atoi(String1.c_str()) also not working! Can anyone help?
You might post your code using code tags </> to see if there are obvious errors. Below is some simple servo test code that seems to do the job ok.
// zoomkat 7-30-10 serial servo test
// type servo position 0 to 180 in serial monitor
// for writeMicroseconds, use a value like 1500
// Powering a servo from the arduino usually *DOES NOT WORK*.
String readString;
#include <Servo.h>
Servo myservo; // create servo object to control a servo
void setup() {
Serial.begin(9600);
myservo.attach(9);
}
void loop() {
while (Serial.available()) {
if (Serial.available() >0) {
char c = Serial.read(); //gets one byte from serial buffer
readString += c; //makes the string readString
delay(3);
}
}
if (readString.length() >0) {
Serial.println(readString);
int n = readString.toInt();
Serial.println(n);
myservo.writeMicroseconds(n);
//myservo.write(n);
readString="";
}
}