Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Output of int to serial
15-03-2016, 03:53 PM,
#1
Output of int to serial
Hallo,

I build my 45K50 and installed the software.
Now I am trying to output an int value to the serial interface.
The text part, ADC value : , is printing OK.
But the int value, A2D, gives rubbish.
I am using TeraTerm on Windows XP Pro SP3.

What am I doing wrong?

Code:
#define ThermistorPIN A0           // Sensor on pin A0
int A2D;

void setup()
{
  Serial.begin(9600);
  pinMode(ThermistorPIN, INPUT);
}

void loop()
{
  A2D = analogRead(ThermistorPIN);
  Serial.print("ADC value : ");
  Serial.println(A2D);
}

Greetings form The Netherlands,
Henk Siewert
Reply
15-03-2016, 04:29 PM,
#2
RE: Output of int to serial
Hallo,

I have rewritten my code.
Now it works.
But why does Serial.println(A2D); not work.
Is the Arduino translation buggie?

#define ThermistorPIN A0 // Sensor on pin A0
int A2D;

void setup()
{
Serial.begin(9600);
pinMode(ThermistorPIN, INPUT);
}

void loop()
{
A2D = analogRead(ThermistorPIN);
Serial.printf("ADC value : ");
Serial.printf("%d",A2D);
Serial.printf("\r\n");
delay(1000);
}
Reply
15-03-2016, 06:29 PM,
#3
RE: Output of int to serial
Serial.println or Serial.print requests 2 arguments : m as numerical value and type such as FLOAT, DEC, HEX, BYTE, OCT, BIN written in that way.
for your example : Serial.println (A2D,DEC)  should work as A2D is declared int.
Bye
André
Reply
19-03-2016, 12:06 PM,
#4
RE: Output of int to serial
Hallo André,

Thanks.
But I think I stick with the printf.
It gives me a good feeling being back doing real C again.
I will pull my C books from the bookcase, next to the CP/M and MS-DOS ones, and start enjoying myself again with coding real C.
Maybe I will send the Pinguino output to a real RS232C port and start using BASIC to show the result om the screen.
This is no joke. I mean it.
I will let you know the results.
Boy, this will be fun!

Henk Siewert
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)