Arduino temperature sensor negative temperatures -


when measuring negative temperatures not show me correct values on led output. see 4983. need advice code.

i using arduino uno. type of senzor: ds18b20

code:

#include <spi.h> #include <wire.h> #include <adafruit_gfx.h> #include <adafruit_ssd1306.h> #define oled_mosi 9 #define oled_clk 10 #define oled_dc 11 #define oled_cs 12 #define oled_reset 13 adafruit_ssd1306 display (oled_mosi, oled_clk, oled_dc, oled_reset, oled_cs); #define numflakes 10 #define xpos 0 #define ypos 1 #define deltay 2 #define logo16_glcd_height 16 #define logo16_glcd_width 16 static const unsigned char progmem logo16_glcd_bmp [] = {b00000000, b11000000, b00000001, b11000000, b00000001, b11000000, b00000011, b11100000, b11110011, b11100000, b11111110, b11111000, b01111110, b11111111, b00110011, b10011111, b00011111, b11111100, b00001101, b01110000, b00011011, b10100000, b00111111, b11100000, b00111111, b11110000, b01111100, b11110000, b01110000, b01110000, b00000000, b00110000};  #if (ssd1306_lcdheight! = 64) #error ("error, adafruit_ssd1306.h!"); #endif #include <onewire.h> onewire ds (2);  void setup () { display.begin (ssd1306_switchcapvcc, 0x3c); display.cleardisplay ();  }  void loop () {   byte i; byte present = 0; byte data[12]; byte addr[8];  if (! ds.search (addr)) { serial.print ("\ n"); ds.reset_search (); return; }  ds.reset (); ds.select (addr); ds.write (0x44,1);  delay (1000);  ds.reset (); ds.select (addr); ds.write (0xbe);   (i = 0; <9; ++) { data [i] = ds.read (); }  serial.print ("crc =");  serial.print (onewire :: crc8 (data, 8), hex); serial.println (); float tc_100; tc_100 = (data [1] * 256. + data [0]) / 16 .;  serial.print (tc_100);   display.cleardisplay (); display.setcursor (5,5); display.settextsize (1); display.settextcolor (white); display.println ("temperature");  display.setcursor (65,5); display.settextsize (1); display.settextcolor (white); display.println ("motora");  display.setcursor (109,5); display.settextsize (1); display.settextcolor (white); display.println ("o");  display.setcursor (115,5); display.settextsize (1); display.settextcolor (white); display.println ("c");  display.setcursor (30,28); display.settextsize (4); display.settextcolor (white); display.print (tc_100, 1);  display.display (); delay(1000); } 

first, change:

data [i] = ds.read (); 

to

data[i] = ds.read(); 

and see kind of results get.

i'm not sure calculations after that. use following code convert 9 hex values temperature ds18b20:

  int highbyte, lowbyte, treading, signbit, tc_100, whole, fract;   lowbyte = data[0];   highbyte = data[1];   treading = (highbyte << 8) + lowbyte;   signbit = treading & 0x8000;  // test sig bit   if (signbit) { // negative     treading = (treading ^ 0xffff) + 1; // 2's comp   }   tc_100 = (6 * treading) + treading / 4;    // multiply (100 * 0.0625) or 6.25    whole = tc_100 / 100;  // separate off whole , fractional portions   fract = tc_100 % 100;     if (signbit) { // if negative      serial.print("-");   }   serial.print(whole);   serial.print(".");   if (fract < 10) {      serial.print("0");   }   serial.print(fract);    serial.print("\n"); 

see onewire temperature


Comments

Popular posts from this blog

Magento/PHP - Get phones on all members in a customer group -

php - Bypass Geo Redirect for specific directories -

php - .htaccess mod_rewrite for dynamic url which has domain names -