2015年5月19日 星期二

arduino-溫濕度感應器/圖案顯示器/顯示溫濕度

溫濕度感應器
硬體


  • arduino板
  • 麵包板
  • 溫濕度感應器DHT11
程式


  • http://ming-shian.blogspot.tw/2014/05/arduino19dht11.html
圖案顯示器
硬體
  • arduino板
  • 麵包板
  • nokia5110顯示器
  • 接腳按照程式接
程式
  • 下載https://github.com/adafruit/Adafruit-GFX-Library
  • 下載https://github.com/adafruit/Adafruit-PCD8544-Nokia-5110-LCD-library
  • 將上面兩個檔案解壓縮放進libraries
  • 從範例中開啟Adafruit-PCD8544-Nokia-5110-LCD-library的pcdtest
顯示溫濕度
硬體
  • arduino板
  • 麵包板
  • nokia5110顯示器
  • 溫濕度感應器DHT11
程式
  • 參考Adafruit-PCD8544-Nokia-5110-LCD-library的pcdtest中,Hello, world!那一段
  • // draw a single pixel以下全部刪除,只留Hello, world!那段
  • 將溫濕度感應.h檔導入,設好接腳define
  • 將print、println的值分別改成temperature =、DHT.temperature、C
  • 同樣方法改濕度
  • print跟println的差別在於有ln則換行
  • 改好後若發現temperature比humidity多一行是因為temperature = 這串超過螢幕範圍自動跳行,刪掉=後的空格就好
程式碼-此為將溫溼度合併在同個畫面,並不將數值反白


/*********************************************************************


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 <SPI.h>
#include <Adafruit_GFX.h>
#include <Adafruit_PCD8544.h>
#include <dht.h>   

// Software SPI (slower updates, more flexible pin options):
// 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)
Adafruit_PCD8544 display = Adafruit_PCD8544(7, 6, 5, 4, 3);

// Hardware SPI (faster, but must use certain hardware pins):
// SCK is LCD serial clock (SCLK) - this is pin 13 on Arduino Uno
// MOSI is LCD DIN - this is pin 11 on an Arduino Uno
// pin 5 - Data/Command select (D/C)
// pin 4 - LCD chip select (CS)
// pin 3 - LCD reset (RST)
// Adafruit_PCD8544 display = Adafruit_PCD8544(5, 4, 3);
// Note with hardware SPI MISO and SS pins aren't used but will still be read
// and written to during SPI transfer.  Be careful sharing these pins!

#define NUMFLAKES 10
#define XPOS 0
#define YPOS 1
#define DELTAY 2


#define LOGO16_GLCD_HEIGHT 16
#define LOGO16_GLCD_WIDTH  16

#define dht_dpin 2 //定義訊號要從Pin A0 進來  
  
dht DHT;   

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 };

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.clearDisplay();   // clears the screen and buffer
}
void loop(){
  //show H&T
  DHT.read11(dht_dpin);
  display.setTextSize(1);
  display.setTextColor(BLACK);
  display.setCursor(0,0);
  display.println("Humidity = ");
  display.setTextColor(BLACK); 
  display.print(DHT.humidity);
  display.setTextSize(1);
  display.setTextColor(BLACK);
  display.println("%"); 
  display.display();
  display.setTextSize(1);
  display.setTextColor(BLACK);
  display.println("temperature =");
  display.setTextColor(BLACK); 
  display.print(DHT.temperature);
  display.setTextSize(1);
  display.setTextColor(BLACK);
  display.print("C"); 
  display.display();
  delay(2000);
  display.clearDisplay();   // clears the screen and buffer
}

沒有留言:

張貼留言