2020年1月27日月曜日

Controlling 16x8 Matrix LED with Raspberry Pi






































Raspberry Piに8x8 Matrix LED 2個を繋げてみた


制御chip HT16K33





















matrix 8x8 led  788ASY  *2
(昔 aitendoで入手した奴かな?!)
ブレッドボードに横並びで16x8に見えるように配置
(pinは上下8pinづつになりますな)

配線

LED pin   HT16K33
16        C7    (左led, 右led 共通)
15        C6
11        C5
6         C4
10        C3
4         C2
3         C1
13        C0

5         A0, A8  (左led, 右led)
2         A1, A9
7         A2, A10
1         A3, A11
12        A4, A12
8         A5, A13
14        A6, A14
9         A7, A15


試しに、circuitpythonを使って動作確認

# apt install python3-pip
# pip3 install --upgrade setuptools
# pip3 install RPI.GPIO
# pip3 install adafruit-blinka

# apt install python3-pil
# pip3 install adafruit-circuitpython-ht16k33


ValueError: No I2C device at address: 70  となる
/boot/config.txt でi2c bus 追加してた場合

# 4 i2c add
### dtoverlay=i2c-gpio,i2c_gpio_sda=0,i2c_gpio_scl=1,i2c_gpio_delay_us=2,bus=3
で、OK!!(コメント化)
busの指定が無いのが問題だけどね。CircuitPythonだからね。


sample code get
# git clone https://github.com/adafruit/Adafruit_CircuitPython_HT16K33.git


動作確認 code
[matrix16x8_heike_scroll.py]

#!/usr/bin/env python3

import time
import board
import busio

from PIL import Image
from PIL import ImageDraw
from PIL import ImageFont

from adafruit_ht16k33 import matrix

def horizontal_scroll(image, padding=True):

        image_list = list()
        width = image.size[0]
        # Scroll into the blank image.
        if padding:
            for x in range(16):
                section = image.crop((0, 0, x, 8))
                display_section = create_blank_image()
                display_section.paste(section, (16 - x, 0, 16, 8))
                image_list.append(display_section)

        #Scroll across the input image.
        for x in range(16, width + 1):
            section = image.crop((x - 16, 0, x, 8))
            display_section = create_blank_image()
            display_section.paste(section, (0, 0, 16, 8))
            image_list.append(display_section)

        #Scroll out, leaving the blank image.
        if padding:
            for x in range(width - 15, width + 1):
                section = image.crop((x, 0, width, 8))
                display_section = create_blank_image()
                display_section.paste(section, (0, 0, 15 - (x - (width - 15)), 8))
                image_list.append(display_section)

        #Return the list of images created
        return image_list

def create_blank_image():
      return Image.new("RGB", (16, 8))

# Create the I2C interface.
i2c = busio.I2C(board.SCL, board.SDA)

# Create the matrix class.
matrix = matrix.Matrix16x8(i2c, address=0x70)

text = "ぎおんしょうじゃのかねのこえ しょぎょうむじょうのひびきあり さらそうじゅのはなのいろ じょう しゃひっすいのことわりをあらわす おごれるひともひさしからず ただはるのよのゆめのごとし たけきもの もついにはほろびぬ ひとえにかぜのまえのちりにおなじ"

text_len = len(text)
image = Image.new('1', (text_len*8, 8))
draw  = ImageDraw.Draw(image)
font  = ImageFont.truetype("/home/pi/font/misakifont/misaki_gothic.ttf", 8, encoding='unic')
draw.text((0,1), text, font=font, fill=255)
new_image = image.transpose(Image.FLIP_TOP_BOTTOM)

image_list = horizontal_scroll(new_image)

max_images = len(image_list)
while True:
    for i in range(0, max_images):
         matrix.image(image_list[i])





0 件のコメント: