I2C OLED Module En: 두 판 사이의 차이

아두위키 : Arduwiki
(새 문서: {{#seo:|title=아두위키 : 아두이노 I2C OLED 모듈 가이드|title_mode=append|keywords=아두이노, 정보과학, 메이커학습, 수행평가, I2C OLED 모듈, 아두이노 작품, 캡스톤작품, 아두이노 예제코드|description=아두이노로 I2C OLED 모듈을 제어하는 방법(기본정보, 회로, 예제 코드)을 소개합니다. 정보과학과 메이커수업에 활용가능합니다.}} 가운데|class=coders100 == '''개...)
 
잔글편집 요약 없음
 
1번째 줄: 1번째 줄:
{{#seo:|title=아두위키 : 아두이노 I2C OLED 모듈 가이드|title_mode=append|keywords=아두이노, 정보과학, 메이커학습, 수행평가, I2C OLED 모듈, 아두이노 작품, 캡스톤작품, 아두이노 예제코드|description=아두이노로 I2C OLED 모듈을 제어하는 방법(기본정보, 회로, 예제 코드)을 소개합니다. 정보과학과 메이커수업에 활용가능합니다.}}
{{#seo:|title=Arduwiki : Arduino I2C OLED Module Guide|title_mode=append|keywords=Arduino, Information Science, Maker Learning, Performance Assessment, I2C OLED Module, Arduino Project, Capstone Project, Arduino Example Code|description=This introduces how to control a I2C OLED Module with Arduino (basic information, circuit, example code). It can be used in Information Science and Maker classes.}}


[[파일:OLED 사진.jpg|가운데|class=coders100]]
[[파일:OLED 사진.jpg|가운데|class=coders100]]


== '''개요''' ==
== '''Overview''' ==
아두이노 OLED 모듈은 작은 크기와 높은 해상도를 가진 디스플레이 모듈로, 다양한 프로젝트에 활용될 수 있습니다. OLED(Organic Light Emitting Diode) 기술을 기반으로 하여, 뛰어난 색감과 명암비를 제공합니다.
The Arduino OLED module is a display module with a small size and high resolution, suitable for various projects. Based on OLED (Organic Light Emitting Diode) technology, it provides excellent color and contrast.




=== OLED 작동 원리 ===
=== OLED Operating Principle ===
 
* '''유기 물질''': OLED는 얇은 유기 물질 층을 포함하고 있으며, 이 층이 전류에 의해 빛을 발산합니다. 유기 화합물은 전기적 자극을 받을 때 발광하는 특성을 가지고 있습니다.
* '''전극''': OLED 패널은 일반적으로 두 개의 전극(양극과 음극)으로 구성되어 있으며, 전기가 흐르면 유기 물질이 전자를 방출하고, 이 전자와 정공이 결합하여 빛을 생성합니다.


'''Organic Material''': OLED contains a thin layer of organic materials that emit light when an electric current passes through. Organic compounds have the property of emitting light when stimulated electrically.
'''Electrodes''': The OLED panel typically consists of two electrodes (anode and cathode). When electricity flows, the organic material releases electrons, and these electrons combine with holes to generate light.




=== SSD1306 ===
=== SSD1306 ===
SSD1306은 OLED 디스플레이를 구동하기 위한 드라이버 IC(집적 회로)입니다.
The SSD1306 is a driver IC (integrated circuit) used to control OLED displays.


1KB의 그래픽 디스플레이 전용 RAM(GDDRAM)을 내장하고 있어 이를 통해 표시할 비트 패턴을 저장합니다.
It contains 1KB of dedicated RAM for graphic display (GDDRAM), which is used to store the bit patterns to be displayed.


[[파일:SSD1306 구조.jpg|가운데|class=coders100]]
[[파일:SSD1306 구조.jpg|가운데|class=coders100]]
{| class="wikitable"
{| class="wikitable"
!항목
!List
!설명
!Explanation
|-
|-
|'''메모리 용량'''
|'''Memory capacity'''
|1KB (8192비트)
|1KB (8192bit)
|-
|-
|'''페이지 수'''
|'''Number of Page'''
|8 페이지 (페이지 0-7)
|8 page (Page 0-7)
|-
|-
|'''세로 줄 수'''
|'''Number of lines arranged vertically'''
|128 세로 줄 (세로 줄 0-127)
|128 vertical lines (vertical line 0-127)
|-
|-
|'''비트 정보'''
|'''Bit Information'''
|각 세로 줄당 8 비트 (비트 0-7)
|8 bits per vertical line (bits 0-7)
|-
|-
|'''계산'''
|'''Calculation'''
|8 페이지 x 128 세로 줄 x 8 비트 = 8192 비트 = 1024 바이트(1KB)
|8 pages x 128 vertical lines x 8 bits = 8192 bits = 1024 bytes (1KB)
|}
|}




== '''사양''' ==
== '''Specification''' ==
{| class="wikitable"
{| class="wikitable"
!항목
!List
!설명
!Explanation
|-
|-
|'''화면 크기'''
|'''Display Size'''
|0.91인치, 0.96인치, 1.3인치, 2.42인치 등 다양한 크기
|Various sizes such as 0.91inch, 0.96inch, 1.3inch, 2.42inch
|-
|-
|'''해상도'''
|'''Resolution'''
|128x64 픽셀 또는 128x32픽셀
|128x64 pixels or 128x32 pixels
|-
|-
|'''디스플레이 타입'''
|'''Display Type'''
|OLED (Organic Light Emitting Diode)
|OLED (Organic Light Emitting Diode)
|-
|-
|'''색상'''
|'''Color'''
|흑백 (화이트 또는 블루)
|Black and White (White or Blue)
|-
|-
|'''인터페이스'''
|'''Interface'''
|I2C (2선)
|I2C (2 pins)
|-
|-
|'''전압'''
|'''Voltage'''
|3.3V ~ 5V
|3.3V ~ 5V
|-
|-
|'''전력 소모'''
|'''Power Consumption'''
|대기 전력: 0.1mA, 최대 전력: 20mA
|Standby Power: About 0.1mA, Maximum Power: About 20mA
|}
|}




== '''활용 예제''' ==
== '''Application Examples''' ==


=== 회로 구성 ===
=== Circuit Configuration ===
{| class="wikitable"
{| class="wikitable"
!OLED 모듈 핀
!OLED module pin
!아두이노 우노/나노
!Arduino Uno/Nano
!아두이노 메가
!Arduino Mega
|-
|-
|VCC
|VCC
|5V 또는 3.3V
|5V or 3.3V
|5V 또는 3.3V
|5V or 3.3V
|-
|-
|GND
|GND
95번째 줄: 94번째 줄:
[[파일:OLED회로.jpg|가운데|class=coders100]]
[[파일:OLED회로.jpg|가운데|class=coders100]]


=== 장치 주소 확인 ===
=== Device Address Verification ===
I2C 버스에 연결된 장치의 주소를 찾기 위해 사용되는 코드입니다.
 
This is the code used to find the address of devices connected to the I2C bus.


아래 소개될 예제들을 실행하기 이전에 I2C Scanner를 먼저 실행해 모듈의 주소를 확인해주세요.<syntaxhighlight lang="c++" line="1">
Before running the examples introduced below, please run the I2C Scanner first to check the address of the module.<syntaxhighlight lang="c++" line="1">
#include <Wire.h>
#include <Wire.h>


void setup() {
void setup() {
   Serial.begin(9600); // 시리얼 통신 시작
   Serial.begin(9600);
   Wire.begin();       // I2C 버스 시작
   Wire.begin();
   Serial.println("I2C Scanner 시작...");
   Serial.println("I2C Scanner Start...");
}
}


111번째 줄: 111번째 줄:
   int nDevices = 0;
   int nDevices = 0;


   Serial.println("I2C 장치 검색 중...");
   Serial.println("I2C Device Scanning...");


   for (address = 1; address < 127; address++) {
   for (address = 1; address < 127; address++) {
     // I2C 장치에 연결 시도
     // Attempting to connect to the I2C device
     Wire.beginTransmission(address);
     Wire.beginTransmission(address);
     error = Wire.endTransmission();
     error = Wire.endTransmission();


     if (error == 0) {
     if (error == 0) {
       Serial.print("장치 발견! 주소: 0x");
       Serial.print("Device found! Address: 0x");
       if (address < 16) {
       if (address < 16) {
         Serial.print("0");
         Serial.print("0");
127번째 줄: 127번째 줄:
       nDevices++;
       nDevices++;
     } else if (error == 4) {
     } else if (error == 4) {
       Serial.print("주소 0x");
       Serial.print("Address 0x");
       Serial.print(address, HEX);
       Serial.print(address, HEX);
       Serial.println("에 오류 발생!");
       Serial.println("error occurred!");
     }
     }
   }
   }


   if (nDevices == 0) {
   if (nDevices == 0) {
     Serial.println("I2C 장치가 발견되지 않았습니다.");
     Serial.println("No I2C device found.");
   } else {
   } else {
     Serial.println("장치 검색 완료.");
     Serial.println("Device scanning complete.");
   }
   }


   delay(5000); // 5초 대기 후 다시 스캔
   delay(5000); // Wait for 5 seconds before scanning again.
}
}
</syntaxhighlight>
</syntaxhighlight>
148번째 줄: 148번째 줄:




=== 라이브러리 ===
=== Library ===
Adafruit SSD1306 라이브러리를 사용합니다.
Please use the Adafruit SSD1306 library.


SSD1306 설치시 추가로 요구하는 Adafruit BusIO, Adafruit GFX Library도 INSTALL ALL을 눌러 함께 설치해주세요.
When installing SSD1306, please also click INSTALL ALL to install the required Adafruit BusIO and Adafruit GFX Library together.


[[파일:OLED라이브러리설치.jpg|가운데|class=coders100]]
[[파일:OLED라이브러리설치.jpg|가운데|class=coders100]]




=== 1. 라이브러리 기본 제공 예제 ===
=== 1. Library Default Examples ===
File - Examples - Adafruit SSD1306 - ssd1306_128x64 i2c 를 클릭하여 예제를 열어주세요.
 
Click on File - Examples - Adafruit SSD1306 - ssd1306_128x64 i2c to open the example.


[[파일:OLED라이브러리기본제공예제.png|class=coders50]]
[[파일:OLED라이브러리기본제공예제.png|class=coders50]]
163번째 줄: 164번째 줄:




예제 코드 속 Address 부분을 이전에 I2C Scanner로 확인한 장치 주소로 변경해주세요.
Please change the Address part in the example code to the device address confirmed earlier with the I2C Scanner.


[[파일:OLED장치주소수정.jpg|가운데|class=coders100]]
[[파일:OLED장치주소수정.jpg|가운데|class=coders100]]
169번째 줄: 170번째 줄:




==== 실행 결과 ====
==== Execution Result ====
<div class="coders70">
<div class="coders70">
<youtube> LFLyyKAffCI </youtube>
<youtube> LFLyyKAffCI </youtube>
175번째 줄: 176번째 줄:




=== 2. 텍스트 출력 ===
=== 2. Text Output ===
간단한 텍스트를 출력하는 예제입니다.


0.91인치 OLED를 사용했으며 이 모듈의 경우 128 x 32픽셀이기 때문에 6번째 줄 SCREEN_HEIGHT를 64에서 32로 변경했습니다.<syntaxhighlight lang="c++" line="1">
This is an example of printing simple text.
 
I used a 0.91-inch OLED, and since this module has a resolution of 128 x 32 pixels, I changed the 6th line SCREEN_HEIGHT from 64 to 32.
<syntaxhighlight lang="c++" line="1">
#include <Wire.h>
#include <Wire.h>
#include <Adafruit_GFX.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>
#include <Adafruit_SSD1306.h>


#define SCREEN_WIDTH 128  // OLED 화면의 너비
#define SCREEN_WIDTH 128  // OLED width
#define SCREEN_HEIGHT 32  // OLED 화면의 높이
#define SCREEN_HEIGHT 32  // OLED height


// OLED 모듈의 I2C 주소 (일반적으로 0x3D 또는 0x3C)
// I2C address of the OLED module (typically 0x3D or 0x3C)
#define OLED_ADDR 0x3C  
#define OLED_ADDR 0x3C  


// Adafruit_SSD1306 객체 생성
// Create Adafruit_SSD1306 object
Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, -1);
Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, -1);


void setup() {
void setup() {
   // OLED 초기화
   // OLED Initialization
   display.begin(SSD1306_SWITCHCAPVCC, OLED_ADDR);
   display.begin(SSD1306_SWITCHCAPVCC, OLED_ADDR);
   display.clearDisplay(); // 화면 지우기
   display.clearDisplay(); // Clear the screen
   display.setTextSize(1); // 텍스트 크기 설정
   display.setTextSize(1); // Set text size
   display.setTextColor(SSD1306_WHITE); // 텍스트 색상 설정
   display.setTextColor(SSD1306_WHITE); // Set text color
   display.setCursor(0, 0); // 커서 위치 설정
   display.setCursor(0, 0); // Set cursor position
   display.println("GONGZIPSA"); // 텍스트 출력
   display.println("GONGZIPSA"); // Print text
   display.setCursor(0, 10); // 커서 위치 설정
   display.setCursor(0, 10); // Set cursor position
   display.println("ArduWiki"); // 텍스트 출력
   display.println("ArduWiki"); // Print text
   display.display(); // 화면에 출력
   display.display(); // Display on the screen
}
}


void loop() {
void loop() {
  // 루프에서는 아무 작업도 하지 않음
}
}
</syntaxhighlight>
</syntaxhighlight>
212번째 줄: 214번째 줄:




사용된 함수들의 역할은 다음과 같습니다.
The roles of the used functions are as follows.
{| class="wikitable"
{| class="wikitable"
!함수 이름
!Functions
!설명
!Explanation
|-
|-
|<code>begin()</code>
|<code>begin()</code>
|OLED 디스플레이를 초기화합니다. I2C 주소와 해상도를 설정합니다.
|Initializes the OLED display. Sets the I2C address and resolution.
|-
|-
|<code>clearDisplay()</code>
|<code>clearDisplay()</code>
|현재 디스플레이의 내용을 지웁니다. 화면을 초기화합니다.
|Clears the current content of the display. Initializes the screen.
|-
|-
|<code>setTextSize(size)</code>
|<code>setTextSize(size)</code>
|출력할 텍스트의 크기를 설정합니다. <code>size</code>는 배율을 나타냅니다. (예: 1, 2 )
|Sets the size of the text to be displayed. The <code>size</code> indicates the scale. (e.g., 1, 2, etc.)
|-
|-
|<code>setTextColor(color)</code>
|<code>setTextColor(color)</code>
|텍스트의 색상을 설정합니다. 일반적으로 <code>SSD1306_WHITE</code>, <code>SSD1306_BLACK</code>를 사용합니다.
|Sets the color of the text. Typically, <code>SSD1306_WHITE</code> and <code>SSD1306_BLACK</code> are used.
|-
|-
|<code>setCursor(x, y)</code>
|<code>setCursor(x, y)</code>
|텍스트를 출력할 위치를 설정합니다. <code>x</code>는 가로 위치, <code>y</code>는 세로 위치입니다.
|Sets the position where the text will be displayed. <code>x</code> is the horizontal position, and <code>y</code> is the vertical position.
(0, 0)이 왼쪽 상단이며 <code>x</code>가 커지면 오른쪽, y가 커지면 아래로 이동합니다.
 
(0, 0) is the top-left corner, and as <code>x</code> increases, it moves to the right, while increasing <code>y</code> moves it downward.
|-
|-
|println("출력 내용")
|println("Contents")
|출력할 내용을 설정합니다.
|Sets the content to be displayed.
|-
|-
|<code>display()</code>
|<code>display()</code>
|버퍼에 저장된 내용을 OLED 디스플레이에 출력합니다.
|Outputs the content stored in the buffer to the OLED display.
|}
|}




==== 실행 결과 ====
==== Execution Result ====
[[파일:OLED예제2실행결과.jpg|가운데|class=coders100]]
[[파일:OLED예제2실행결과.jpg|가운데|class=coders100]]




=== 3. 간단한 도형 출력 ===
=== 3. Simple Shape Output ===
사각형, 삼각형, 원 등 간단한 도형들을 출력하는 예제입니다.<syntaxhighlight lang="c++" line="1">
 
This is an example of outputting simple shapes such as rectangles, triangles, and circles.<syntaxhighlight lang="c++" line="1">
#include <Wire.h>
#include <Wire.h>
#include <Adafruit_GFX.h>
#include <Adafruit_GFX.h>
259번째 줄: 263번째 줄:
void setup() {
void setup() {
   display.begin(SSD1306_SWITCHCAPVCC, OLED_ADDR);
   display.begin(SSD1306_SWITCHCAPVCC, OLED_ADDR);
   display.clearDisplay(); // 화면 초기화
   display.clearDisplay(); // Clear the screen
   display.drawTriangle(10, 10, 40, 30, 10, 30, WHITE); // 작은 삼각형
   display.drawTriangle(10, 10, 40, 30, 10, 30, WHITE); // Draw a small triangle
   display.drawRect(50, 10, 30, 20, WHITE); // 사각형
   display.drawRect(50, 10, 30, 20, WHITE); // Draw a rectangle
   display.fillRect(90, 10, 30, 20, WHITE); // 채워진사각형
   display.fillRect(90, 10, 30, 20, WHITE); // Draw a filled rectangle
   display.drawCircle(25, 50, 13, WHITE); //
   display.drawCircle(25, 50, 13, WHITE); // Draw a circle
   display.drawRoundRect(50, 40, 30, 20, 7, WHITE); // 모서리가 둥근 사각형
   display.drawRoundRect(50, 40, 30, 20, 7, WHITE); // Draw a rounded rectangle
   display.fillRoundRect(90, 40, 30, 20, 7, WHITE); // 모서리가 둥근 채워진 사각형
   display.fillRoundRect(90, 40, 30, 20, 7, WHITE); // Draw a filled rounded rectangle
   display.display();
   display.display(); // Display the shapes
}
}


275번째 줄: 279번째 줄:




 
The functions related to shapes are as follows:
도형과 관련된 함수들은 다음과 같습니다.
{| class="wikitable"
{| class="wikitable"
!함수 이름
!Functions
!설명
!Explanation
|-
|-
|<code>drawLine(x1, y1, x2, y2, color)</code>
|<code>drawLine(x1, y1, x2, y2, color)</code>
|두 점을 연결하는 선을 그립니다.
|Draws a line connecting two points.
|-
|-
|<code>drawRect(x, y, width, height, color)</code>
|<code>drawRect(x, y, width, height, color)</code>
|빈 사각형을 그립니다.
|Draws an empty rectangle.
|-
|-
|<code>fillRect(x, y, width, height, color)</code>
|<code>fillRect(x, y, width, height, color)</code>
|채워진 사각형을 그립니다.
|Draws a filled rectangle.
|-
|-
|<code>drawCircle(x, y, radius, color)</code>
|<code>drawCircle(x, y, radius, color)</code>
|빈 원을 그립니다.
|Draws an empty circle.
|-
|-
|<code>fillCircle(x, y, radius, color)</code>
|<code>fillCircle(x, y, radius, color)</code>
|채워진 원을 그립니다.
|Draws a filled circle.
|-
|-
|<code>drawTriangle(x1, y1, x2, y2, x3, y3, color)</code>
|<code>drawTriangle(x1, y1, x2, y2, x3, y3, color)</code>
|삼각형을 그립니다.
|Draws a triangle
|-
|-
|<code>drawRoundRect(x, y, width, height, radius, color)</code>
|<code>drawRoundRect(x, y, width, height, radius, color)</code>
|둥근 모서리가 있는 사각형을 그립니다.
|Draws an empty rectangle with rounded corners.
|-
|-
|<code>fillRoundRect(x, y, width, height, radius, color)</code>
|<code>fillRoundRect(x, y, width, height, radius, color)</code>
|채워진 둥근 모서리 사각형을 그립니다.
|Draws a filled rectangle with rounded corners.
|}
|}




==== 실행결과 ====
==== Execution Result ====
[[파일:OLED예제3실행결과.jpg|가운데|class=coders100]]
[[파일:OLED예제3실행결과.jpg|가운데|class=coders100]]




=== 4. 아스키 코드 출력 ===
=== 4. ASCII Code Output ===
아스키 코드 표에 대응하는 1~8번 문자를 출력하는 예제입니다.
 
This is an example of outputting characters corresponding to ASCII codes 1 to 8.


더 많은 문자를 출력하시려면 아스키 코드 표를 참고하세요.<syntaxhighlight lang="c++" line="1">
For more characters, please refer to the ASCII code table.<syntaxhighlight lang="c++" line="1">
#include <Wire.h>
#include <Wire.h>
#include <Adafruit_GFX.h>
#include <Adafruit_GFX.h>
327번째 줄: 331번째 줄:
void setup() {
void setup() {
   display.begin(SSD1306_SWITCHCAPVCC, OLED_ADDR);
   display.begin(SSD1306_SWITCHCAPVCC, OLED_ADDR);
   display.clearDisplay(); // 화면 초기화
   display.clearDisplay(); // Clear the screen


   // 텍스트 출력 설정
   // Text output settings
   display.setTextSize(1);      // 텍스트 크기 설정
   display.setTextSize(1);      // Set text size
   display.setTextColor(WHITE);  // 텍스트 색상 설정
   display.setTextColor(WHITE);  // Set text color
   display.setCursor(0, 0);      // 커서 위치 설정
   display.setCursor(0, 0);      // Set cursor position


   // 아스키 코드 문자 출력
   // Print ASCII code characters
   display.println("ASCII Code Print");
   display.println("ASCII Code Print");


   // 아스키 코드 문자 출력
   // Print ASCII code characters
   for (char c = 1; c < 9; c++) { // 아스키 코드 1부터 8까지
   for (char c = 1; c < 9; c++) { // From ASCII code 1 to 8
    display.print(c);                // 각 문자 출력
      display.print(c);                // Print each character
    display.print(" ");              // 공백 추가
      display.print(" ");              // Add space
   }
   }


   display.display(); // 버퍼 내용을 화면에 출력
   display.display(); // Display the buffer content on the screen
}
}


void loop() {
void loop() {
  // 반복할 작업이 없으므로 빈 상태
}
}
</syntaxhighlight>
</syntaxhighlight>




==== 실행 결과 ====
==== Execution Result ====
[[파일:OLED예제4아스키코드출력.jpg|가운데|class=coders100]]
[[파일:OLED예제4아스키코드출력.jpg|가운데|class=coders100]]




=== 5. 비트맵 이미지 출력 ===
=== 5. Bitmap Image Output ===
이미지를 바이트 배열로 변환하여 OLED에서 출력하는 예제입니다.


This is an example of outputting an image on the OLED by converting it into a byte array.


==== 이미지를 바이트 배열로 변환하는 방법 ====
1. [https://javl.github.io/image2cpp/ image2cpp (javl.github.io)] 로 접속합니다.


'''2. 이미지 업로드'''
==== How to Convert an Image to a Byte Array ====
1. Go to [https://javl.github.io/image2cpp/ image2cpp (javl.github.io)].


좌측 Select image에서 파일을 선택하여 업로드합니다.
2. '''Upload Image'''
 
Select a file to upload from the left-side Select image.


[[파일:Img2cpp이미지업로드.png|가운데|class=coders100]]
[[파일:Img2cpp이미지업로드.png|가운데|class=coders100]]


'''3. 이미지 세팅'''
3. '''Image Settings'''


Canvas size에 이미지 사이즈를 입력하신 후, Preview를 확인합니다. 이미지가 너무 큰데 Canvas 이미지를 작게 만드는 등 사이즈 조절이 잘 못 된다면 Preview에 정상적으로 이미지가 출력되지 않습니다.
Enter the image size in the Canvas size field and check the Preview. If the image is too large and the Canvas size is not properly adjusted, the image may not display correctly in the Preview.


[[파일:Img2cpp이미지세팅.png|가운데|class=coders100]]
[[파일:Img2cpp이미지세팅.png|가운데|class=coders100]]
377번째 줄: 381번째 줄:




'''4. 출력'''
'''4. Output'''


Code output format을 Arduino Code로 설정하신 후 Generate code를 누르면 아래에 배열이 출력됩니다.
Set the Code output format to Arduino Code and click Generate code. The array will be displayed below.


출력된 배열을 복사하여 예제 코드에서 활용하세요.
Copy the output array and use it in the example code.


[[파일:Img2cpp출력.png|가운데|class=coders100]]
[[파일:Img2cpp출력.png|가운데|class=coders100]]




==== 예제 코드 ====
==== Code ====
<code>drawBitmap(x, y, bitmap, width, height, color)</code> 함수를 사용하여 지정된 위치에 비트맵 이미지를 그립니다.
You can use the <code>drawBitmap(x, y, bitmap, width, height, color)</code> function to draw a bitmap image at a specified position.


<code>color</code>는 흰색으로 설정되어 있어 이미지를 흰색으로 표시합니다.
The <code>color</code> is set to white, so the image will be displayed in white.




12번째 줄 const unsigned char ~ 부분을 위에서 만든 바이트 배열로 변경하여 활용하세요.
Change the const unsigned char ~ part on line 12 to the byte array you created above.


예제 이미지(64 x 64 사이즈)와 사이즈가 다르다면 56번째 줄 drawBitmap 함수의 x, y 커서 위치, width, height 사진 크기를 변경해주셔야 합니다.<syntaxhighlight lang="c++" line="1">
If the example image (64 x 64 size) is different in size, you will need to adjust the x and y cursor positions, as well as the width and height values in the drawBitmap function on line 56 to match the image size.
<syntaxhighlight lang="c++" line="1">
#include <Wire.h>
#include <Wire.h>
#include <Adafruit_GFX.h>
#include <Adafruit_GFX.h>
443번째 줄: 448번째 줄:
void setup() {
void setup() {
   display.begin(SSD1306_SWITCHCAPVCC, OLED_ADDR);
   display.begin(SSD1306_SWITCHCAPVCC, OLED_ADDR);
   display.clearDisplay(); // 화면 초기화
   display.clearDisplay(); // Screen initialization
}
}


void loop() {
void loop() {
   display.clearDisplay(); // 화면 지우기
   display.clearDisplay(); // Clear the screen


   // 64x64 비트맵 이미지 그리기
   // Drawing a 64x64 bitmap image
   display.drawBitmap(32, 0, GONGZIPSA, 64, 64, WHITE); // (x, y, bitmap, width, height, color)
   display.drawBitmap(32, 0, GONGZIPSA, 64, 64, WHITE); // (x, y, bitmap, width, height, color)


   display.display(); // 버퍼 내용을 화면에 출력
   display.display(); // Output the buffer contents to the screen
}
}
</syntaxhighlight>
</syntaxhighlight>


==== 실행 결과 ====
==== Execution Result ====
플리커링 현상 때문에 모습 촬영 시에 잘려서 보이지만 실제로는 동그란 로고가 깔끔하게 출력되었습니다.
Due to flickering, the image appears cut off when captured, but in reality, the round logo is displayed clearly.


[[파일:OLED예제5비트맵이미지출력.jpg|가운데|class=coders100]]
[[파일:OLED예제5비트맵이미지출력.jpg|가운데|class=coders100]]




== '''구매 링크''' ==
== '''Purchase Link''' ==
[https://gongzipsa.com/shop/search.php?q=oled 공집사몰]
[https://gongzipsa.com/shop/search.php?q=oled GONGZIPSA]

2024년 8월 9일 (금) 16:34 기준 최신판


Overview

The Arduino OLED module is a display module with a small size and high resolution, suitable for various projects. Based on OLED (Organic Light Emitting Diode) technology, it provides excellent color and contrast.


OLED Operating Principle

Organic Material: OLED contains a thin layer of organic materials that emit light when an electric current passes through. Organic compounds have the property of emitting light when stimulated electrically. Electrodes: The OLED panel typically consists of two electrodes (anode and cathode). When electricity flows, the organic material releases electrons, and these electrons combine with holes to generate light.


SSD1306

The SSD1306 is a driver IC (integrated circuit) used to control OLED displays.

It contains 1KB of dedicated RAM for graphic display (GDDRAM), which is used to store the bit patterns to be displayed.

List Explanation
Memory capacity 1KB (8192bit)
Number of Page 8 page (Page 0-7)
Number of lines arranged vertically 128 vertical lines (vertical line 0-127)
Bit Information 8 bits per vertical line (bits 0-7)
Calculation 8 pages x 128 vertical lines x 8 bits = 8192 bits = 1024 bytes (1KB)


Specification

List Explanation
Display Size Various sizes such as 0.91inch, 0.96inch, 1.3inch, 2.42inch
Resolution 128x64 pixels or 128x32 pixels
Display Type OLED (Organic Light Emitting Diode)
Color Black and White (White or Blue)
Interface I2C (2 pins)
Voltage 3.3V ~ 5V
Power Consumption Standby Power: About 0.1mA, Maximum Power: About 20mA


Application Examples

Circuit Configuration

OLED module pin Arduino Uno/Nano Arduino Mega
VCC 5V or 3.3V 5V or 3.3V
GND GND GND
SCL A5 21
SDA A4 22

Device Address Verification

This is the code used to find the address of devices connected to the I2C bus.

Before running the examples introduced below, please run the I2C Scanner first to check the address of the module.

#include <Wire.h>

void setup() {
  Serial.begin(9600);
  Wire.begin();
  Serial.println("I2C Scanner Start...");
}

void loop() {
  byte error, address;
  int nDevices = 0;

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

  for (address = 1; address < 127; address++) {
    // Attempting to connect to the I2C device
    Wire.beginTransmission(address);
    error = Wire.endTransmission();

    if (error == 0) {
      Serial.print("Device found! Address: 0x");
      if (address < 16) {
        Serial.print("0");
      }
      Serial.print(address, HEX);
      Serial.println();
      nDevices++;
    } else if (error == 4) {
      Serial.print("Address 0x");
      Serial.print(address, HEX);
      Serial.println("error occurred!");
    }
  }

  if (nDevices == 0) {
    Serial.println("No I2C device found.");
  } else {
    Serial.println("Device scanning complete.");
  }

  delay(5000); // Wait for 5 seconds before scanning again.
}


실행 결과


Library

Please use the Adafruit SSD1306 library.

When installing SSD1306, please also click INSTALL ALL to install the required Adafruit BusIO and Adafruit GFX Library together.


1. Library Default Examples

Click on File - Examples - Adafruit SSD1306 - ssd1306_128x64 i2c to open the example.


Please change the Address part in the example code to the device address confirmed earlier with the I2C Scanner.


Execution Result


2. Text Output

This is an example of printing simple text.

I used a 0.91-inch OLED, and since this module has a resolution of 128 x 32 pixels, I changed the 6th line SCREEN_HEIGHT from 64 to 32.

#include <Wire.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>

#define SCREEN_WIDTH 128  // OLED width
#define SCREEN_HEIGHT 32   // OLED height

// I2C address of the OLED module (typically 0x3D or 0x3C)
#define OLED_ADDR 0x3C 

// Create Adafruit_SSD1306 object
Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, -1);

void setup() {
  // OLED Initialization
  display.begin(SSD1306_SWITCHCAPVCC, OLED_ADDR);
  display.clearDisplay(); // Clear the screen
  display.setTextSize(1); // Set text size
  display.setTextColor(SSD1306_WHITE); // Set text color
  display.setCursor(0, 0); // Set cursor position
  display.println("GONGZIPSA"); // Print text
  display.setCursor(0, 10); // Set cursor position
  display.println("ArduWiki"); // Print text
  display.display(); // Display on the screen
}

void loop() {
}


The roles of the used functions are as follows.

Functions Explanation
begin() Initializes the OLED display. Sets the I2C address and resolution.
clearDisplay() Clears the current content of the display. Initializes the screen.
setTextSize(size) Sets the size of the text to be displayed. The size indicates the scale. (e.g., 1, 2, etc.)
setTextColor(color) Sets the color of the text. Typically, SSD1306_WHITE and SSD1306_BLACK are used.
setCursor(x, y) Sets the position where the text will be displayed. x is the horizontal position, and y is the vertical position.

(0, 0) is the top-left corner, and as x increases, it moves to the right, while increasing y moves it downward.

println("Contents") Sets the content to be displayed.
display() Outputs the content stored in the buffer to the OLED display.


Execution Result


3. Simple Shape Output

This is an example of outputting simple shapes such as rectangles, triangles, and circles.

#include <Wire.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>

#define SCREEN_WIDTH 128
#define SCREEN_HEIGHT 64
#define OLED_ADDR 0x3C 

Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, -1);

void setup() {
  display.begin(SSD1306_SWITCHCAPVCC, OLED_ADDR);
  display.clearDisplay(); // Clear the screen
  display.drawTriangle(10, 10, 40, 30, 10, 30, WHITE); // Draw a small triangle
  display.drawRect(50, 10, 30, 20, WHITE); // Draw a rectangle
  display.fillRect(90, 10, 30, 20, WHITE); // Draw a filled rectangle
  display.drawCircle(25, 50, 13, WHITE); // Draw a circle
  display.drawRoundRect(50, 40, 30, 20, 7, WHITE); // Draw a rounded rectangle
  display.fillRoundRect(90, 40, 30, 20, 7, WHITE); // Draw a filled rounded rectangle
  display.display(); // Display the shapes
}

void loop() {
  
}


The functions related to shapes are as follows:

Functions Explanation
drawLine(x1, y1, x2, y2, color) Draws a line connecting two points.
drawRect(x, y, width, height, color) Draws an empty rectangle.
fillRect(x, y, width, height, color) Draws a filled rectangle.
drawCircle(x, y, radius, color) Draws an empty circle.
fillCircle(x, y, radius, color) Draws a filled circle.
drawTriangle(x1, y1, x2, y2, x3, y3, color) Draws a triangle
drawRoundRect(x, y, width, height, radius, color) Draws an empty rectangle with rounded corners.
fillRoundRect(x, y, width, height, radius, color) Draws a filled rectangle with rounded corners.


Execution Result


4. ASCII Code Output

This is an example of outputting characters corresponding to ASCII codes 1 to 8.

For more characters, please refer to the ASCII code table.

#include <Wire.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>

#define SCREEN_WIDTH 128
#define SCREEN_HEIGHT 64
#define OLED_ADDR 0x3C 

Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, -1);

void setup() {
  display.begin(SSD1306_SWITCHCAPVCC, OLED_ADDR);
  display.clearDisplay(); // Clear the screen

  // Text output settings
  display.setTextSize(1);       // Set text size
  display.setTextColor(WHITE);  // Set text color
  display.setCursor(0, 0);      // Set cursor position

  // Print ASCII code characters
  display.println("ASCII Code Print");

  // Print ASCII code characters
  for (char c = 1; c < 9; c++) { // From ASCII code 1 to 8
      display.print(c);                // Print each character
      display.print(" ");              // Add space
  }

  display.display(); // Display the buffer content on the screen
}

void loop() {
}


Execution Result


5. Bitmap Image Output

This is an example of outputting an image on the OLED by converting it into a byte array.


How to Convert an Image to a Byte Array

1. Go to image2cpp (javl.github.io).

2. Upload Image

Select a file to upload from the left-side Select image.

3. Image Settings

Enter the image size in the Canvas size field and check the Preview. If the image is too large and the Canvas size is not properly adjusted, the image may not display correctly in the Preview.


4. Output

Set the Code output format to Arduino Code and click Generate code. The array will be displayed below.

Copy the output array and use it in the example code.


Code

You can use the drawBitmap(x, y, bitmap, width, height, color) function to draw a bitmap image at a specified position.

The color is set to white, so the image will be displayed in white.


Change the const unsigned char ~ part on line 12 to the byte array you created above.

If the example image (64 x 64 size) is different in size, you will need to adjust the x and y cursor positions, as well as the width and height values in the drawBitmap function on line 56 to match the image size.

#include <Wire.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>

#define SCREEN_WIDTH 128
#define SCREEN_HEIGHT 64
#define OLED_ADDR 0x3C 

Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, -1);

// GONGZIPSA LOGO
const unsigned char GONGZIPSA [] PROGMEM = { 
	0xff, 0xff, 0xff, 0xf0, 0x0f, 0xff, 0xff, 0xff, 0xff, 0xff, 0xfe, 0x00, 0x00, 0x7f, 0xff, 0xff, 
	0xff, 0xff, 0xf0, 0x00, 0x00, 0x0f, 0xff, 0xff, 0xff, 0xff, 0xc0, 0x00, 0x00, 0x03, 0xff, 0xff, 
	0xff, 0xff, 0x00, 0x00, 0x00, 0x00, 0xff, 0xff, 0xff, 0xfc, 0x00, 0x00, 0x00, 0x00, 0x3f, 0xff, 
	0xff, 0xf8, 0x00, 0x00, 0x00, 0x00, 0x1f, 0xff, 0xff, 0xf0, 0x00, 0x00, 0x00, 0x00, 0x0f, 0xff, 
	0xff, 0xc0, 0x00, 0x00, 0x00, 0x00, 0x03, 0xff, 0xff, 0x80, 0x00, 0x10, 0x00, 0x40, 0x01, 0xff, 
	0xff, 0x00, 0x00, 0x30, 0x00, 0xe0, 0x00, 0xff, 0xff, 0x00, 0x00, 0x70, 0x00, 0xf0, 0x00, 0xff, 
	0xfe, 0x00, 0x00, 0xf0, 0x00, 0xf8, 0x00, 0x7f, 0xfc, 0x00, 0x01, 0xf0, 0x00, 0xfc, 0x00, 0x3f, 
	0xf8, 0x00, 0x03, 0xf0, 0x00, 0xfc, 0x00, 0x1f, 0xf8, 0x00, 0x03, 0xf0, 0x00, 0xff, 0x00, 0x1f, 
	0xf0, 0x00, 0x07, 0xf0, 0x00, 0xff, 0xe0, 0x07, 0xff, 0x80, 0x3e, 0xf0, 0x01, 0xff, 0xf8, 0x7f, 
	0xbf, 0xf1, 0xff, 0xe0, 0x01, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xf0, 0x03, 0xff, 0xff, 0xf7, 
	0xdf, 0xff, 0xff, 0xf0, 0x0f, 0xef, 0xff, 0xf3, 0xc7, 0xdf, 0xff, 0xf0, 0x0f, 0xe7, 0xff, 0x63, 
	0xc3, 0xff, 0xfc, 0xb0, 0x0f, 0xef, 0xff, 0xe3, 0x81, 0xff, 0xf9, 0xb0, 0x0f, 0xff, 0xff, 0xc1, 
	0x80, 0xff, 0xf1, 0x70, 0x07, 0xff, 0xcd, 0xc1, 0x80, 0xf9, 0xfc, 0xf0, 0x0f, 0xff, 0xef, 0xc1, 
	0x80, 0xc9, 0xff, 0xf0, 0x0f, 0xff, 0xff, 0xe1, 0x80, 0x5c, 0xff, 0xe0, 0x07, 0xfb, 0xff, 0xc1, 
	0x00, 0x7f, 0xcf, 0xe0, 0x07, 0xfb, 0xff, 0xc0, 0x00, 0x3f, 0xcf, 0xc0, 0x03, 0xff, 0xff, 0x80, 
	0x00, 0x1f, 0xff, 0x80, 0x01, 0xff, 0xff, 0x80, 0x00, 0x0f, 0xff, 0x00, 0x00, 0x7f, 0xff, 0x00, 
	0x00, 0x07, 0xff, 0x80, 0x00, 0xff, 0xfe, 0x00, 0x00, 0x01, 0xff, 0x80, 0x00, 0xff, 0xf4, 0x00, 
	0x00, 0x00, 0x7f, 0xc0, 0x01, 0xff, 0x90, 0x00, 0x00, 0x00, 0xff, 0xe0, 0x03, 0xff, 0x80, 0x00, 
	0x80, 0x00, 0xff, 0xe0, 0x03, 0xff, 0x80, 0x01, 0x80, 0x00, 0x73, 0x30, 0x02, 0x07, 0x00, 0x01, 
	0x80, 0x71, 0xcb, 0x4e, 0x7d, 0x78, 0xf0, 0x81, 0x81, 0xf3, 0xec, 0xdf, 0x7f, 0xfd, 0xf1, 0x81, 
	0x81, 0x06, 0x2c, 0xf0, 0x0b, 0xc7, 0x01, 0x81, 0xc1, 0x04, 0x7c, 0xe0, 0x13, 0xcf, 0x83, 0x83, 
	0xc3, 0x3c, 0x7a, 0xe6, 0x23, 0xf9, 0xf2, 0xc3, 0xc3, 0x1c, 0x73, 0xe2, 0x63, 0x80, 0x16, 0xc3, 
	0xe3, 0x1c, 0x53, 0xe2, 0xc3, 0x80, 0x17, 0xc7, 0xe3, 0xf7, 0xd1, 0xff, 0xf7, 0x83, 0xfc, 0xc7, 
	0xf1, 0xe3, 0x91, 0x3f, 0xff, 0x03, 0xc8, 0x4f, 0xf0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0x0f, 
	0xf8, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x1f, 0xf8, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x1f, 
	0xfc, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x3f, 0xfe, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x7f, 
	0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xff, 
	0xff, 0x80, 0x00, 0x00, 0x00, 0x00, 0x01, 0xff, 0xff, 0xc0, 0x00, 0x00, 0x00, 0x00, 0x03, 0xff, 
	0xff, 0xf0, 0x00, 0x00, 0x00, 0x00, 0x0f, 0xff, 0xff, 0xf8, 0x00, 0x00, 0x00, 0x00, 0x1f, 0xff, 
	0xff, 0xfc, 0x00, 0x00, 0x00, 0x00, 0x3f, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00, 0xff, 0xff, 
	0xff, 0xff, 0xc0, 0x00, 0x00, 0x03, 0xff, 0xff, 0xff, 0xff, 0xf0, 0x00, 0x00, 0x0f, 0xff, 0xff, 
	0xff, 0xff, 0xfe, 0x00, 0x00, 0x7f, 0xff, 0xff, 0xff, 0xff, 0xff, 0xf0, 0x0f, 0xff, 0xff, 0xff
};

void setup() {
  display.begin(SSD1306_SWITCHCAPVCC, OLED_ADDR);
  display.clearDisplay(); // Screen initialization
}

void loop() {
  display.clearDisplay(); // Clear the screen

  // Drawing a 64x64 bitmap image
  display.drawBitmap(32, 0, GONGZIPSA, 64, 64, WHITE); // (x, y, bitmap, width, height, color)

  display.display(); // Output the buffer contents to the screen
}

Execution Result

Due to flickering, the image appears cut off when captured, but in reality, the round logo is displayed clearly.


Purchase Link

GONGZIPSA