아두이노 oled 코드 - adu-ino oled kodeu

안녕하세요 이번에는 간단하게 OELD에 텍스트를 표시하는것과 기본적으로 제공하는 

GraphicsTest 예제를 사용하는 방법에 대해 작성해 보았습니다.

 

핵심부품

 

아두이노 oled 코드 - adu-ino oled kodeu
아두이노 OLED 정보

 

 

부품목록

아두이노 oled 코드 - adu-ino oled kodeu

 

 

브레드보드

아두이노 oled 코드 - adu-ino oled kodeu
OLED 제어 브레드보드

 

 

 

회로도

아두이노 oled 코드 - adu-ino oled kodeu
OLED 제어 회로도

 

 

 

예제사용


스케치 -> 라이브러리 포함하기 -> 라이브러리 관리에 들어갑니다.

아두이노 oled 코드 - adu-ino oled kodeu

자 다음으로 "U8glib"를 검색 합니다.

찾은 이후 설치를 해주세요.

아두이노 oled 코드 - adu-ino oled kodeu

자 그럼 우선 간단하게 제공하고 있는 예제를 불러와 업로드를 해보겠습니다.

라이브러리를 설치한 이후 파일 -> 예제 -> U8glib -> GraphicsTest를 클릭.

아두이노 oled 코드 - adu-ino oled kodeu

예제를 불러오셨다면 아래 주석을 찾아서 주석을 해제 해주세요

(해제하지 않으면 실행이 안될수도 있습니다.)


U8GLIB_SSD1306_128X64 u8g(U8G_I2C_OPT_NONE|U8G_I2C_OPT_DEV_0); // I2C / TWI

아래와 같이 "//" 를 지우시면 주석이 해제가 됩니다.



아두이노 oled 코드 - adu-ino oled kodeu

 

 

 

 

예제 영상

 

[아두이노] OLED 제어하기 -GraphicsTest 예제

 

 

소스코드

 


자 그러면 이제는 OLED에 원하는 text를 간단하게 표시해 보겠습니다.
소스코드는 아래와 같습니다.

#include "U8glib.h"

U8GLIB_SSD1306_128X64 u8g(U8G_I2C_OPT_NONE);

void setup() {

}
void loop() {
    u8g.firstPage();
    do{
        u8g.setFont(u8g_font_unifont);
        u8g.setPrintPos(0,10);     //초기 위치 설정
        u8g.print("Hello, World"); //초기 위치 설정에 따른 text 출력
        u8g.drawStr(0,30, "Hello, Arduino"); //x,y 좌표값을 이용한 text 출력
        u8g.drawStr(0,50, "Hello, NAVER");
    }while(u8g.nextPage());
}

 

 

구현 결과

아두이노 oled 코드 - adu-ino oled kodeu

이상입니다 감사합니다.

공유하기

게시글 관리

구독하기배씨의 프로그래밍

저작자표시

  • 카카오스토리
  • 트위터
  • 페이스북

'프로그래밍 > 아두이노[Arduino]&라즈베리파이[Raspberry Pi]' 카테고리의 다른 글

[아두이노] OLED[0.96인치(128*64)]에 원하는 그림 출력-NodeMCU포함  (0)2019.05.13[아두이노] 토양수분감지센서로 OLED에 표시[Soil Moisture Sensor]  (0)2019.05.03[아두이노] 조이스틱[joystick] 모듈을 사용하여 LED제어하기  (4)2019.04.29[아두이노] 전압센서 모듈을 이용하여 LCD에 센서값 표시하기  (0)2019.04.29[아두이노] 빗물감지센서 모듈을 사용하여 LCD에 센서값을 표시하기 + LED 제어  (0)2019.04.26

SSD1306 driver를 IC를 사용하고 128X64 OLED는 동일하지만 만드는 회사마다, Interface가 조금씩 다르기때문에 이부분을 잘 선택해 줍니다. 주석처리된 부분을 해제시켜 줍니다. 저같은 경우는 아래 녹색 글씨 부분입니다. 

 

#include <Arduino.h>

#include <U8x8lib.h>

#ifdef U8X8_HAVE_HW_SPI
#include <SPI.h>

#endif

 

U8X8_SSD1306_128X64_NONAME_SW_I2C u8x8(/* clock=*/ SCL, /* data=*/ SDA, /* reset=*/ U8X8_PIN_NONE);   // OLEDs without Reset of the Display

 

void setup(void)
{
  u8x8.begin();
  u8x8.setPowerSave(0);      
}

void loop(void)
{
  u8x8.setFont(u8x8_font_chroma48medium8_r);
  u8x8.drawString(0,0,"Helloo World!");
  delay(2000);
}

-. Adafruit SD1306이용하기 

파일>예제>adafruit SSD1306>ssd1306_128x64_i2c 

 

code가 길어서 적지 않았습니다 바로 실행해 보세요. 

화면이 아무것도 출력이 되지 않으면, 아래의 코드레서 Address를 check해주세요.

0x3D > 0x3C로 변경해보고 실행 

  if(!display.begin(SSD1306_SWITCHAPVCC,0x3D)) { // Address 0x3D for 128x64

 

0x3D, 0x3C로도 안되면 Address를 아래의 방법으로 찾아서 변경해 주시면 됩니다.

https://www.youtube.com/watch?v=dVqv3LvJAJY

https://garagegeekguy.blogspot.com/2018/10/how-to-find-out-address-of-your-i2c.html

 

간단히 설명하면 

아래의 code를 복사해 넣고 실행한후에 툴>시리얼모니터를 실행하면 I2C에 붙어있는 Device의 address를 알수 있습니다. 



#include <Wire.h>

 

void setup()

{

Wire.begin();

Serial.begin(9600);

while (!Serial);

Serial.println("\nI2C Scanner");

}

 

void loop()

{

   byte error, address;

   int nDevices;

   Serial.println("Scanning...");

 

nDevices = 0;

   for(address = 1; address < 127; address++ )

      {

   // The i2c_scanner uses the return value of

   // the Write.endTransmisstion to see if

   // a device did acknowledge to the address.

   Wire.beginTransmission(address);

   error = Wire.endTransmission();

 

   if (error == 0)

   {

      Serial.print("I2C device found at address 0x");

      if (address<16) Serial.print("0");

         Serial.print(address,HEX);

      Serial.println(" !");

      nDevices++;

   }

   else if (error==4)

   {

      Serial.print("Unknow error at address 0x");

      if (address<16)

         Serial.print("0");

      Serial.println(address,HEX);

   }

   if (nDevices == 0)

      Serial.println("No I2C devices found\n");

   else

      Serial.println("done\n");

   delay(5000); // wait 5 seconds for next scan

}


●결과물 

좌(u8g2 라이브러리 이용), 중,우(Adafruit SSD1306, Adafruit GFX 라이브러리 이용)

아두이노 oled 코드 - adu-ino oled kodeu
아두이노 oled 코드 - adu-ino oled kodeu
아두이노 oled 코드 - adu-ino oled kodeu

 

●마치며 

단순 text출력은 비교적 쉬운데, 그래픽 관련 API들을 사용하려면, 이제부터는 공부가 필요합니다. 

그리고 화면 구성을 어떻게 사용할지도 구상해야 합니다.

라이브러리마다 github에서 매뉴얼도 제공하기때문에, 참조하시어 본인의 제작물에 적용을 해보시면 되겠습니다. 

 

https://github.com/olikraus/u8g2/wiki

https://github.com/adafruit/Adafruit_SSD1306

https://github.com/adafruit/Adafruit-GFX-Library

 

 

나머지 참조할만한 내용들입니다. 

 

https://m.blog.naver.com/PostView.nhn?blogId=namgoocha&logNo=220670935526&proxyReferer=https%3A%2F%2Fwww.google.co.kr%2F