今天發現一家新的電子材料行在市區開幕,就想說進去逛一下看看有沒有新的感測模組,剛好看到 Nokia 5510 LCD 這個模組,只覺得樹莓派有顯示畫面,如果是 Arduino 要如何將字元或圖像呈現在 LCD上。當下就花了 1百xx元買了一片,要來試看看 Arduino 如何將影像透過連接的 Pin 顯示到 LCD上。結果帶回去一試,螢幕中間那塊都變成深色,於是再拿回去店裡換一個新的。
有了顯示 LCD 後,我試著將 DS18B20這個測試溫度的IC 接上,將讀取的值顯示在 LCD上,請看以下實做的結果:
• Nokia 5510 x 1
• DS18B20 溫度控制 IC x 1
• 可變電阻 x 1
• 連接線 x n條
• Nokia 5110 LCD模組連接線路
*1 : 連接可變電阻(中),可變電阻另兩腳分別接 3.3V 和 GND
• DS18B20 連接線路:
左腳接地;右腳接 5V;中間腳接 Arduino Pin 10及6.8 K Ohm後接 3.3V電源
• One Wire Library
• PCD8544 library
• DallasTemperature Library
• randomnerdtutorials.com:Complete Guide for Nokia 5110 LCD with Arduino
• Danny van den Brande:Arduino - Nokia 5110 LCD temperature meter with the DS18B20
有了顯示 LCD 後,我試著將 DS18B20這個測試溫度的IC 接上,將讀取的值顯示在 LCD上,請看以下實做的結果:
[材料]
• Arduino Uno x 1• Nokia 5510 x 1
• DS18B20 溫度控制 IC x 1
• 可變電阻 x 1
• 連接線 x n條
[接線圖]
• Nokia 5110 LCD模組連接線路
| Arduino接腳 | Nokia 5510 LCD模組 |
|---|---|
| Pin 6 | RST (Reset) |
| Pin 7 | CE (Chip Enable) |
| Pin 5 | D/C (Data/Command Selection) |
| Pin 4 | DIN (Serial Input) |
| Pin 3 | CLK (Clock Input) |
| VCC | 3.3V (VCC) |
| *1 | 7- LIGHT (Backlight Control) |
| GND | GND (Ground) |
*1 : 連接可變電阻(中),可變電阻另兩腳分別接 3.3V 和 GND
• DS18B20 連接線路:
左腳接地;右腳接 5V;中間腳接 Arduino Pin 10及6.8 K Ohm後接 3.3V電源
[程式一]
程式內呼叫三個不同的函式庫,請到以下網址下載後,解壓縮放在執行 Arduino 資料夾內的 Libraries 目錄。• One Wire Library
• PCD8544 library
• DallasTemperature Library
#include <onewire.h>
#include <PCD8544.h>
#include <dallastemperature.h>
#define ONE_WIRE_BUS 10 // DB18B20 中間腳接的 Pin
// 設定 oneWire 與 DS18B20 通訊
OneWire oneWire(ONE_WIRE_BUS);
// 將 oneWire 參考值傳給 DB18B20
DallasTemperature sensors(&oneWire);
// 畫一個笑臉
static const byte glyph[] = { B00010000, B00110100, B00110000, B00110100, B00010000 };
static PCD8544 lcd;
void setup() {
// 與 PCD8544 相容的顯示器
lcd.begin(84, 48);
// 將笑臉圖案設定在位於 ASCII table 0 的位置.
lcd.createChar(0, glyph);
sensors.begin();
}
void loop() {
static int counter = 0;
// 寫入一段文字
lcd.setCursor(0, 0);
lcd.print("I'm Ceiling.");
// 讀取 DS18B20溫度
sensors.requestTemperatures();
// 在畫面顯示計數器
lcd.setCursor(0, 1);
lcd.print(counter, DEC);
lcd.write(' ');
lcd.write(0); // 畫一個笑臉
// 將游標設定在第 3 列
lcd.setCursor(1, 3);
lcd.print("Temp: ");
lcd.print(sensors.getTempCByIndex(0));
lcd.print("'C");
delay(200);
counter++;
}
[程式二]
以下程式是顯示溫度,我保留原作者的程式碼,僅修改連接 LCD的 Pin 號,作者使用 LCD5110_Graph這個函式庫,可以將字型放大、縮小,讓大家參考。/*
Author: Danny van den Brande, ArduinoSensors.nl. BlueCore Tech.
Hello world! this is a example project for the DS18b20 on a old Nokia 5110 LCD Display.
*/
#include <onewire.h>
#include <DallasTemperature.h>
#include <LCD5110_Graph.h>
#define ONE_WIRE_BUS 10
LCD5110 lcd(3,4,5,6,7);
extern unsigned char SmallFont[];
extern unsigned char BigNumbers[];
extern uint8_t borderRoundedIcon[];
char TempCelciusFahrenheit[6];
OneWire oneWire(ONE_WIRE_BUS);
DallasTemperature sensors(&oneWire);
float tempC = 0;
float tempF = 0;
void setup(void)
{
lcd.InitLCD();
sensors.begin();
}
void loop(void)
{
lcd.clrScr();
lcd.drawBitmap(0, 0, borderRoundedIcon, 84, 48);
sensors.requestTemperatures();
tempC = sensors.getTempCByIndex(0);
tempF = sensors.toFahrenheit(tempC);
// convertToString(tempF); //these are Fahrenheit, uncomment when using degrees.
convertToString(tempC); //These are degrees, comment when using Fahrenheit.
lcd.setFont(BigNumbers);
lcd.print(TempCelciusFahrenheit,22,14); // You can set position of the text here.
lcd.setFont(SmallFont);
lcd.print("Temp.Celc.",17,5); //Comment when using Fahrenheit
lcd.print("Temp.Fahr.",17,5); //Uncomment when using Celcius lcd.update();
delay(1000);
}
void convertToString(float number)
{
dtostrf(number, 3, 1, TempCelciusFahrenheit);
}
[執行結果]
[參考資料]
• Sparkfun:Graphic LCD Hookup Guide• randomnerdtutorials.com:Complete Guide for Nokia 5110 LCD with Arduino
• Danny van den Brande:Arduino - Nokia 5110 LCD temperature meter with the DS18B20

張貼留言