Go Down

Topic: error: statement cannot resolve address of overloaded function - Uart.println (Read 308 times) previous topic - next topic

danb35

I'm working on some code on a Teensy 2.0 to read a pressure sensor, turn that input into a text string, and output that string using the onboard hardware serial.  Here's the code that I think is most directly relevant:

Code: [Select]
char outString[17];
HardwareSerial Uart = HardwareSerial();
float pressure = 0;

    sprintf(outString,"OPT,%04.4,0000",pressure);
    Uart.println (outString);


When I attempt to compile, it errors out with the error in the subject, and the last line (Uart.println) marked.  A web search suggests that this error comes up when you forget a () following a function call, but that doesn't seem to be the case here.  Any ideas what's up?

As an unrelated question, I'm not at all sure my sprintf expression makes any sense.  What I'm trying to do is turn the pressure reading into a four-digit integer, padded with zeroes as appropriate.  So, if pressure=85.2, the string should read OPT,0085,0000.

Complete code is below:

Code: [Select]

const int sensorInPin = A0;
const int warningInPin = A1;
const int ledOutPin = 11;

unsigned long previousMillisPoll = 0;
unsigned long previousMillisFlash = 0;
unsigned long currentMillis = 0;
long pollInterval = 250; // poll every 250 ms
long flashInterval = 125; // 4 Hz flash (8 transitions/sec)

int ledState = LOW;
boolean warningFlag = false;
boolean debug = true;
int sensorValue = 0;
int warningValue = 0;
float pressureMultiplier = 4.982; // experimentally derived - divide sensor reading by this to yield PSI

char outString[17];

HardwareSerial Uart = HardwareSerial();

float pressure = 0;


void setup() {
  pinMode (ledOutPin, OUTPUT);
  if (debug == true) {
    Serial.begin (38400);
  }
  Uart.begin (9600);
  warningValue = analogRead(warningInPin);
}

void loop() {
  currentMillis = millis();
  if (currentMillis - previousMillisPoll > pollInterval) {
    previousMillisPoll = currentMillis;
    sensorValue = analogRead (sensorInPin);
    pressure = sensorValue / pressureMultiplier;
    if ( sensorValue < warningValue) {
      warningFlag = true;
    }
    else {
      warningFlag = false;
    }
    sprintf(outString,"OPT,%04.4,0000",pressure);
    Uart.println (outString);
    if (debug == true) {
      Serial.print ("Warning Value: ");
      Serial.println (warningValue);
      Serial.print ("Sensor Value: ");
      Serial.println (sensorValue);
      Serial.print ("Calculated Pressure: ");
      Serial.println (pressure);
      Serial.println (outString);
      Serial.println ;
    }
  }
  if (warningFlag == true && currentMillis - previousMillisFlash > flashInterval) {
    previousMillisFlash = currentMillis;
    if (ledState == LOW) ledState = HIGH;
    else ledState = LOW;
    digitalWrite (ledOutPin, ledState);
  }
}

PaulS

If you are using the Arduino libraries, there is already an instance of the HardwareSerial class created, tied to the hardware serial pins.

If you aren't, you should be asking on the Teensy forum.

Quote
I'm not at all sure my sprintf expression makes any sense.

I am. They don't. A format specifier starts with a % and ends with the type of output to produce (d for int, f for float, etc.). In between are padding, width and precision values. %04.4 is missing the type. Having a width of 4, with 4 characters after the decimal point doesn't make sense, either. The width needs to be at least two more than the number of digits after the decimal point, to allow for one before and the decimal point.

danb35

I believe I'm using the Arduino libraries--I'm using the Arduino IDE, anyway; how would I determine what libraries I'm using?  I'm afraid I don't quite understand what "there is already an instance of the HardwareSerial class created" means with respect to my code--should I omit the line "HardwareSerial Uart = HardwareSerial();"?

PaulS

Quote
how would I determine what libraries I'm using?

Post your code - ALL of it - if you don't know.

Quote
I don't quite understand what "there is already an instance of the HardwareSerial class created" means with respect to my code--should I omit the line "HardwareSerial Uart = HardwareSerial();"?

Of course you should.

danb35

I did post all my code in my first post.  Upon further investigation, it looks like the compiler was flagging the wrong line as causing the error--it was actually the line where I wrote Serial.println;.  When I added the parens to that to read Serial.println();, the code now compiles.  I'll need to read up a bit on sprintf to get that expression correct, but it otherwise appears to be working as expected.

vaj4088

The compiler flags the correct line AS IT SEES IT.

However, the Arduino IDE "helps" you by adding code to what you wrote prior to submitting your code to the compiler.  Thus, what you wrote and what the compiler flags are two different things.     :(

There is a way to get the Arduino IDE to tell you where it stored the real source code that was compiled by the compiler.  The details vary depending upon which version of the IDE you are using.  This is one of the issues that caused me to drop the Arduino IDE and go with a different one.  Having a different IDE, I can't tell you how to turn on the Arduino IDE option for this.


Go Up