Hi, I have a problem, Im trying to read instructions from a python program over the serial port on the arduino but I need to read it as decimal not ascii, How can I convert the read instruction to read decimal instead of ascii on the arduino side?
You can capture the string of numeric characters sent to the arduino as a character String, then convert that String into a number. Info link and example below.
// zoomkat 10-14-11 serial servo test
// use a microseconds value like 1500 in serial monitor
// for IDE 0022 and later
// 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.writeMicroseconds(1500); //set initial servo position if desired
myservo.attach(7); //the pin for the servo control
Serial.println("servo-test-22"); // so I can keep track of what is loaded
}
void loop() {
while (Serial.available()) {
char c = Serial.read(); //gets one byte from serial buffer
readString += c; //makes the string readString
delay(2); // allow buffer to fill with next character
}
if (readString.length() >0) {
Serial.println(readString); //so you can see the captured string
myservo.writeMicroseconds(readString.toInt()); //convert readString to number for servo
readString=""; //empty for next input
}
}