1

I have SPI RGB led strip with three wires connection:
– TX1818 driver (manufacturer says “it’s compatible with TM1812, UCS1903, SM16703, WS2811–2815”)
– 12V, 9.3 W/m, 5060, 60/metre
– 3600 pixels, 60 lines, each 1 metre long with 60 pixels
– each 4 lines connected to power supply, 20 line per power supplier
– each line in section connected to power supply in parallel
– all lines have common ground and connected with common data cable
– length of data cable is about 2 metres between controller and matrix

Data cable and common ground connected to RPi 4b (21 GPIO). RPi has Raspberry Pi OS on the board, any software is up to date.

Connection schema enter image description here

The problem: show() method takes like more than 0.2s to execute (using adafruit-circuitpython-neopixel & rpi_ws281x python libraries, calling after matrix values are updated)

import numpy as np
from PIL import Image, ImageSequence
import time
import board
import neopixel

PIN = board.D21
NUM_PIXELS = 3600
MATRIX_SIZE = 60
ORDER = neopixel.RGB

pixels = neopixel.NeoPixel(
    PIN, NUM_PIXELS, auto_write=False, pixel_order=ORDER
)

# USING rpi_ws281x
# from rpi_ws281x import *
# LED_FREQ_HZ    = 800000
# LED_DMA        = 10
# LED_BRIGHTNESS = 100
# LED_INVERT     = False
# LED_CHANNEL    = 0
# LED_STRIP      = ws.WS2811_STRIP_GRB
# pixels = Adafruit_NeoPixel(NUM_PIXELS, PIN, LED_FREQ_HZ, LED_DMA, LED_INVERT, LED_BRIGHTNESS, LED_CHANNEL, LED_STRIP)
# pixels.begin()


def readImage(path = ‘./some.gif’):    
    return np.array([np.array(frame.copy().convert('RGB').getdata(),dtype=np.uint8).reshape(frame.size[0] * frame.size[1],3) for frame in ImageSequence.Iterator(Image.open(path))])
image = readImage()

def printFrame(pixels, frame):
    for rowIdx in range(NUM_PIXELS):
        pixels[rowIdx] = frame[rowIdx]

def animate(pixels, frames):
    for frame in frames:
        start = time.time()
        printFrame(pixels, frame)
        pixels.show()
        print(time.time() - start) # 0.3+ for adafruit-circuitpython-neopixel
                                   # 0.2+ for rpi_ws281x
        time.sleep(1/60)

while True:
    animate(pixels, image)

I also have Arduino Mega Rev3, but it’s not enough memory for 3600 pixel.
I thought about splitting matrix by three sections 60x20 (1200 pixels), each connected to separate SPI GPIO but couldn’t find libraries that can handle multiple channels as one. May be there is something I’m missing? Some hidden settings? Or for RPi some extension should be used for this case, like hat?

asvetly
  • 111
  • 2
  • 2
    RPi MCUs are, generally, ***very fast***!! Some are multi-core (memory serving.) Regardless, there should be zero problems getting fast displays. But I wouldn't assume so, if you are working with free library code. In general, these codes are designed to get anyone up and going without a lot of hassle. They are for simplistic applications. But they are NOT designed for ***fast*** nor for background operation. (My limited experience.) If you want performance and behavior that you understand and control, then you may need to be writing assembly code. – periblepsis Aug 20 '23 at 11:44
  • 2
    "but couldn’t find libraries that can handle multiple channels as one" - so create your own! – brhans Aug 20 '23 at 12:04
  • 1
    Also, an interpreted language like python may not be the best choice when you're aiming for speed. – brhans Aug 20 '23 at 13:07
  • any work except calling show() method takes like 0.01sec show() is a bottleneck, so, I guess, spi protocol is – asvetly Aug 20 '23 at 13:54
  • You say the led strip is SPI but your wiring says you are using 1 wire leds. The raspi is painfully slow at generating 1wire led data. Get yourself a led driver board and the raspi can talk via Ethernet to it. – Kartman Aug 20 '23 at 14:19
  • Theoretica time: 1.25 us per bit * 24 bits * 3600 LEDs = 108 ms. The driver probably uses 7 bit SPI (clock unused), 3 SPI bits per LED bit, sending 2 LED bits per SPI word, 1 bit wasted. So factoring in this inefficiency, 108 ms * 7/6 = 126 mS. Conclusion: you can do better by writing a better driver. – Mattman944 Aug 20 '23 at 23:12
  • yeah, it seems to be running about half speed, perhaps there's a UART mode that can be used, eg: 7n1 with 3 bits per symbol. – Jasen Слава Україні Aug 21 '23 at 01:06
  • Would a factor of (almost) 2x improvement be enough (assuming a theoretically perfect driver) and getting to keep all 3600 LEDs on a single channel? If not then you would have to go multi-channel. – brhans Aug 21 '23 at 17:39

0 Answers0