아하 로고
검색 이미지
생활꿀팁 이미지
생활꿀팁생활
생활꿀팁 이미지
생활꿀팁생활
은혜로운왈라비232
은혜로운왈라비23219.05.22
Arduino에서 SSD1306을 이용하여 문자 출력을 어떻게 해야 하나요?

안녕하세요.

Arduino Nano를 가지고 이번에 샘플로 들어온 SSD1306이라는 OLED display를 테스트 하고자 합니다.

SSD1306이 I2C통신을 하는데 혹시 기본적인 문자열 출력을 하는 방법을 알 수 있을까요?

답변 부탁 드립니다.

  • 안녕하세요~

    우선 SSD1306 사양서를 보시고 통신 방식을 확인하셔야 합니다.

    제가 얼마 전에 만든 code 올립니다.

    헤더는 SPI.h와 Wire.h를 기본으로 including 하셔야 합니다.

    font는 구글링하면 제가 사용한 헤더를 구하실 수 있을 것 같네요.

    감사합니다.

    #include <SPI.h> #include <Wire.h> #include <Adafruit_GFX.h> #include <Adafruit_SSD1306.h> #include "crafty_girls_font.h" #include "schoolbell_font.h" #define SCREEN_WIDTH 128 // OLED display width, in pixels #define SCREEN_HEIGHT 32 // OLED display height, in pixels // Declaration for an SSD1306 display connected to I2C (SDA, SCL pins) #define OLED_RESET 4 // Reset pin # (or -1 if sharing Arduino reset pin) Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, OLED_RESET); #define NUMFLAKES 10 // Number of snowflakes in the animation example #define LOGO_HEIGHT 25//32//16 #define LOGO_WIDTH 44//25//16 static const unsigned char PROGMEM logo_bmp[] = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xf8, 0x00, 0x00, 0x00, 0x00, 0x0f, 0xfe, 0x00, 0x00, 0x00, 0x00, 0x7f, 0xff, 0x00, 0x00, 0x00, 0x01, 0xff, 0xff, 0x00, 0x03, 0xf3, 0xff, 0xff, 0xff, 0x00, 0x02, 0x10, 0x1f, 0xf0, 0xfe, 0x00, 0x02, 0x10, 0x1f, 0xf0, 0xfe, 0x00, 0x02, 0x12, 0x1f, 0xf0, 0xfc, 0x00, 0x02, 0x1e, 0x1f, 0xf0, 0xfc, 0x00, 0x02, 0x00, 0x1e, 0x70, 0xf8, 0x00, 0x02, 0x00, 0x1c, 0x30, 0xf0, 0x00, 0x02, 0x00, 0x1c, 0x70, 0xe0, 0x00, 0x02, 0x1e, 0x1f, 0xf0, 0xc0, 0x00, 0x02, 0x1e, 0x1f, 0xf0, 0xfc, 0x00, 0x02, 0x1e, 0x1f, 0xf0, 0x02, 0x00, 0x02, 0x1e, 0x1f, 0xf0, 0x02, 0x00, 0x02, 0x1f, 0x3f, 0xf0, 0x06, 0x00, 0x03, 0xff, 0xff, 0xff, 0xfc, 0x00, 0x03, 0xff, 0xff, 0xc0, 0x00, 0x00, 0x03, 0xff, 0xff, 0x00, 0x00, 0x00, 0x03, 0xff, 0xf0, 0x00, 0x00, 0x00, 0x01, 0xff, 0xc0, 0x00, 0x00, 0x00, 0x00, 0x7c, 0x00, 0x00, 0x00, 0x00 }; void setup() { Serial.begin(9600); //Serial.begin(115200); // SSD1306_SWITCHCAPVCC = generate display voltage from 3.3V internally if(!display.begin(SSD1306_SWITCHCAPVCC, 0x3C)) { // Address 0x3C for 128x32 Serial.println(F("SSD1306 allocation failed")); for(;;); // Don't proceed, loop forever } // Show initial display buffer contents on the screen -- // the library initializes this with an Adafruit splash screen. display.clearDisplay(); // Clear the buffer //display.drawBitmap((display.width() - LOGO_WIDTH ) / 2, (display.height() - LOGO_HEIGHT) / 2, logo_bmp, LOGO_WIDTH, LOGO_HEIGHT, 1); display.drawBitmap(0, (display.height() - LOGO_HEIGHT) / 2, logo_bmp, LOGO_WIDTH, LOGO_HEIGHT, 1); display.setTextSize(2); // Set text size display.setTextColor(WHITE); // Set text color display.setCursor(50,10); // Set initial position display.print("TEST"); display.display(); delay(3000); display.startscrollleft(0x00, 0x0F); delay(8500); display.stopscroll(); // drawbitmap(); display.clearDisplay(); // Clear the buffer display.setTextSize(2); // Set text size display.setTextColor(WHITE); // Set text color display.setCursor(0,5); // Set initial position // display.setFont(&Crafty_Girls_Regular_16); // Set font // display.setFont(&Schoolbell_Regular_16); // Set font display.print("Welcome^^"); display.display(); // Update display delay(3000); display.clearDisplay(); display.setTextSize(1); // Set text size display.setCursor(0,10); // Set initial position display.print("HELLO"); display.setCursor(0,20); // Set initial position display.print("WORLD"); display.display(); // Update display delay(3000); display.clearDisplay(); drawbitmap(); display.display(); } void loop() { } void drawbitmap(void) { display.clearDisplay(); display.drawBitmap( 0, 0, logo_bmp, LOGO_WIDTH, LOGO_HEIGHT, 1); //(display.width() - LOGO_WIDTH ) / 2, //(display.height() - LOGO_HEIGHT) / 2, //logo_bmp, LOGO_WIDTH, LOGO_HEIGHT, 1); display.display(); delay(1000); }