ESP-01 with OLED

IoT_ESP8266 2018. 12. 30. 18:11

ESP-01 모듈에

0.96인치 OLED 연결



OLED용 라이브러리는

u8g가 아닌 SSD1306 사용




사용한 라이브러리

https://randomnerdtutorials.com/esp8266-0-96-inch-oled-display-with-arduino-ide/


esp8266 oled ssd1306 라이브러리 설치 방법
다운 : Click here to download the esp8266 oled ssd1306 library.

다음 파일의 압축 푼다 : esp8266-oled-ssd1306-master folder
폴더 이름 변경 : esp8266-oled-ssd1306-master 에서 esp8266_oled_ssd1306 로
폴더를 본인의 ARDUINO IDE 설정폴더로 옮긴다
Arduino IDE를 닫고 다시 시작한다

참고 라이브러리

https://github.com/ThingPulse/esp8266-oled-ssd1306




// ============================================================================================
// ESP8266 보드 설치하기
// https://learn.sparkfun.com/tutorials/esp8266-thing-hookup-guide/installing-the-esp8266-arduino-addon
// To begin, we’ll need to update the board manager with a custom URL. Open up Arduino, 
// then go to the Preferences (File > Preferences). Then, towards the bottom of the window, 
// copy this URL into the “Additional Board Manager URLs” text box:
//
// Hit OK. Then navigate to the Board Manager by going to Tools > Boards > Boards Manager. 
// There should be a couple new entries in addition to the standard Arduino boards. 
// Look for esp8266. Click on that entry, then select Install.
// SSD1306 Lib for ESP8266
// https://randomnerdtutorials.com/esp8266-0-96-inch-oled-display-with-arduino-ide/
// https://github.com/squix78/esp8266-oled-ssd1306/archive/master.zip
// unzip to : C:\Users\turbocrazy\Documents\Arduino\libraries
// other lib not tested
// https://github.com/ThingPulse/esp8266-oled-ssd1306
// ============================================================================================
#include <ESP8266WiFi.h>
#include <Wire.h>
#include "SSD1306.h"              // alias for #include "SSD1306Wire.h"
SSD1306  display(0x3C, 0, 2);     // 0x3C OLED address(not=0x78/A), SDA=GPIO 0, SCL=GPIO 2
//boolean LEDON = false;
//int BuiltInLED = 1;               // built in BLUE = TxD --> GPIO 1, RxD = GPIO 3
long int count = 0;               // for LED to toggle

byte m = 0;    // contains the minutes, refreshed each loop
byte h = 0;    // contains the hours, refreshed each loop
byte s = 0;    // contains the seconds, refreshed each loop
byte sOld = 60;
// ============================================================================================
void setup() {
  //pinMode(LED_BUILTIN, OUTPUT);
  //digitalWrite(LED_BUILTIN, LOW);
  //Serial1.begin(115200);                // fot WiFi
  Serial.begin(115200);                 // Arduino monitor
  // OLED stuff - Initialise the display.
  display.init();
  display.flipScreenVertically();        // flipping 
  display.setFont(ArialMT_Plain_10);
  display.drawString(0, 10, "ESP Clock");
  display.drawString(0, 24, "Clock Init ...");  
  display.display();          // write the buffer to the display
}
// ============================================================================================
void loop() {
  if(s != sOld){
    String t = String(h) + ":" + String(m) + ":" + String(s);
    Serial.println(t);
    display.clear();
    display.drawString(0, 10, "ESP Clock");
    display.drawString(0, 24, t);
    display.display();          // write the buffer to the display
    sOld = s;
  }
  delay(1000);
  s++;
  if(s>=60) {s = 0; m++;}
  if(m>=60) {m = 0; h++;}
  if(h>=24) h = 0;
}
// ============================================================================================


블로그 이미지

DIYworld

,