MAX7219 Arduino用ドットマトリクスモジュール4-in-1ディスプレイ5pinライン
てのを衝動買いしてしまったので、Raspberry Piで試してみました。
3.3Vで動きましたね
配線
MAX7219 Pin Name Remarks RPi Pin RPi Function
1 VCC +5V Power 1 3.3V
2 GND Ground 6 GND
3 DIN Data In 19 GPIO 10 (MOSI)
4 CS Chip Select 24 GPIO 8 (SPI CE0)
5 CLK Clock 23 GPIO 11 (SPI CLK)
ライブラリは以下のを使用させて頂きました。
https://github.com/rm-hull/luma.led_matrix
# git clone https://github.com/rm-hull/max7219.git
# cd max7219
# python3 setup.py install
[sample script]
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
import time
import argparse
from luma.led_matrix.device import max7219
from luma.core.interface.serial import spi, noop
from PIL import ImageFont
font = ImageFont.truetype("/home/pi/font/misakifont/misaki_gothic.ttf", 8, encoding='unic')
from PIL import Image
from PIL import ImageDraw
from PIL import ImageFont
_WIDTH=8
def horizontal_scroll(n, image, padding=True):
image_list = list()
width = image.size[0]
w, hight = image.size
# Scroll into the blank image.
if padding:
for x in range(n*_WIDTH):
section = image.crop((0, 0, x, hight))
display_section = create_blank_image(n, hight)
display_section.paste(section, (_WIDTH*n - x, 0, _WIDTH*n, hight))
image_list.append(display_section)
#Scroll across the input image.
for x in range(8*n, width + 1):
section = image.crop((x - _WIDTH*n, 0, x, hight))
display_section = create_blank_image(n, hight)
display_section.paste(section, (0, 0, _WIDTH*n, hight))
image_list.append(display_section)
#Scroll out, leaving the blank image.
if padding:
for x in range(width - (_WIDTH*n-1), width + 1):
section = image.crop((x, 0, width, hight))
display_section = create_blank_image(n, hight)
display_section.paste(section, (0, 0, ((8*n)-1) - (x - (width - ((8*n)-1))), hight))
image_list.append(display_section)
#Return the list of images created
return image_list
def create_blank_image(n, hight):
return Image.new("RGB", (_WIDTH*n, hight))
def main(n, block_orientation, rotate, inreverse):
# create matrix device
serial = spi(port=0, device=0, gpio=noop())
device = max7219(serial, cascaded=n or 1, block_orientation=block_orientation,
rotate=rotate or 0, blocks_arranged_in_reverse_order=inreverse)
text = "春はあけぼの やうやう白くなり行く、山ぎはすこしあかりて、むらさきだちたる雲のほそくたび きたる 夏は夜 夏は夜月のころはさらなり やみもなほ、ほたるの多く飛びちがひたる また、ただ一つ二つなど、ほのかにうち光りて行くもをかし 雨など降るもをかし"
text_len = len(text)
image = Image.new('1', (text_len*8, 8))
draw = ImageDraw.Draw(image)
font = ImageFont.truetype("/home/shin/font/misakifont/misaki_gothic.ttf", 8, encoding='unic')
draw.text((0,0), text, font=font, fill=255)
image_list = horizontal_scroll(n, image)
max_images = len(image_list)
while True:
for i in range(0, max_images):
# device.display(image_list[i].convert(device.mode))
device.display(image_list[i].convert('1'))
device.display(image_list[i].convert('1'))
# time.sleep(0.1)
time.sleep(0.5)
if __name__ == "__main__":
parser = argparse.ArgumentParser(description='matrix_demo arguments',
formatter_class=argparse.ArgumentDefaultsHelpFormatter)
parser.add_argument('--cascaded', '-n', type=int, default=4, help='Number of cascaded MAX7219 LED matrices')
parser.add_argument('--block-orientation', type=int, default=-90, choices=[0, 90, -90], help='Corrects block orientation when wired vertically')
parser.add_argument('--rotate', type=int, default=0, choices=[0, 1, 2, 3], help='Rotate display 0=0°, 1=90°, 2=180°, 3=270°')
parser.add_argument('--reverse-order', type=bool, default=False, help='Set to true if blocks are in reverse order')
args = parser.parse_args()
try:
main(args.cascaded, args.block_orientation, args.rotate, args.reverse_order)
except KeyboardInterrupt:
pass
0 件のコメント:
コメントを投稿