본문 바로가기
IT/Platform

[RPi4] I2C LCD & Python

by 블랙오닉스 2022. 2. 5.

0. Ref

https://learn.adafruit.com/adafruit-16x2-character-lcd-plus-keypad-for-raspberry-pi/python-usage

 

Adafruit 16x2 Character LCD + Keypad for Raspberry Pi

This new Adafruit Pi Plate makes it easy to use an RGB 16x2 Character LCD. We really like the RGB Character LCDs we stock in the shop. Unfortunately, these LCDs do require quite a few digital pins, 6 to control the LCD and then another 3 to control the RGB

learn.adafruit.com

1. 연결

RPi4 I2C LCD 20x4
5V (2, 4) VCC
GND (6, 9, 14, ...) GND
SDA (3) SDA
SCL (5) SCL

2. 샘플 코드

import board
import busio
import adafruit_character_lcd.character_lcd_i2c as character_lcd
lcd_columns = 20
lcd_rows = 4
i2c = busio.I2C(board.SCL, board.SDA)
lcd = character_lcd.Character_LCD_I2C(i2c, lcd_columns, lcd_rows)
lcd.clear()
lcd.message = "Hello\nCircuitPython"

실행

python3 lcd.py

Traceback (most recent call last):
  File "/usr/local/lib/python3.7/dist-packages/adafruit_bus_device/i2c_device.py", line 154, in __probe_for_device
    self.i2c.writeto(self.device_address, b"")
  File "/usr/local/lib/python3.7/dist-packages/busio.py", line 166, in writeto
    return self._i2c.writeto(address, buffer, stop=stop)
  File "/usr/local/lib/python3.7/dist-packages/adafruit_blinka/microcontroller/generic_linux/i2c.py", line 49, in writeto
    self._i2c_bus.write_bytes(address, buffer[start:end])
  File "/usr/local/lib/python3.7/dist-packages/Adafruit_PureIO/smbus.py", line 314, in write_bytes
    self._device.write(buf)
OSError: [Errno 121] Remote I/O error

3. 연결확인

pi@raspberrypi:~ $ i2cdetect -y 1
     0  1  2  3  4  5  6  7  8  9  a  b  c  d  e  f
00:          -- -- -- -- -- -- -- -- -- -- -- -- -- 
10: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 
20: -- -- -- -- -- -- -- 27 -- -- -- -- -- -- -- -- 
30: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 
40: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 
50: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 
60: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 
70: -- -- -- -- -- -- -- --

4. 엘레파츠 블로그 확인

https://blog.naver.com/PostView.naver?blogId=elepartsblog&logNo=221583231746&parentCategoryNo=&categoryNo=34&viewDate=&isShowPopularPosts=false&from=postView 

 

라즈베리파이에서 파이썬으로 1602 I2C 캐릭터 LCD 사용하기

이번 포스팅에서는 라즈베리파이에서 1602 IIC LCD를 이용해 문자를 출력해 보는 동작을 하도록 하겠...

blog.naver.com

5. 샘플 코드 다운로드, 실행

git clone https://github.com/eleparts/RPi_I2C_LCD_driver
cd RPi_I2C_LCD_driver
python3 example.py

'IT > Platform' 카테고리의 다른 글

[FPGA] ZYBO Z7: UART (Pmod USBUART)  (0) 2022.02.12
[FPGA] ZYBO Z7: Vivado  (0) 2022.02.11
[FPGA] Vivado License @CentOS & Windows 10  (0) 2022.02.05
[FPGA] HDMI Solution  (0) 2022.02.03
[RPi] 4B Tips  (0) 2022.02.03