//coded by Ümit Kabuli
#include
#include
#include //url=https://github.com/adafruit/Adafruit-GFX-Library
#include //url=https://github.com/adafruit/Adafruit_SSD1306
// If using software SPI (the default case):
/*
#define OLED_MOSI 9
#define OLED_CLK 10
#define OLED_DC 11
#define OLED_CS 12
#define OLED_RESET 13
*/
#include "DHT.h"
#define DHTPIN 8 // what pin we're connected to
//#define DHT_VDD 0
// Uncomment whatever type you're using!
//#define DHTTYPE DHT11 // DHT 11
#define DHTTYPE DHT22 // DHT 22 (AM2302) url=http://akizukidenshi.com/download/ds/aosong/AM2302.pdf
//#define DHTTYPE DHT21 // DHT 21 (AM2301)
DHT dht(DHTPIN, DHTTYPE);
// screen url: http://www.aliexpress.com/item/Brand-New-High-Quality-0-96-IIC-I2C-Serial-128x64-OLED-LED-Display-White-Module-For/32325016860.html
#define OLED_MOSI 5 //D1 sağdan 4.sarı
#define OLED_CLK 6 //D0 sağdan 5. beyaz
#define OLED_DC 3 //DC sağdan 2. turuncu
#define OLED_CS 2 //CS en sağda mavi
#define OLED_RESET 4 //RES sağdan 3. yeşil
#define TEXT_SIZE 2
#define TEXT_TEMP_COLUMN 10
#define TEXT_TEMP_ROW 0
#define TEXT_TEMP "Sicaklik:"
#define VALUE_TEMP_COL 40
#define VALUE_TEMP_ROW 0
#define VALUE_TEMP_ROW TEXT_TEMP_ROW
#define VALUE_HUMIDITY_COL 20
#define VALUE_HUMIDITY_ROW 48
#define VALUE_HUMIDITY_LENGHT 60
#define READ_TIME 5000 //ms cinsinden
#define TEXT_SIZE2_HIGHT 14
#define DEGREE_SYMBOL 0xF8
#define TEMPERATURE_SYMBOL_COL 0
#define TEMPERATURE_SYMBOL_ROW 0
#define TEMPERATURE_SYMBOL_HIGHT 48
#define TEMPERATURE_SYMBOL_WIDTH 48
#define HUMIDITY_SYMBOL_COL 75
#define HUMIDITY_SYMBOL_ROW 20
#define HUMIDITY_SYMBOL_HIGHT 48
#define HUMIDITY_SYMBOL_WIDTH 48
#define COLOR_FOREGROUND WHITE
#define COLOR_BACKGROUND BLACK
#define DEBUG_ON true
#define DEBUG_OFF false
#define DEBUG_MODE DEBUG_ON
Adafruit_SSD1306 display(OLED_MOSI, OLED_CLK, OLED_DC, OLED_RESET, OLED_CS);
/* Uncomment this block to use hardware SPI
#define OLED_DC 6
#define OLED_CS 7
#define OLED_RESET 8
Adafruit_SSD1306 display(OLED_DC, OLED_RESET, OLED_CS);
*/
#if (SSD1306_LCDHEIGHT != 64)
#error("Height incorrect, please fix Adafruit_SSD1306.h!");
#endif
static const unsigned char PROGMEM temperature_symbol [] = {//derece sembolü
0x00, 0x00, 0x03, 0xC0, 0x00, 0x00, 0x00, 0x00, 0x07, 0xE0, 0x00, 0x00, 0x00, 0x00, 0x0C, 0x30,
0x00, 0x00, 0x00, 0x00, 0x0C, 0x18, 0x00, 0x00, 0x00, 0x00, 0x08, 0x18, 0x00, 0x00, 0x00, 0x00,
0x08, 0x18, 0x00, 0x00, 0x00, 0x00, 0x08, 0x18, 0x00, 0x00, 0x00, 0x00, 0x08, 0x18, 0x00, 0x00,
0x00, 0x00, 0x08, 0x18, 0x00, 0x00, 0x00, 0x00, 0x08, 0x18, 0x00, 0x00, 0x00, 0x00, 0x08, 0x18,
0x00, 0x00, 0x00, 0x00, 0x08, 0x18, 0x00, 0x00, 0x00, 0x00, 0x08, 0x18, 0x00, 0x00, 0x00, 0x00,
0x08, 0x1F, 0x80, 0x00, 0x00, 0x00, 0x08, 0x1F, 0x80, 0x00, 0x00, 0x00, 0x08, 0x18, 0x00, 0x00,
0x00, 0x00, 0x08, 0x18, 0x00, 0x00, 0x00, 0x00, 0x08, 0x18, 0x00, 0x00, 0x00, 0x00, 0x08, 0x1F,
0x80, 0x00, 0x00, 0x00, 0x08, 0x1F, 0x80, 0x00, 0x00, 0x00, 0x08, 0x18, 0x00, 0x00, 0x00, 0x00,
0x08, 0x18, 0x00, 0x00, 0x00, 0x00, 0x08, 0x18, 0x00, 0x00, 0x00, 0x00, 0x08, 0x18, 0x00, 0x00,
0x00, 0x00, 0x08, 0x1F, 0x80, 0x00, 0x00, 0x00, 0x08, 0x1F, 0x80, 0x00, 0x00, 0x00, 0x08, 0x18,
0x00, 0x00, 0x00, 0x00, 0x08, 0x18, 0x00, 0x00, 0x00, 0x00, 0x18, 0x18, 0x00, 0x00, 0x00, 0x00,
0x38, 0x1C, 0x00, 0x00, 0x00, 0x00, 0x60, 0x06, 0x00, 0x00, 0x00, 0x00, 0xC0, 0x03, 0x00, 0x00,
0x00, 0x01, 0x80, 0x01, 0x80, 0x00, 0x00, 0x01, 0x80, 0x00, 0x80, 0x00, 0x00, 0x01, 0x00, 0x00,
0xC0, 0x00, 0x00, 0x03, 0x00, 0x00, 0xC0, 0x00, 0x00, 0x03, 0x00, 0x00, 0x40, 0x00, 0x00, 0x03,
0x00, 0x00, 0x40, 0x00, 0x00, 0x03, 0x00, 0x00, 0x40, 0x00, 0x00, 0x03, 0x00, 0x00, 0xC0, 0x00,
0x00, 0x03, 0x00, 0x00, 0xC0, 0x00, 0x00, 0x01, 0x80, 0x00, 0x80, 0x00, 0x00, 0x01, 0x80, 0x01,
0x80, 0x00, 0x00, 0x00, 0xC0, 0x03, 0x00, 0x00, 0x00, 0x00, 0x60, 0x06, 0x00, 0x00, 0x00, 0x00,
0x38, 0x1C, 0x00, 0x00, 0x00, 0x00, 0x1F, 0xF8, 0x00, 0x00, 0x00, 0x00, 0x03, 0xC0, 0x00, 0x00
};
const unsigned char PROGMEM humidity_symbol [] = { //yüzdeli damla sembolü
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0xC0, 0x00, 0x00, 0x00, 0x00, 0x00, 0xC0, 0x00, 0x00, 0x00, 0x00, 0x01, 0xE0, 0x00, 0x00,
0x00, 0x00, 0x01, 0xF0, 0x00, 0x00, 0x00, 0x00, 0x03, 0xF0, 0x00, 0x00, 0x00, 0x00, 0x07, 0xF8,
0x00, 0x00, 0x00, 0x00, 0x07, 0xF8, 0x00, 0x00, 0x00, 0x00, 0x0F, 0xFC, 0x00, 0x00, 0x00, 0x00,
0x0F, 0xFC, 0x00, 0x00, 0x00, 0x00, 0x1F, 0xFE, 0x00, 0x00, 0x00, 0x00, 0x1F, 0xFF, 0x00, 0x00,
0x00, 0x00, 0x3F, 0xFF, 0x00, 0x00, 0x00, 0x00, 0x3F, 0xFF, 0x80, 0x00, 0x00, 0x00, 0x7F, 0xFF,
0x80, 0x00, 0x00, 0x00, 0x7F, 0xFF, 0xC0, 0x00, 0x00, 0x00, 0xFF, 0xFF, 0xC0, 0x00, 0x00, 0x00,
0xE0, 0xF3, 0xE0, 0x00, 0x00, 0x01, 0xE4, 0xE7, 0xE0, 0x00, 0x00, 0x01, 0xCC, 0x6F, 0xF0, 0x00,
0x00, 0x03, 0xCE, 0x4F, 0xF0, 0x00, 0x00, 0x03, 0xCE, 0x5F, 0xF0, 0x00, 0x00, 0x03, 0xC4, 0x90,
0xF8, 0x00, 0x00, 0x03, 0xE0, 0xA0, 0x78, 0x00, 0x00, 0x03, 0xF3, 0x26, 0x78, 0x00, 0x00, 0x03,
0xFE, 0x46, 0x78, 0x00, 0x00, 0x03, 0xFE, 0x46, 0x78, 0x00, 0x00, 0x03, 0xFC, 0xE6, 0x70, 0x00,
0x00, 0x03, 0xFD, 0xE0, 0xF0, 0x00, 0x00, 0x01, 0xF9, 0xF9, 0xE0, 0x00, 0x00, 0x01, 0xFF, 0xFF,
0xE0, 0x00, 0x00, 0x00, 0xFF, 0xFF, 0xC0, 0x00, 0x00, 0x00, 0x7F, 0xFF, 0x80, 0x00, 0x00, 0x00,
0x3F, 0xFF, 0x00, 0x00, 0x00, 0x00, 0x0F, 0xFE, 0x00, 0x00, 0x00, 0x00, 0x03, 0xF0, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
};
void setup() {
Serial.begin(9600);
// pinMode(DHT_VDD,OUTPUT);
//digitalWrite(DHT_VDD,HIGH);
// by default, we'll generate the high voltage from the 3.3v line internally! (neat!)
display.begin(SSD1306_SWITCHCAPVCC);
display.setTextSize(TEXT_SIZE);
display.setTextColor(COLOR_FOREGROUND);
// display.setCursor(TEXT_TEMP_COLUMN,TEXT_TEMP_ROW);
display.clearDisplay();
// display.print(TEXT_TEMP);
display.drawBitmap(TEMPERATURE_SYMBOL_COL, \
TEMPERATURE_SYMBOL_ROW, \
temperature_symbol, \
TEMPERATURE_SYMBOL_HIGHT, \
TEMPERATURE_SYMBOL_WIDTH, \
COLOR_FOREGROUND);
display.drawBitmap(HUMIDITY_SYMBOL_COL,\
HUMIDITY_SYMBOL_ROW, \
humidity_symbol, \
HUMIDITY_SYMBOL_HIGHT, \
HUMIDITY_SYMBOL_WIDTH, \
COLOR_FOREGROUND);
display.display();
}
void loop() {
// Reading temperature or humidity takes about 250 milliseconds!
// Sensor readings may also be up to 2 seconds 'old' (its a very slow sensor)
float humidity = dht.readHumidity();
// Read temperature as Celsius
float temp = dht.readTemperature();
// Read temperature as Fahrenheit
// float f = dht.readTemperature(true);
// Check if any reads failed and exit early (to try again).
if (isnan(temp) || isnan(humidity)) {
Serial.println("Failed to read from DHT sensor!");
return;
}
clearValues();
printTemperature(temp);
printHumidity(humidity);
if(DEBUG_MODE==DEBUG_ON) {
Serial.println(String(TEXT_TEMP)+String(temp));
Serial.println(String("Bagil Nem(%): ")+String(humidity));
}
delay(READ_TIME);
}
void clearValues()
{
display.fillRect(VALUE_TEMP_COL,\
VALUE_TEMP_ROW, \
display.height(), \
TEXT_SIZE2_HIGHT, \
COLOR_BACKGROUND);
display.fillRect(VALUE_HUMIDITY_COL, \
VALUE_HUMIDITY_ROW, \
VALUE_HUMIDITY_LENGHT, \
TEXT_SIZE2_HIGHT, \
COLOR_BACKGROUND);
display.display();
}
void printTemperature(float temp)
{
display.setCursor(VALUE_TEMP_COL,VALUE_TEMP_ROW);
display.print(temp,1);// Virgülden sonra 1 basamak
// display.print(" ");
display.print((char) DEGREE_SYMBOL);
display.print("C");
}
void printHumidity(float humidity)
{
display.setCursor(VALUE_HUMIDITY_COL,VALUE_HUMIDITY_ROW);
display.print(humidity,1);
display.print("%");
display.display();
}
Bitmap dizisi için “LCD Assistant” programını kullandım. Oryantasyon olarak horizontal’ı seçtim.
ssd1306 oled ekranların bazıları uno da çalışmıyor sadece duede çalışıyor. adafruit urununde seviye çeviriciler oldugunde uno dada çalışıyor ama diğer çinli uretıcılerde bu donusturuculer ve 3.3v regulator bord uzerınde olmadıgından çalıştırmada sorun yaşanabıliyor. ssd1306 diye satılan farklı bir kaç ürün var. bu ekranları kullanırlen dikkat edin. nighteagle bu ekranı kullanıp denediniz mi mumkunse arduinoturkiye.com yazdırılmış bir ekran görüntüsü paylaşırsan sevinirim…
Direkt 5 volt kullandım. Adafruit’in kartını taklit etmişler sanırım. Ama tam benzemiyor devre (https://learn.adafruit.com/monochrome-oled-breakouts/wiring-1-dot-3-128x64). 3.3v regülatör kartın üzerinde herhalde. Ama 3.3v’a takınca da çalıştı. Library örnekleri sorunsuz çalıştı. Benim kullandığım ekran linteki şirketten aldığım. Ayrıntılı devre fotosu var. Ama şema dosyası bulamadım. Ekran pin şeridinin üzerinde “JQ-12854A01” yazıyor. internette bu ifade akkında bir bilgi bulamadım. http://www.adafruit.com/datasheets/SSD1306.pdf Benim ekran modülü için 3v-5v diyor. (http://www.aliexpress.com/store/product/Brand-New-High-Quality-0-96-IIC-I2C-Serial-128x64-OLED-LED-Display-White-Module-For/1710316\_32325016860.html)