Go Down

Topic: Serial.print problem (Read 365 times) previous topic - next topic

alkopop79

I've been trying to interface a Duemilanove with Processing, Max/MSP and Pure Data and read an analog input. I've done this dozens of times with no problem yet this time I don't get the values I'm expecting. Whichever software the board is interfaced, I only useless, get two-digit values instead of the 0-1024. I get the correct values in the Arduino serial monitor but only there. I tried different baud rates, installed the latest FTDI driver, tried hex and decimal encoding with no success. I haven't tried the Firmata. This is the code:


void setup() {
  Serial.begin(9600);
}
void loop() {
  int val = analogRead(0);
  Serial.print(val,DEC)
  delay(50);
}


Any ideas?

alkopop79

I guess the serial values are sent as ASCII characters since I get two-digit values around 50. How can I get around this problem?

PaulS

Quote
I guess the serial values are sent as ASCII characters since I get two-digit values around 50.

They are, if you use Serial.print().

Quote
How can I get around this problem?

What problem? If the "problem" is that the data is being sent as ASCII data, then stop doing that. Use Serial.write() instead. Keep in mind, though, that Serial.write() only sends bytes, not ints.

Go Up