0
0

More than 1 year has passed since last update.

Raspberry Pi で Grove の LCD モジュールを使う

Last updated at Posted at 2021-09-28

次のページを参考にしました。
Grove - LCD RGB Backlight

ベースシールドは次のものを使いました。
Stackable Shield for Raspberry Pi 2.0

実行時の様子
IMG_20210929_080733.jpg

プログラム

display_lcd.py
#! /usr/bin/python3
#
#	display_lcd.py
#
# ------------------------------------------------------------------
import	sys
import	time
import	lcd_lib

# ------------------------------------------------------------------
sys.stderr.write("*** start ***\n")
count = 0
while True:
	text = 'count = ' + str(count)
	lcd_lib.setText_norefresh(text)
	time.sleep(1)
	count += 1
#
sys.stderr.write("*** end ***\n")
# ------------------------------------------------------------------
lcd_lib.py
#
#	lcd_lib.py
#
# ------------------------------------------------------------------
import	time
import	smbus

DISPLAY_RGB_ADDR = 0x62
DISPLAY_TEXT_ADDR = 0x3e

bus = smbus.SMBus(1)
# ------------------------------------------------------------------
def textCommand(cmd):
    bus.write_byte_data(DISPLAY_TEXT_ADDR,0x80,cmd)
# ------------------------------------------------------------------
def setText_norefresh(text):
    textCommand(0x02) # return home
    time.sleep(.05)
    textCommand(0x08 | 0x04) # display on, no cursor
    textCommand(0x28) # 2 lines
    time.sleep(.05)
    count = 0
    row = 0
    while len(text) < 32: #clears the rest of the screen
        text += ' '
    for c in text:
        if c == '\n' or count == 16:
            count = 0
            row += 1
            if row == 2:
                break
            textCommand(0xc0)
            if c == '\n':
                continue
        count += 1
        bus.write_byte_data(DISPLAY_TEXT_ADDR,0x40,ord(c))
#
# ------------------------------------------------------------------

次のバージョンで確認しました。

$ python3 --version
Python 3.7.3
0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0