Go Down

Topic: help writing library (Read 1 time) previous topic - next topic

PaulS

Quote
How do I return a number in scientific notation with the exponents instead of in float form?

You don't. That's a method of presenting the data, not a way of storing/passing it.

ichris93


Quote
How do I return a number in scientific notation with the exponents instead of in float form?

You don't. That's a method of presenting the data, not a way of storing/passing it.


Okay then lets say my Arduino code was
Code: [Select]

lcd.print(sensor.readpressure());


How do I print it in exponential form?

PaulS

Quote
How do I print it in exponential form?

The Print class, which a lot of classes derive from, does not have a method to do that. The dtostre() function can be used to create a string, though, that the Print class can print.

ichris93


The Print class, which a lot of classes derive from, does not have a method to do that. The dtostre() function can be used to create a string, though, that the Print class can print.


Great thank you!  I have this now
Code: [Select]

char buffer[10];
dtostrf(sensor.readpressure(), 10, 2, buffer);
  lcd.print(buffer);

But it doesn't seem to be adding the exponential notation.

pYro_65

post what you are getting, if you make buffer large enough you can manipulate extra text in there.

ichris93


post what you are getting, if you make buffer large enough you can manipulate extra text in there.

Values from 0.97 to 177.70, formatted just like that.

PaulS

Quote
Great thank you!  I have this now

Why? dtostrf() is not dtostre().

ichris93


Why? dtostrf() is not dtostre().


:smiley-sweat:You're right.  How do you use dtostre()?

Thank you!

PaulS

Quote
How do you use dtostre()?

Just like I use dtostrf(). I look it up. Using google.

ichris93


Just like I use dtostrf(). I look it up. Using google.


I, too, used google to try to explain it when I tried using it just as I used dtostrf() and received this error.
Code: [Select]

print_w_display.cpp: In function 'void loop()':
print_w_display:14: error: invalid conversion from 'int' to 'char*'
print_w_display:14: error: initializing argument 2 of 'char* dtostre(double, char*, unsigned char, unsigned char)'
print_w_display:14: error: invalid conversion from 'char*' to 'unsigned char'
print_w_display:14: error: initializing argument 4 of 'char* dtostre(double, char*, unsigned char, unsigned char)'

tuxduino

Uh ? Since when google turned into a compiler  ]:)

Seriously, though, you should post _the whole code_ that generated the error together with the error..

ichris93


Uh ? Since when google turned into a compiler  ]:)

Seriously, though, you should post _the whole code_ that generated the error together with the error..


Okay, here is the code that gave me the previous error.
Code: [Select]

#include <Wire.h>
#include <LiquidCrystal_I2C.h>
#include <CONVECTRON.h>

CONVECTRON sensor(A0);

LiquidCrystal_I2C lcd(0b0111000,20,4);

void setup() {

}

void loop() {
  char buffer[10];
  dtostre(sensor.readpressure(), 10, 2, buffer);
  lcd.init();
  lcd.backlight();
  lcd.print(buffer);
  delay(1000);
}

PaulS

You obviously misread google:
Code: [Select]
char * dtostre (double __val, char *__s, unsigned char __prec, unsigned char __flags)
The 2nd argument is where to write to, not the 4th.

https://ccrma.stanford.edu/courses/250a/docs/avr-libc-user-manual-1.2.5/group__avr__stdlib.html

ichris93


You obviously misread google:
Code: [Select]
char * dtostre (double __val, char *__s, unsigned char __prec, unsigned char __flags)
The 2nd argument is where to write to, not the 4th.

https://ccrma.stanford.edu/courses/250a/docs/avr-libc-user-manual-1.2.5/group__avr__stdlib.html


You're quite right.  I saw it and just assumed it was exactly the same as the dtostrf() and could use the same format.  Now I have it working properly.  I really appreciate your help, thank you. 

Go Up