When measuring negative temperatures does not show me the correct values on my led output. I see something like 4983. I need advice with my 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);
for (i = 0; i <9; i ++) {
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);
}