温度库:http://milesburton.com/Dallas_Temperature_Control_Library
5110库:https://github.com/adafruit/Adafruit-PCD8544-Nokia-5110-LCD-library
资料上显示 DS18B20 可以使用 3-5v 电源供电,可以做到9-12位精度。不过12位精度比9位精度测温慢多了。而1820只能5V供电,9位精度。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 | /********************************************************************* This is an example sketch for our Monochrome Nokia 5110 LCD Displays Pick one up today in the adafruit shop! ------> http://www.adafruit.com/products/338 These displays use SPI to communicate, 4 or 5 pins are required to interface Adafruit invests time and resources providing this open source code, please support Adafruit and open-source hardware by purchasing products from Adafruit! Written by Limor Fried/Ladyada for Adafruit Industries. BSD license, check license.txt for more information All text above, and the splash screen must be included in any redistribution *********************************************************************/ #include <Adafruit_GFX.h> #include <Adafruit_PCD8544.h> #include "floatToString.h" #include <OneWire.h> #include <DallasTemperature.h> // pin 7 - Serial clock out (SCLK) // pin 6 - Serial data out (DIN) // pin 5 - Data/Command select (D/C) // pin 4 - LCD chip select (CS) // pin 3 - LCD reset (RST) // pin2 - DS18B20 需要4.7k欧上拉电阻 Adafruit_PCD8544 display = Adafruit_PCD8544(7, 6, 5, 4, 3); #define NUMFLAKES 10 #define XPOS 0 #define YPOS 1 #define DELTAY 2 #define LOGO16_GLCD_HEIGHT 16 #define LOGO16_GLCD_WIDTH 16 static 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 }; // Data wire is plugged into port 2 on the Arduino #define ONE_WIRE_BUS 2 #define TEMPERATURE_PRECISION 12 // Setup a oneWire instance to communicate with any OneWire devices (not just Maxim/Dallas temperature ICs) OneWire oneWire(ONE_WIRE_BUS); // Pass our oneWire reference to Dallas Temperature. DallasTemperature sensors(&oneWire); // arrays to hold device addresses DeviceAddress insideThermometer, outsideThermometer; void setup() { Serial.begin(9600); display.begin(); // init done // you can change the contrast around to adapt the display // for the best viewing! display.setContrast(50); display.display(); // show splashscreen // Start up the library sensors.begin(); // locate devices on the bus Serial.print("Locating devices..."); Serial.print("Found "); Serial.print(sensors.getDeviceCount(), DEC); Serial.println(" devices."); // set the resolution to 12 bit sensors.setResolution( TEMPERATURE_PRECISION); // draw a single pixel display.drawPixel(10, 10, BLACK); display.display(); delay(2000); } //char buffer[25];// floatToString //char s[25];// floatToString void loop() { Serial.print("Requesting temperatures..."); sensors.requestTemperatures(); Serial.println("DONE"); display.clearDisplay(); // clears the screen and buffer // float tempC = sensors.getTempCByIndex(0); // floatToString(buffer, tempC, 2); // Serial.println("Temp C: "); // Serial.print(tempC); //sprintf(s,"c:%s",buffer); // text display tests display.setTextSize(1); display.setTextColor(BLACK); display.setCursor(0,0); display.print("c0:"); display.println(sensors.getTempCByIndex(0)); display.print("c1:"); display.println(sensors.getTempCByIndex(1)); display.print("c2:"); display.println(sensors.getTempCByIndex(2)); display.display(); delay(2000); } |
注意,需要使用arduino-1.52以上版本,arduino-1.05的会出现以下错误:
\arduino-1.0.5-windows\arduino-1.0.5\libraries\Robot_Control\ArduinoRobot.cpp: In constructor 'RobotControl::RobotControl()':
\arduino-1.0.5-windows\arduino-1.0.5\libraries\Robot_Control\ArduinoRobot.cpp:8: error: 'LCD_CS' was not declared in this scope
\arduino-1.0.5-windows\arduino-1.0.5\libraries\Robot_Control\ArduinoRobot.cpp:8: error: 'DC_LCD' was not declared in this scope
\arduino-1.0.5-windows\arduino-1.0.5\libraries\Robot_Control\ArduinoRobot.cpp:8: error: 'RST_LCD' was not declared in this scope
\arduino-1.0.5-windows\arduino-1.0.5\libraries\Robot_Control\ArduinoRobot.cpp: In member function 'void RobotControl::begin()':
\arduino-1.0.5-windows\arduino-1.0.5\libraries\Robot_Control\ArduinoRobot.cpp:18: error: 'MUXA' was not declared in this scope
\arduino-1.0.5-windows\arduino-1.0.5\libraries\Robot_Control\ArduinoRobot.cpp:18: error: 'MUXB' was not declared in this scope
\arduino-1.0.5-windows\arduino-1.0.5\libraries\Robot_Control\ArduinoRobot.cpp:18: error: 'MUXC' was not declared in this scope
\arduino-1.0.5-windows\arduino-1.0.5\libraries\Robot_Control\ArduinoRobot.cpp:18: error: 'MUXD' was not declared in this scope
\arduino-1.0.5-windows\arduino-1.0.5\libraries\Robot_Control\ArduinoRobot.cpp:19: error: 'MUX_IN' was not declared in this scope
\arduino-1.0.5-windows\arduino-1.0.5\libraries\Robot_Control\ArduinoRobot.cpp:22: error: 'BUZZ' was not declared in this scope
\arduino-1.0.5-windows\arduino-1.0.5\libraries\Robot_Control\ArduinoRobot.cpp:25: error: 'Serial1' was not declared in this scope