0
當測量負溫度時,在我的LED輸出上沒有顯示正確的值。我看到類似4983的東西。我需要我的代碼的建議。Arduino溫度傳感器負溫度
我使用arduino uno。 類型senzor的:DS18B20
代碼:
#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);
}
歡迎堆棧溢出!您可能想查看[如何提出問題](http://stackoverflow.com/help/how-to-ask)。正確地格式化您的問題將有助於您找到所需的答案。 –