Go Down

Topic: Serial.Print() of printf'ed variable - corrupt output? (Read 251 times) previous topic - next topic

jdeluyck

Hey folks,

I'm toying with some existing arduino code to read out some TCRT sensors. this all works fine, but I'm getting stumped by the following behaviour:

In parts of the code, I want to print out the values I'm getting back from the sensor. When doing this through a simple Serial.print(var) - I get the values fine.

On the other hand - when using printf(var, ...) - all I get back is corrupted output.

Baud settings etc are fine. I'm using an arduino nano.

Anyone any idea?

Code: [Select]

 Serial.println(thresholdSampleCounter);
  Serial.println(threshold1L);
  Serial.println(threshold1H);
  Serial.println(last1);
  Serial.println(threshold2L);
  Serial.println(threshold2H);
  Serial.println(last2);
  char message[40];
  printf(message,"C=%d\n1=%d-%d : %s\n2=%d-%d : %d",  thresholdSampleCounter, threshold1L,threshold1H, last1, threshold2L, threshold2H, last2);
  Serial.println(message);


output:

998
314
393
3744
3148
3200
4362
⸮M ⸮

Delta_G

How did you go about enabling printf for the Arduino?
|| | ||| | || | ||  ~Woodstock

Please do not PM with technical questions or comments.  Keep Arduino stuff out on the boards where it belongs.

wildbill


jdeluyck

Oh, god, I feel so stupid now :p

Indeed, had to be sprintf(). *cough*

Sorry for the noise.

Go Up