Can't get dtostrf to work. just returns spaces

Status
Not open for further replies.

gwpt

Member
I am trying to convert a float to string to display on an LCD

I found the many variants of the following snippet in discussions online, but when I run it (On a Tennsy 3.2) I just get spaces (In the example below, 7 of them)

Code:
char buff[100];
float val = 23.5;
dtostrf(val, 7, 2, buff);


Any idea what I could be doing wrong?
 
Teensy 3.2, Arduino IDE 1.8.13, Teensyduino 1.53, I see no issue:

Sketch:
Code:
void setup() {
  Serial.begin(115200);
}

void loop() {
  char buff[100];
  float val = 23.5;
  dtostrf(val, 7, 2, buff);
  Serial.println(buff);
  delay(1000);
}

Console:
Code:
  23.50

  23.50

  23.50

  23.50

  23.50

  23.50

  23.50

  23.50

  23.50

  23.50
 
Thanks, I tried that code and it on it's own but not in my app.
So, I stripped the app back and it turned out that I had an Array which must have been allocated too much RAM.
When I reduced it's size, dtostrf started to work
 
Status
Not open for further replies.
Back
Top