Report
4 years, 2 months ago.

Serial Communication Issues

I am trying to use pc.printf to debug some code. I have used it lot's before without issue, now when I use it I get the following error code:

Error: Argument of type "float *" is incompatible with parameter of type "const char *" in "main.cpp", Line: 87, Col: 17

It is referring to the following code (line 3):

float readings [5] = { 350,370,400,360,290 }; read the values of the ADC pins (thermistors) into the "readings" array pc.printf("r1 = ");

pc.printf(readings, "\n\r" ); display the ADC Readings

I am no sure where "const char" has come from, wondering if it is a requirement that you can only send certain serial data to the PC?

Any thoughts would be much appreciated.

You need a variable type handler in the printf statement You have an array with 5 elements of type float so to 'print' each element you need a line such as:

pc.printf("%f\n\r",readings[n]); where n= element Number from zero to 4 for your case

Regards

posted by Martin Simpson 08 Jun 2015
Comment on this question

1 Answer

4 years, 2 months ago.

You are passing printf() a float pointer where it expects a character string. For more details on the printf format: http://www.cplusplus.com/reference/cstdio/printf/ To convert your float array to debug output I would suggest format flags in the following format:

Code Example

for(int n = 0; n < 5; n++) { pc.printf("Reading %d is %f\r\n", n, readings[n]); }


You need to log in to post a question