2016年1月6日 星期三

Arduino MLX90614 紅外線溫度感測器 + Nokia 5110 LCD display

Arduino  MLX90614  紅外線溫度感測器 + Nokia 5110 LCD display


  MLX90614 有分5V跟3.3V的要注意!!! 以下是共通規格
  • Factory calibrated
  • -40°C to +125°C for sensor temperature
  • -70°C to +380°C for object temperature
  • ±0.5°C accuracy around room temperatures
  • High accuracy of 0.5°C over wide temperature
  • 90° Field of view
  • I2C interface, 0x5A is the fixed 7-bit address
 開啟Arduino IDE 貼上這段程式碼


/*************************************************** 
  This is a library example for the MLX90614 Temp Sensor

  Designed specifically to work with the MLX90614 sensors in the
  adafruit shop
  ----> https://www.adafruit.com/products/1748
  ----> https://www.adafruit.com/products/1749

這是用 Adafruit LCD &  MLX90614   驅動程式都是在 Adafruit 下載

https://www.adafruit.com/products/1748
https://www.adafruit.com/products/1749
https://www.adafruit.com/products/338

雖然是 BSD License 還是呼籲多買 Adafruit 的產品
Adafruit 老闆是美女喔!!

MLX90614 sensors 腳位定義
Pin A4             I2C data  SDA
Pin A5             I2C clock   SCL

LCD 腳位定義
Pin 11 for contrast on the Nokia 5110
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)
*/

#include "Adafruit_GFX.h"                                           //LCM 定義程式!!這三個要擺一起!!!
#include "Adafruit_PCD8544.h"
Adafruit_PCD8544 display = Adafruit_PCD8544 (7, 6, 5, 4, 3);

// Pin 4 Pin 3 的腳位要注意,我的是反過來的!!


#include <Wire.h>                                                  //MLX90614 定義程式!!這三個要擺一起!!!
#include <Adafruit_MLX90614.h>
Adafruit_MLX90614 mlx = Adafruit_MLX90614();


void setup() {
  
  mlx.begin();                                       // 啟動 MLX90614
  
  display.begin();                 //這是 Adafruit_PCD8544  Library 定義的
  display.setContrast(60);   //LCD 對比
  delay(1000);
  display.clearDisplay();             // 清除LCD內容
  display.setTextSize(2);            // 設定自形大小
  display.setTextColor(BLACK);  //定義顏色顏色

}

void loop() { 

  display.clearDisplay();                                // 清除LCD內容
  display.print(mlx.readObjectTempC());      // 顯示測到的溫度 度C
  display.println("C");                                   // 顯示字串 "C" 然後換行
  display.print(mlx.readObjectTempF());       // 顯示測到的溫度 度F
  display.println("F");                                    // 顯示字串 "F" 然後換行
  display.display();

  delay(1000);                   // 等一秒

}


上傳 然後就OK了



腳位在說明都有定義,

Nokia 5110 LCD 接地就好不用接電源


要特別注意的是

#include "Adafruit_GFX.h"                                           //LCM 定義程式!!這三個要擺一起!!!
#include "Adafruit_PCD8544.h"
Adafruit_PCD8544 display = Adafruit_PCD8544 (7, 6, 5, 4, 3);

#include <Wire.h>                                                  //MLX90614 定義程式!!這三個要擺一起!!!
#include <Adafruit_MLX90614.h>
Adafruit_MLX90614 mlx = Adafruit_MLX90614();

這些不要為了整齊順序互相調換!!!

1 則留言: