Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
DS18B20 FAHRENHEIT ACCURACY
30-10-2015, 01:36 AM,
#11
RE: DS18B20 FAHRENHEIT ACCURACY
Code:
#define ONEWIREBUS    2

int ifar;
int ffar;


void setup() {
 //DS18B20.begin(ONEWIREBUS);
 // put your setup code here, to run once:    
}

void loop() {


TEMPERATURE t;
   ifar = t.integer * 100;
        ifar += t.fraction;

        ifar = ((ifar * 1.8)  + 3200);
        ffar = ifar % 100;  
        ifar /= 100;
    // TEMPERATURE t;
     if (DS18B20.read(ONEWIREBUS, SKIPROM, RES9BIT, &t)) {
   
         CDC.println("");
         CDC.printf("  %d.%d F \r\n", ifar,ffar);
         CDC.printf(" %d.%d C \r\n" ,t.integer,t.fraction);
         
}
}
i ran many tests tonight with ice and heat from a candle measuring both celsius and fahrenheit and my temps are right on. I have not seen any negative values in the higher temp range.
thank you 
fred
Reply
30-10-2015, 11:37 AM, (This post was last modified: 30-10-2015, 11:38 AM by pingotg.)
#12
RE: DS18B20 FAHRENHEIT ACCURACY
I'm puzzled why it was at 96, but you might try changing
ifar = ((ifar * 9) / 5) + 3200;
to
ifar = (((long)ifar * 9) / 5) + 3200;

instead of using floating point.

In case that causes a compiler warning, cast it to int:
ifar = (int) (((long)ifar * 9) / 5) + 3200;

John
Reply
30-10-2015, 03:08 PM,
#13
RE: DS18B20 FAHRENHEIT ACCURACY
(30-10-2015, 11:37 AM)pingotg Wrote: I'm puzzled why it was at 96, but you might try changing
ifar = ((ifar * 9) / 5) + 3200;
to
ifar = (((long)ifar * 9) / 5) + 3200;

instead of using floating point.

In case that causes a compiler warning, cast it to int:
ifar = (int) (((long)ifar * 9) / 5) + 3200;

John

John, 
I will try that tonight
 thank you
fred
Reply
30-10-2015, 08:58 PM,
#14
RE: DS18B20 FAHRENHEIT ACCURACY
Hi,
I tested it with my Pinguino2550.
Just declare ifar and ffar "unsigned" and it will work:
u16 ifar;
u8 ffar;

Luca
Reply
30-10-2015, 11:39 PM,
#15
RE: DS18B20 FAHRENHEIT ACCURACY
(30-10-2015, 08:58 PM)brikker Wrote: Hi,
I tested it with my Pinguino2550.
Just declare ifar and ffar "unsigned" and it will work:
u16 ifar;
u8 ffar;

Luca

luca,
which sketch did you use?
thanks
fred
Reply
31-10-2015, 12:07 AM,
#16
RE: DS18B20 FAHRENHEIT ACCURACY
Hi Derf,
I used this code:


Code:
/*-----------------------------------------------------
Author:  --<>
Date: 2015-10-23
Description:

-----------------------------------------------------*/
#define ONEWIREBUS    2

// Vars
int led_handle = 0;

char temp_sign = 0;
u16 ifar;
u8 ffar;

// Functions

void TMR3_Tick() {
   led_handle = (led_handle ^ 1);
   digitalWrite(USERLED, led_handle);
}

void setup() {
   pinMode(USERLED, OUTPUT);
   digitalWrite(USERLED, HIGH);
   
   OnTimer3(TMR3_Tick, INT_MILLISEC, 500);
}

void loop() {

       TEMPERATURE t;
       if (DS18B20.read(ONEWIREBUS, SKIPROM, &t)) {
           if (t.sign) {
               temp_sign = 45;                      // ascii "-"
           } else {
               temp_sign = 43;                      // ascii "+"
           }

           ifar = t.integer * 100;
           ifar += t.fraction;

           ifar = ((ifar * 9) / 5) + 3200;
           ffar = ifar % 100;
           ifar /= 100;
           
           CDC.printf("Temp: %c%02d.%02d C || %c%03d.%02d F\r\n",  temp_sign, t.integer, t.fraction, temp_sign, ifar,ffar);
       }          
           delay(2000);
}
which output:


Code:
Temp: +20.50 C || +068.90 F
Temp: +20.50 C || +068.90 F
Temp: +20.50 C || +068.90 F
Temp: +20.50 C || +068.90 F
Temp: +20.00 C || +068.00 F
Temp: +20.00 C || +068.00 F
Temp: +20.00 C || +068.00 F
Temp: +20.00 C || +068.00 F
Temp: +20.00 C || +068.00 F
Temp: +20.50 C || +068.90 F
Temp: +20.00 C || +068.00 F
Temp: +20.00 C || +068.00 F
Temp: +20.00 C || +068.00 F
Temp: +20.00 C || +068.00 F
Temp: +20.00 C || +068.00 F
Temp: +24.00 C || +075.20 F
Temp: +35.50 C || +095.90 F
Temp: +46.00 C || +114.80 F
Temp: +53.00 C || +127.40 F
Temp: +57.50 C || +135.50 F
Temp: +59.50 C || +139.10 F
Temp: +58.50 C || +137.30 F


I didn't test under zero, but it should work
try it and let me know!
Luca
Reply
31-10-2015, 12:34 AM, (This post was last modified: 31-10-2015, 02:04 AM by derf158.)
#17
RE: DS18B20 FAHRENHEIT ACCURACY
(31-10-2015, 12:07 AM)brikker Wrote: Hi Derf,
I used this code:




Code:
/*-----------------------------------------------------
Author:  --<>
Date: 2015-10-23
Description:

-----------------------------------------------------*/
#define ONEWIREBUS    2

// Vars
int led_handle = 0;

char temp_sign = 0;
u16 ifar;
u8 ffar;

// Functions

void TMR3_Tick() {
   led_handle = (led_handle ^ 1);
   digitalWrite(USERLED, led_handle);
}

void setup() {
   pinMode(USERLED, OUTPUT);
   digitalWrite(USERLED, HIGH);
   
   OnTimer3(TMR3_Tick, INT_MILLISEC, 500);
}

void loop() {

       TEMPERATURE t;
       if (DS18B20.read(ONEWIREBUS, SKIPROM, &t)) {
           if (t.sign) {
               temp_sign = 45;                      // ascii "-"
           } else {
               temp_sign = 43;                      // ascii "+"
           }

           ifar = t.integer * 100;
           ifar += t.fraction;

           ifar = ((ifar * 9) / 5) + 3200;
           ffar = ifar % 100;
           ifar /= 100;
           
           CDC.printf("Temp: %c%02d.%02d C || %c%03d.%02d F\r\n",  temp_sign, t.integer, t.fraction, temp_sign, ifar,ffar);
       }          
           delay(2000);
}
which output:




Code:
Temp: +20.50 C || +068.90 F
Temp: +20.50 C || +068.90 F
Temp: +20.50 C || +068.90 F
Temp: +20.50 C || +068.90 F
Temp: +20.00 C || +068.00 F
Temp: +20.00 C || +068.00 F
Temp: +20.00 C || +068.00 F
Temp: +20.00 C || +068.00 F
Temp: +20.00 C || +068.00 F
Temp: +20.50 C || +068.90 F
Temp: +20.00 C || +068.00 F
Temp: +20.00 C || +068.00 F
Temp: +20.00 C || +068.00 F
Temp: +20.00 C || +068.00 F
Temp: +20.00 C || +068.00 F
Temp: +24.00 C || +075.20 F
Temp: +35.50 C || +095.90 F
Temp: +46.00 C || +114.80 F
Temp: +53.00 C || +127.40 F
Temp: +57.50 C || +135.50 F
Temp: +59.50 C || +139.10 F
Temp: +58.50 C || +137.30 F


I didn't test under zero, but it should work
try it and let me know!
Luca

Code:
#define ONEWIREBUS    2                        
u16 ifar;
u8 ffar;                            

void setup()
{
}

void loop()
{
    TEMPERATURE t;
    ifar = t.integer * 100;
         ifar += t.fraction;
        // ifar = (((long)ifar * 9) / 5) + 3200;
         ifar = ((ifar * 9) / 5) + 3200;
         ffar = ifar % 100;  
         ifar /= 100;
    if (DS18B20.read(ONEWIREBUS, SKIPROM,  &t))
    {
        if (t.sign) CDC.printf("-");
        CDC.printf("%d.%dC \n", t.integer, t.fraction);
        CDC.printf("%d.%dF \n", ifar, ffar);
    }
    delay(1000);
}
this is what i tried and it works but temperature would not go above 130.40 F using on a candle my infrared temp sensor was displaying 190 F 
Reply
31-10-2015, 02:11 AM,
#18
RE: DS18B20 FAHRENHEIT ACCURACY
(31-10-2015, 12:34 AM)derf158 Wrote:
(31-10-2015, 12:07 AM)brikker Wrote: Hi Derf,
I used this code:





Code:
/*-----------------------------------------------------
Author:  --<>
Date: 2015-10-23
Description:

-----------------------------------------------------*/
#define ONEWIREBUS    2

// Vars
int led_handle = 0;

char temp_sign = 0;
u16 ifar;
u8 ffar;

// Functions

void TMR3_Tick() {
   led_handle = (led_handle ^ 1);
   digitalWrite(USERLED, led_handle);
}

void setup() {
   pinMode(USERLED, OUTPUT);
   digitalWrite(USERLED, HIGH);
   
   OnTimer3(TMR3_Tick, INT_MILLISEC, 500);
}

void loop() {

       TEMPERATURE t;
       if (DS18B20.read(ONEWIREBUS, SKIPROM, &t)) {
           if (t.sign) {
               temp_sign = 45;                      // ascii "-"
           } else {
               temp_sign = 43;                      // ascii "+"
           }

           ifar = t.integer * 100;
           ifar += t.fraction;

           ifar = ((ifar * 9) / 5) + 3200;
           ffar = ifar % 100;
           ifar /= 100;
           
           CDC.printf("Temp: %c%02d.%02d C || %c%03d.%02d F\r\n",  temp_sign, t.integer, t.fraction, temp_sign, ifar,ffar);
       }          
           delay(2000);
}
which output:





Code:
Temp: +20.50 C || +068.90 F
Temp: +20.50 C || +068.90 F
Temp: +20.50 C || +068.90 F
Temp: +20.50 C || +068.90 F
Temp: +20.00 C || +068.00 F
Temp: +20.00 C || +068.00 F
Temp: +20.00 C || +068.00 F
Temp: +20.00 C || +068.00 F
Temp: +20.00 C || +068.00 F
Temp: +20.50 C || +068.90 F
Temp: +20.00 C || +068.00 F
Temp: +20.00 C || +068.00 F
Temp: +20.00 C || +068.00 F
Temp: +20.00 C || +068.00 F
Temp: +20.00 C || +068.00 F
Temp: +24.00 C || +075.20 F
Temp: +35.50 C || +095.90 F
Temp: +46.00 C || +114.80 F
Temp: +53.00 C || +127.40 F
Temp: +57.50 C || +135.50 F
Temp: +59.50 C || +139.10 F
Temp: +58.50 C || +137.30 F


I didn't test under zero, but it should work
try it and let me know!
Luca

Code:
#define ONEWIREBUS    2                        
u16 ifar;
u8 ffar;                            

void setup()
{
}

void loop()
{
    TEMPERATURE t;
    ifar = t.integer * 100;
         ifar += t.fraction;
        // ifar = (((long)ifar * 9) / 5) + 3200;
         ifar = ((ifar * 9) / 5) + 3200;
         ffar = ifar % 100;  
         ifar /= 100;
    if (DS18B20.read(ONEWIREBUS, SKIPROM,  &t))
    {
        if (t.sign) CDC.printf("-");
        CDC.printf("%d.%dC \n", t.integer, t.fraction);
        CDC.printf("%d.%dF \n", ifar, ffar);
    }
    delay(1000);
}
this is what i tried and it works but temperature would not go above 130.40 F using on a candle my infrared temp sensor was displaying 190 F 
Code:
#define ONEWIREBUS    2
#define RES_12BIT
                        
char temp_sign = 0;    
u16 ifar;
u8 ffar;                

void setup()
{
}
void loop()
{
    TEMPERATURE t;
       if (t.sign) {
              temp_sign = 45;                      // ascii "-"
          } else {
              temp_sign = 43;                      // ascii "+"
          }
         
    ifar = t.integer * 100;
         ifar += t.fraction;

         ifar = ((ifar * 1.8)  + 3200);
         ffar = ifar % 100;  
         ifar /= 100;
    if (DS18B20.read(ONEWIREBUS, SKIPROM,  &t))
{                
    CDC.printf("Temp: %c%2d.%02d C || %c%3d.%02d F\r\n",  temp_sign, t.integer, t.fraction, temp_sign, ifar,ffar);
    
                                 
                 
    }
    delay(1000);
}
this is what i have now and my temp will measure above 130.40 F and i went down to 32 F
Reply
31-10-2015, 02:36 AM,
#19
RE: DS18B20 FAHRENHEIT ACCURACY
Code:
#define ONEWIREBUS    2
#define RES_12BIT
                        
char temp_sign = 0;    
u16 ifar;
u8 ffar;                

void setup()
{
pinMode(13,OUTPUT);
}
void loop()
{
    TEMPERATURE t;
       if (t.sign) {
              temp_sign = 45;                      // ascii "-"
          } else {
              temp_sign = 43;                      // ascii "+"
          }
         
    ifar = t.integer * 100;
         ifar += t.fraction;
         ifar = (((long)ifar * 9) / 5) + 3200;
         //ifar = ((ifar * 1.8)  + 3200);
         ffar = ifar % 100;  
         ifar /= 100;
    if (DS18B20.read(ONEWIREBUS, SKIPROM,  &t))
{                
    CDC.printf("Temp: %c%2d.%02d C || %c%3d.%02d F\r\n",  temp_sign, t.integer, t.fraction, temp_sign, ifar,ffar);
    if (ifar > 73) {
   digitalWrite(13, HIGH);
   
 }
 else {
   digitalWrite(13,LOW);
   
 }
                                 
                 
    }
    delay(1000);
}
this also works
Reply
31-10-2015, 09:52 AM,
#20
RE: DS18B20 FAHRENHEIT ACCURACY
Hi Derf,

you were right, I didn' t thought on it.
See this page: http://wiki.pinguino.cc/index.php/Data_types
if ifar is u16 then the max value for the multiply is 65535
then if you consider the max temperature which can be read by the sensor (125C), will return 125*100*9= 112500 which is bigger then the value limit of 65535.
You can change the declaration of ifar to u32 or doing as you did above.

I still do not understand why you make calculation before reading the sensor:
t.sign, t.integer and t.fraction are available after the reading of the sensor.
If you call them before, at first powerup you will get some wrong value, then you are going to display the previous value.
The actual temperature is dispalyed only on next cycle.
Correct me if I am wrong.

Luca
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)