rm-hull/luma.led_matrix

getting display() to work properly

Closed this issue · 8 comments

Type of Raspberry Pi

Raspberry Pi 3 B Plus

Linux Kernel version

Linux raspberrypi 4.14.52-v7+ #1123 SMP Wed Jun 27 17:35:49 BST 2018 armv7l GNU/Linux

Expected behaviour

I am trying to use display() to work, showing a (rather crude) drawing of a pair of eye on two daisy chained 8x8 matrices. The setup works fine with all examples provided, and I can tweak them to chance text, speeds and other characteristics of the displayed content.

Still, I can't get display() to work, that is, I can't display drawings of my own concoction.

Here is the code that got me the farthest: it doesn't generate errors and <> (I can't be sure what) flashes briefly on the displays. The code:

import numpy as np
from PIL import Image

from luma.core.interface.serial import spi, noop
from luma.led_matrix.device import max7219

serial = spi(port=0, device=0, gpio=noop())
device = max7219(serial, cascaded=2)

pixels = np.array([[000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000],
                   [000,000,000,255,255,000,000,000,000,000,000,255,255,000,000,000],
                   [000,000,255,000,000,255,000,000,000,000,255,000,000,255,000,000],
                   [000,255,000,000,000,000,255,000,000,255,000,000,000,000,255,000],
                   [000,255,000,000,255,000,255,000,000,255,000,000,255,000,255,000],
                   [000,255,000,255,255,000,255,000,000,255,000,255,255,000,255,000],
                   [000,000,255,000,000,000,255,000,000,255,000,000,000,255,000,000],
                   [000,000,000,255,255,255,000,000,000,000,255,255,255,000,000,000]])
				   
img = Image.fromarray(pixels, '1')

device.display(img)

Actual behaviour

Something (I can't be sure what) flashes briefly across the displays. And that's it. The code runs without errors, but nothing happens.

I have tried putting the display() command on an infinite loop, but still no result.

If I could be so bold, can an example of the correct usage be provided?

Thanks for any support you can provide (I am quite new on both python, raspberry pi and luma).

So, you should be aware that when the program finishes, it will clean up the device and switch it off. So simply, add a time.sleep(60) or something hold the image on the LEDs.

The display() command just expects a regular Pillow image - in your case, if you initialize an image of size 16x8, with a one bit pixel depth, like below, and then try just setting random pixels:

from PIL import Image
import time

from luma.core.interface.serial import spi, noop
from luma.led_matrix.device import max7219

serial = spi(port=0, device=0, gpio=noop())
device = max7219(serial, cascaded=2)

img = Image('1', (16, 8))
img.setpixel((2, 3), 1)
img.setpixel((5, 5), 1)
img.setpixel((11,6), 1)

device.display(img)
time.sleep(60)

(havent run this code, its just from memory, BTW)

The canvas is an abstraction over the Pillow library to allow you use primitives from Pillow's ImageDraw module.

Thanks for the prompt reply, Richard.

I ran the code you proposed. The cascaded displays blink for a fraction of a second (not even time enough to identify what is being plotted), and then just disappears.

Incidentally, I had tried time.sleep() before, with the same results.

Could this be a bug on display()?

Do you have any other programs running that may be using SPI ?

Do the demo programs work ok?

The examples work fine, and I even got an example you provided here on issues, that lights up random dots, four at a time.

Oh, and there’s nothing else running on the pi.

Same behaviour of my case (posted on "display output issue"), to me even the examples are not working at all, and nothing else running on the pi.

Would recommend you run an SPI loopback test to isolate whether there is extraneous chatter on the SPI bus - see https://github.com/rm-hull/spidev-test

No feedback, closing.