0.91인치 OLED 디스플레이 – 제품 소개

Language

0.91인치 OLED 디스플레이는 I2C 통신 기반의 저전력 디스플레이 모듈로, 해상도는 128x32입니다. Jetson 시리즈 메인 컨트롤러, Raspberry Pi, Orange Pi 등 다양한 개발 보드와 연결할 수 있으며 시스템 작동 상태 정보를 실시간으로 표시할 수 있습니다.

주요 기능

  • 📊 CPU 사용량 실시간 표시
  • ⏰ 현재 시스템 시간 표시
  • 💾 메모리 사용량 및 전체 메모리 표시
  • 🗄️ TF 카드 용량 사용량 표시
  • 🌐 기기 로컬 IP 주소 표시
  • 🔌 핫 스왑 지원, 안정적이고 신뢰성 높음

하드웨어 연결

배선 방법

I2C 통신 인터페이스를 사용한 배선 방법은 다음과 같습니다:

OLED 핀 개발 보드 핀
VCC 3.3V
GND GND
SDA I2C SDA
SCL I2C SCL
⚠️ 참고: 배선이 올바른지 확인하고 핀 단락을 피하세요. 단락 시 메인 보드 하드웨어가 손상될 수 있습니다.

소프트웨어 사용 가이드

지원 플랫폼:

  • ✅ Jetson 시리즈 메인 컨트롤러
  • ✅ 모든 Raspberry Pi 모델
  • ✅ 모든 Orange Pi 모델
  • ✅ I2C 통신을 지원하는 기타 Linux 개발 보드

Jetson 시리즈 설치 단계

1. 종속성 설치

sudo apt install -y python3-pip
sudo pip3 install smbus
sudo pip3 install Adafruit_SSD1306

2. I2C 장치 감지

# List all I2C buses
i2cdetect -l

# Detect I2C devices, OLED default address is 0x3c
i2cdetect -y -r *

3. 테스트 코드 실행

#!/usr/bin/env python3
# coding=utf-8
import time
import os
import sys
import Adafruit_SSD1306 as SSD
from PIL import Image, ImageDraw, ImageFont
import subprocess

class Juxi_OLED:
    def __init__(self, i2c_bus=1, debug=False):
        self.__debug = debug
        self.__i2c_bus = i2c_bus
        self.__top = -2
        self.__x = 0
        self.__total_last = 0
        self.__idle_last = 0
        self.__str_CPU = "CPU:0%"

    # Initialize OLED, return True on success, False on failure
    def begin(self):
        try:
            self.__oled = SSD.SSD1306_128_32(rst=None, i2c_bus=self.__i2c_bus, gpio=1)
            self.__oled.begin()
            self.__oled.clear()
            self.__oled.display()
            self.__width = self.__oled.width
            self.__height = self.__oled.height
            self.__image = Image.new('1', (self.__width, self.__height))
            self.__draw = ImageDraw.Draw(self.__image)
            self.__font = ImageFont.truetype("DejaVuSansMono.ttf",8)
            return True
        except:
            return False

    # Clear display, refresh=True to refresh immediately
    def clear(self, refresh=False):
        self.__draw.rectangle((0, 0, self.__width, self.__height), outline=0, fill=0)
        if refresh:
            self.refresh()

    # Add text at specified position
    def add_text(self, start_x, start_y, text, refresh=False):
        if start_x > 128 or start_x < 0 or start_y < 0 or start_y > 32:
            return
        x = int(start_x + self.__x)
        y = int(start_y + self.__top)
        self.__draw.text((x, y), str(text), font=self.__font, fill=255)
        if refresh:
            self.refresh()

    # Add text to specified line (1-4)
    def add_line(self, text, line=1, refresh=False):
        if line < 1 or line > 4:
            return
        y = int(8 * (line - 1))
        self.add_text(0, y, text, refresh)

    # Refresh OLED display
    def refresh(self):
        self.__oled.image(self.__image)
        self.__oled.display()

    # Get CPU usage
    def getCPULoadRate(self, index):
        count = 10
        if index == 0:
            f1 = os.popen("cat /proc/stat", 'r')
            stat1 = f1.readline()
            data_1 = []
            for i in range(count):
                data_1.append(int(stat1.split(' ')[i+2]))
            self.__total_last = sum(data_1)
            self.__idle_last = data_1[3]
        elif index == 4:
            f2 = os.popen("cat /proc/stat", 'r')
            stat2 = f2.readline()
            data_2 = []
            for i in range(count):
                data_2.append(int(stat2.split(' ')[i+2]))
            total_now = sum(data_2)
            idle_now = data_2[3]
            total = int(total_now - self.__total_last)
            idle = int(idle_now - self.__idle_last)
            usage = int(total - idle)
            usageRate = int(float(usage / total) * 100)
            self.__str_CPU = "CPU:" + str(usageRate) + "%"
            self.__total_last = 0
            self.__idle_last = 0
        return self.__str_CPU

    # Get system time
    def getSystemTime(self):
        cmd = "date +%H:%M:%S"
        date_time = subprocess.check_output(cmd, shell=True)
        str_Time = str(date_time).lstrip('b\'').rstrip('\\n\'')
        return str_Time

    # Get memory usage
    def getUsagedRAM(self):
        cmd = "free | awk 'NR==2{printf \"RAM:%2d%% -> %.1fGB \", 100*($2-$7)/$2, ($2/1048576.0)}'"
        FreeRam = subprocess.check_output(cmd, shell=True)
        str_FreeRam = str(FreeRam).lstrip('b\'').rstrip('\'')
        return str_FreeRam

    # Get disk usage
    def getUsagedDisk(self):
        cmd = "df -h | awk '$NF==\"/\"{printf \"SDC:%s -> %.1fGB\", $5, $2}'"
        Disk = subprocess.check_output(cmd, shell=True)
        str_Disk = str(Disk).lstrip('b\'').rstrip('\'')
        return str_Disk

    # Get local IP address
    def getLocalIP(self):
        ip = os.popen("/sbin/ifconfig enP8p1s0 | grep 'inet' | awk '{print $2}'").read()
        ip = ip[0: ip.find('\n')]
        if(ip == ''):
            ip = os.popen("/sbin/ifconfig wlP1p1s0 | grep 'inet' | awk '{print $2}'").read()
            ip = ip[0: ip.find('\n')]
            if(ip == ''):
                ip = 'x.x.x.x'
        if len(ip) > 15:
            ip = 'x.x.x.x'
        return ip

    # Main operation loop, support hot swap
    def main_program(self):
        state = False
        try:
            cpu_index = 0
            state = self.begin()
            while state:
                self.clear()
                str_CPU = self.getCPULoadRate(cpu_index)
                str_Time = self.getSystemTime()
                if cpu_index == 0:
                    str_FreeRAM = self.getUsagedRAM()
                    str_Disk = self.getUsagedDisk()
                    str_IP = "IPA:" + self.getLocalIP()
                self.add_text(0, 0, str_CPU)
                self.add_text(50, 0, str_Time)
                self.add_line(str_FreeRAM, 2)
                self.add_line(str_Disk, 3)
                self.add_line(str_IP, 4)
                self.refresh()
                cpu_index = cpu_index + 1
                if cpu_index >= 5:
                    cpu_index = 0
                time.sleep(.1)
        except:
            pass

if __name__ == "__main__":
    try:
        i2c_num = 7
        if len(sys.argv) > 1:
            if str(sys.argv[1]).isdigit():
                i2c_num = int(sys.argv[1])
        
        oled = Juxi_OLED(i2c_num, debug=True)
        while True:
            oled.main_program()
            time.sleep(2)
    except KeyboardInterrupt:
        oled.clear(True)
        del oled
        print(" Program closed! ")
        pass

4. 프로그램 시작

# Default bus 7
python3 Oled_i2c.py

# Or specify bus (e.g. bus 1)
python3 Oled_i2c.py 1

Raspberry Pi / Orange Pi 설치 단계

1. I2C 인터페이스 활성화

시스템 설정 진입: Preferences → Raspberry Pi Configuration → Interfaces → Enable I2C option, 그런 다음 시스템을 재시작합니다.

또는 명령줄 모드 사용:

sudo raspi-config
# Select Interface Options → I2C → Enable → Restart system

2. 종속성 설치

sudo apt install -y python3-dev python3-smbus i2c-tools python3-pil python3-pip python3-setuptools python3-rpi.gpio python3-venv

# Install required font
sudo apt-get install -y fonts-dejavu-core

3. 권한 구성

sudo chmod a+rw /dev/i2c-* # Temporary effect, permanent effect requires udev rule configuration

4. 장치 감지

i2cdetect -y 1
# Normally, device address 0x3c will be displayed

5. 가상 환경 생성(권장)

# Install virtual environment tool (if not installed)
sudo apt-get install -y python3-venv

# Create virtual environment
python3 -m venv oled_env

# Activate virtual environment
source oled_env/bin/activate

# Install required libraries
pip install Adafruit_SSD1306 pillow -i https://mirrors.aliyun.com/pypi/simple/

6. 프로그램 실행

python3 Oled_i2c.py 1
# If permission error occurs, check sudo configuration or I2C device permissions

표시 효과

프로그램이 정상 실행되면 OLED 화면에 다음 정보가 4줄로 표시됩니다:

  1. 첫 번째 줄: CPU 사용량 + 시스템 시간
  2. 두 번째 줄: 메모리 사용량 + 전체 메모리
  3. 세 번째 줄: TF 카드 사용량 + 총 용량
  4. 네 번째 줄: 기기 로컬 IP 주소

관련 링크

 

이 글은 요약본입니다. 전체 기술 문서는 Wiki에서 읽어보세요.

Wiki에서 전체 글 읽기 →

Feishu Wiki에서 열기