Pages: 1 [2]   Go Down
Author Topic: help writing library  (Read 1317 times)
0 Members and 1 Guest are viewing this topic.
Seattle, WA USA
Offline Offline
Brattain Member
*****
Karma: 634
Posts: 50243
Seattle, WA USA
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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.
Logged

Offline Offline
Jr. Member
**
Karma: 0
Posts: 51
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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:
lcd.print(sensor.readpressure());

How do I print it in exponential form?
Logged

Seattle, WA USA
Offline Offline
Brattain Member
*****
Karma: 634
Posts: 50243
Seattle, WA USA
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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.
Logged

Offline Offline
Jr. Member
**
Karma: 0
Posts: 51
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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:
char buffer[10];
dtostrf(sensor.readpressure(), 10, 2, buffer);
  lcd.print(buffer);
But it doesn't seem to be adding the exponential notation.
Logged

North Queensland, Australia
Online Online
Edison Member
*
Karma: 74
Posts: 2214
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

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


Offline Offline
Jr. Member
**
Karma: 0
Posts: 51
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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.
Logged

Seattle, WA USA
Offline Offline
Brattain Member
*****
Karma: 634
Posts: 50243
Seattle, WA USA
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
Great thank you!  I have this now
Why? dtostrf() is not dtostre().
Logged

Offline Offline
Jr. Member
**
Karma: 0
Posts: 51
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Why? dtostrf() is not dtostre().

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

Thank you!
Logged

Seattle, WA USA
Offline Offline
Brattain Member
*****
Karma: 634
Posts: 50243
Seattle, WA USA
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
How do you use dtostre()?
Just like I use dtostrf(). I look it up. Using google.
Logged

Offline Offline
Jr. Member
**
Karma: 0
Posts: 51
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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:
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)'
Logged

Offline Offline
Edison Member
*
Karma: 26
Posts: 1339
You do some programming to solve a problem, and some to solve it in a particular language. (CC2)
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Uh ? Since when google turned into a compiler  smiley-evil

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

Offline Offline
Jr. Member
**
Karma: 0
Posts: 51
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Uh ? Since when google turned into a compiler  smiley-evil

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:
#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);
}
Logged

Seattle, WA USA
Offline Offline
Brattain Member
*****
Karma: 634
Posts: 50243
Seattle, WA USA
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

You obviously misread google:
Code:
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
Logged

Offline Offline
Jr. Member
**
Karma: 0
Posts: 51
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

You obviously misread google:
Code:
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. 
Logged

Pages: 1 [2]   Go Up
Jump to: