Pages: 1 2 [3]   Go Down
Author Topic: Arduino Uno ds18b20 and sure 2416 dor matrix display  (Read 1474 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Newbie
*
Karma: 0
Posts: 31
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I understand the kind of error but I don't know what I should write.


 
sensors.requestTemperatures();

float temp = sensors.getTempCByIndex(0);

Serial.println(temp,DEC);
      char buffer[8];
      dtostrf(temp,buffer,10);                                    <====== Float temp inside to buffer in decimal type but how change it ?
      ht1632_putchar(6 , 8, buffer[0]);
      ht1632_putchar(12 , 8, buffer[1]);
 //     ht1632_putchar(12 , 8, buffer[2]);
 //     ht1632_putchar(18 , 8, buffer[3]);
      ht1632_puttinychar(19 , 8, 'o');
      ht1632_putchar(24 , 8, 'C');
      delay(150); 


temp is the variable where the sensor give the reading of temperature
buffer is where temp goes

how convert by dtostrf float temp to buffer  ?


the error is

 dtostrf(double, signed char, unsigned char, char*)

what is double ?
what is signed char ?
what is unsigned char ?
what is char* ?

many thanks

Daniel
Logged

Temple, Texas
Offline Offline
Sr. Member
****
Karma: 14
Posts: 354
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

http://lmgtfy.com/?q=dtostrf&l=1

This has information about what the parameters need to be.  If you have trouble interpreting it, post back with what you tried and why  smiley

Cheers,
John
Logged

Seattle, WA USA
Online Online
Brattain Member
*****
Karma: 549
Posts: 46128
Seattle, WA USA
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
what is double ?
The value to be converted.

Quote
what is signed char ?
The width of the string to be produced. Why an signed char? Beats me.

Quote
what is unsigned char ?
The precision - the number of places after the decimal point. Why an unsigned char? Beats me.

Quote
what is char* ?
The buffer where the string is to be created.

Code:
float someTemp = 14.5;
char buffer[10];
dtostrf(someTemp, 8, 3, buffer);
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 31
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

many thanks for you help

here what I write

 
sensors.requestTemperatures();
//int temp = sensors.getTempCByIndex(0);
float temp = sensors.getTempCByIndex(0);

Serial.println(temp,DEC);
      char buffer[10];
   //     itoa(temp,buffer,10);
      dtostrf(temp, 8, 3, buffer);
      ht1632_putchar(6 , 8, buffer[0]);
      ht1632_putchar(12 , 8, buffer[1]);
      ht1632_putchar(18 , 8, buffer[2]);
      ht1632_putchar(24 , 8, buffer[3]);
      ht1632_puttinychar(32 , 8, 'o');
      ht1632_putchar(35 , 8, 'C');
      delay(150); 

in this way change only where the temp is writed on display

ie 22 degree is written in decimal position  _ _ , 22 °C

but without comma

where is the error ? I feel to be near to solution

Many thanks
Daniel
Logged

Temple, Texas
Offline Offline
Sr. Member
****
Karma: 14
Posts: 354
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I think you would do better to consider the code that Paul provided as an example and an opportunity to think about how it applies to your situation rather than something to just paste into your code and report back that it doesn't work.

You should ask yourself questions like
How wide do I want the number to be?  e.g. "22.51345" would be 8 wide
What precision do I want it to have ?   e.g. "-23.434"  would be a precision of 3.
and
Is my buffer[] big enough to hold it?
Do I have room to put it on the LCD buffer[0], buffer[1], buffer[2],... buffer[width-1]

Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 31
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

jhon thank you so much now with your details I've understand the meaning of it

I've changed the code here

float temp = sensors.getTempCByIndex(0);

Serial.println(temp,DEC);
      char buffer[10];
   //     itoa(temp,buffer,10);
      dtostrf(temp, 5, 2, buffer);
      ht1632_putchar(6 , 8, buffer[0]);
      ht1632_putchar(12 , 8, buffer[1]);
      ht1632_putchar(18 , 8, buffer[2]);
      ht1632_putchar(24 , 8, buffer[3]);
      ht1632_puttinychar(32 , 8, 'o');
      ht1632_putchar(37 , 8, 'C');
      delay(150); 

now works perfectly

many thanks
Logged

Temple, Texas
Offline Offline
Sr. Member
****
Karma: 14
Posts: 354
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Great!!  Then we'll leave it at that for now  smiley-wink
Logged

Seattle, WA USA
Online Online
Brattain Member
*****
Karma: 549
Posts: 46128
Seattle, WA USA
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

You are asking for 5 characters in the output, with two  digits after the decimal point, so something like 23.45. Then, you are showing 4 characters on the LCD (23.4). Why?
Logged

Pages: 1 2 [3]   Go Up
Jump to: