Hi there,
how is it possible to scroll text over 2 Unicorns on Raspi3?
I tried to change the width from 16 to 32 in the init.py file and connected the Unicorns on the same SPI with the same CS via daisy-chaining.
But the second matrix always remains blank!?
After that i gave them each its own CS (CS0 and CS1) and changed the init.py again.
Then i tried to wait for reaching the end of the first matrix with the first letter to start scrolling on the second matrix to keep the text running, but the text shows up identically as on the first matrix so it doesn’t end or start delayed on the second one.
I guess I have some mistakes in my code.
also it’s a bit strange to wait for scroll until it reaches 32 (end of first matrix) shouldn’t it be 16 (16 leds or 0-15)?
But the best thing would be if daisy-chaining would work, so I can use the second CS for another hardware.
Someone know where is the mistake?
Many thanks in advance!
Some code from init.py
[CODE]
version = ‘0.0.3’
_SOF = 0x72
_DELAY = 1.0/120
WIDTH = 16
#WIDTH = 32
HEIGHT = 16
PHAT = None
HAT = None
PHAT_VERTICAL = None
AUTO = None
_rotation = 0
_brightness = 0.5
#_buf = numpy.zeros((32,16,3), dtype=int)
_buf = numpy.zeros((16,16,3), dtype=int)
_buf2 = numpy.zeros((16,16,3), dtype=int)
is_setup = False
def setup():
global _spi, _spi0, _spi1, _buf, is_setup
if is_setup:
return
#general spi0
_spi = spidev.SpiDev()
_spi.open(0, 0)
_spi.max_speed_hz = 9000000
#spi0 with cs0
_spi0 = spidev.SpiDev()
_spi0.open(0, 0)
_spi0.max_speed_hz = 9000000
#spi0 with cs1
_spi1 = spidev.SpiDev()
_spi1.open(0, 1)
_spi1.max_speed_hz = 9000000
is_setup = True
def show():
"""Output the contents of the buffer to Unicorn HAT HD."""
setup()
#_spi.xfer2([_SOF] + (numpy.rot90(_buf,_rotation).reshape(1536) * _brightness).astype(numpy.uint8).tolist())
#array for 16x16
_spi.xfer2([_SOF] + (numpy.rot90(_buf,_rotation).reshape(768) * _brightness).astype(numpy.uint8).tolist())
time.sleep(_DELAY)
def showLED(matrix):
setup()
if matrix == 0:
_spi0.xfer2([_SOF] + (numpy.rot90(_buf,_rotation).reshape(768) * _brightness).astype(numpy.uint8).tolist())
elif matrix == 1:
_spi1.xfer2([_SOF] + (numpy.rot90(_buf2,_rotation).reshape(768) * _brightness).astype(numpy.uint8).tolist())
time.sleep(_DELAY)
[/CODE]
and from text example.py
[CODE]
#!/usr/bin/env python
import colorsys
import signal
import time
from sys import exit
try:
from PIL import Image, ImageDraw, ImageFont
except ImportError:
exit(“This script requires the pillow module\nInstall with: sudo pip install pillow”)
import unicornhathd
lines = [“ATTENTION!”,
“This is a text!”]
colours = [tuple([int(n * 255) for n in colorsys.hsv_to_rgb(x/float(len(lines)), 1.0, 1.0)]) for x in range(len(lines))]
FONT = ("/usr/share/fonts/truetype/roboto/Roboto-Bold.ttf", 10)
unicornhathd.rotation(0)
unicornhathd.brightness(0.3)
width, height = unicornhathd.get_shape()
#width = width*2
text_x = width
text_y = 3
#start_matrix1 = 0
scroll2 = -1
font_file, font_size = FONT
font = ImageFont.truetype(font_file, font_size)
text_width, text_height = width, 0
for line in lines:
w, h = font.getsize(line)
text_width += w + width
text_height = max(text_height,h)
text_width += width + text_x + 1
image = Image.new(“RGB”, (text_width,max(16, text_height)), (0,0,0))
draw = ImageDraw.Draw(image)
offset_left = 16 # begin on right side
for index, line in enumerate(lines):
draw.text((text_x + offset_left, text_y), line, colours[index], font=font)
offset_left += font.getsize(line)[0] + width
#############################################################################
for scroll in range(text_width - width):# 228-16 -> scroll until 211 (0-211)
for x in range(width):#32
for y in range(height):
pixel = image.getpixel((x+scroll, y))
r, g, b = [int(n) for n in pixel]
unicornhathd.set_pixel(width-1-x, y, r, g, b)
unicornhathd.showLED(0)
if scroll >= 32:
#scroll2=scroll2+1
pixel2 = image.getpixel((x+scroll2, y))
r2, g2, b2 = [int(k) for k in pixel2]
#matrix1()
unicornhathd.set_pixel2(width-1+scroll2, y, r2, g2, b2)
#unicornhathd.set_pixel2(scroll2, y, r, g, b)
unicornhathd.showLED(1)
unicornhathd.showLED(0)
time.sleep(1)
unicornhathd.off()
[/CODE]
Pimoroni originals from github
https://github.com/pimoroni/unicorn-hat-hd/blob/master/library/unicornhathd/init.py
and
github…/examples/text.py