참고할것
https://custom-build-robots.com/top-story-de/jetson-nano-oled-display-ssd1306/11848?lang=en#prettyPhoto
https://github.com/adafruit/Adafruit_Python_SSD1306
연결하기
연결도 참조
1,3,5,9번 핀을 각각 oled의 VCC, SDA, CLK, GND에 연결한다.
설치하기
$ sudo python -m pip install --upgrade pip setuptools wheel
$ sudo pip install Pillow
$ sudo pip install Adafruit-SSD1306
DEPRECATION: Python 2.7 reached the end of its life on January 1st, 2020. Please upgrade your Python as Python 2.7 is no longer maintained. pip 21.0 will drop support for Python 2.7 in January 2021. More details about Python 2 support in pip can be found at <https://pip.pypa.io/en/latest/development/release-process/#python-2-support> pip 21.0 will remove support for this functionality.
WARNING: The directory '/home/r1mini/.cache/pip' or its parent directory is not owned or is not writable by the current user. The cache has been disabled. Check the permissions and owner of that directory. If executing pip with sudo, you may want sudo's -H flag.
Requirement already satisfied: Adafruit-SSD1306 in /usr/local/lib/python2.7/dist-packages/Adafruit_SSD1306-1.6.2-py2.7.egg (1.6.2)
Requirement already satisfied: Adafruit-GPIO>=0.6.5 in /usr/local/lib/python2.7/dist-packages/Adafruit_GPIO-1.0.4-py2.7.egg (from Adafruit-SSD1306) (1.0.4)
Collecting adafruit-pureio
Downloading Adafruit_PureIO-1.0.1.tar.gz (5.5 kB)
Requirement already satisfied: spidev in /usr/local/lib/python2.7/dist-packages/spidev-3.5-py2.7-linux-aarch64.egg (from Adafruit-GPIO>=0.6.5->Adafruit-SSD1306) (3.5)
Building wheels for collected packages: adafruit-pureio
Building wheel for adafruit-pureio (setup.py) ... done
Created wheel for adafruit-pureio: filename=Adafruit_PureIO-1.0.1-py2-none-any.whl size=5929 sha256=21664be32ac36a361ced803eb83f1ed71c8a722c632aaf4ae885ce78de15b814
Stored in directory: /tmp/pip-ephem-wheel-cache-8vkUBf/wheels/08/ba/ad/fc801094c71bfcdc8225d790aee4278077dd538e8f59c4370c
Successfully built adafruit-pureio
Installing collected packages: adafruit-pureio
Successfully installed adafruit-pureio-1.0.1
사용자를 i2c 퍼미션 추가
$ sudo usermod -aG i2c <username>
재부팅
i2cdetect 명령으로 핀번호 확인
$ sudo i2cdetect -y -r 1
[sudo] password for r1mini:
0 1 2 3 4 5 6 7 8 9 a b c d e f
00: -- -- -- -- -- -- -- -- -- -- -- -- --
10: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
20: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
30: -- -- -- -- -- -- -- -- -- -- -- -- 3c -- -- --
40: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
50: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
60: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
70: -- -- -- -- -- -- -- --
Hello world 출력하기
import Adafruit_SSD1306
from PIL import Image
from PIL import ImageDraw
from PIL import ImageFont
import subprocess
# 128x32 display with hardware I2C:
disp = Adafruit_SSD1306.SSD1306_128_32(rst=None, i2c_bus=1, gpio=1) # setting gpio to 1 is hack to avoid platform detection
# 라이브러리 초기화.
disp.begin()
disp.clear()
disp.display()
# 빈 이미지를 하나 만든다. Create blank image for drawing.
# 1bit 컬러(흑백)이미지이므로 이미지 모드를 '1'로 생성한다.
# Make sure to create image with mode '1' for 1-bit color.
width = disp.width
height = disp.height
image = Image.new('1', (width, height))
# 이미지에 그릴 객체를 받아온다. Get drawing object to draw on image.
draw = ImageDraw.Draw(image)
# 이미지를 검정으로 채운다. Draw a black filled box to clear the image.
draw.rectangle((0,0,width,height), outline=0, fill=0)
font = ImageFont.load_default()
# 0,0 위치에 Hello world를 쓴다.
draw.text((0, 0),"Hello world", font=font, fill=255)
# 이미지를 disp에 출력한다.
disp.image(image)
disp.display()