2

I've built the start of a persistence of vision display. The rotation platform itself is built and I have just mounted the LEDs. After doing some testing, I can only get very slow update speeds of the lights themselves. I am using a very simple for loop in Python3 on a Raspberrypi 3B+ using GPIO 10 and 11 to control the strip. The strip is managed by the Adafruit Dotstar library and is controlled by the SPI bus. I choose this Light Strip as it is a clone of the APA102c and is ideal for Persistence of Vision displays. The code below works as design it will travel down the strip and update each LED but quite slowly. Could this be a limitation of the Pi's speed? I feel as if it would have more than enough power for a list update of this nature.

import board
import time
import adafruit_dotstar as dotstar

#Reversed Order
dots = dotstar.DotStar(board.MOSI, board.SCK, 72, brightness=.2)
#Default From Adafruit
#dots = dotstar.DotStar(board.SCK, board.MOSI, 72, brightness=.2)

n_dots = len(dots)
for dot in range(n_dots):
        dots[dot] = (0, 0, 0)
#time.sleep(1)
start = time.time()
for dot in range(n_dots):
        dots[dot] = (255, 255, 255)
end = time.time()
timetoloop = end-start

print ('Finished %.2f'%timetoloop + " Seconds")
  • What exactly does "very slow" mean to you? How fast are the LEDs being updated and how fast do you want them to be updated? Give us numbers, please. Be very clear about how many LEDs are being updated. – Elliot Alderson Mar 19 '21 at 22:14
  • I just used the stopwatch on my phone so the number isn't perfect but it takes approximately 5-6 seconds to change the color of every LED down the strip. I am not yet sure what speed I will need for the POV display yet but I will likely a few hundred changes a second. – Billathekilla Mar 19 '21 at 22:42
  • That sort of slowness is implausible even for python and software based bit toggling. 144 LEDs is about 3500 bits, surely this only takes 1/10 of a second?! Do you have a $10 salae logic analyser clone? Maybe it's ime to dig into the code of the library, or some careful web searching. – tomnexus Mar 20 '21 at 01:19
  • @tomnexus I'm not familiar with the salae logic analyser. I have an oscilloscope in the closet if that will work. I'm not familiar with SPI so I'm not sure if it's readable that way. Regarding the timing being too high I added some timing code that you should now be able to see in the original posting the results are coming back as 3.3 seconds. That is with the reversed pins. I simply can't get it to work the other way around. The blanking of the LEDs in instantaneous. I'm not sure why. This one really has me scratching my head. – Billathekilla Mar 20 '21 at 02:19

1 Answers1

1

I note your pins SCK and MOSI are the other way around from the adafruit examples which say

dots = dotstar.DotStar(board.SCK, board.MOSI, 30, brightness=0.2)

So it's possible that although you're using the SPI pins, the clock and data can't take advantage of the hardware transceiver. You might be forcing it to send the bits in software, which in Python, won't be very fast.

Try swapping the pins in hardware, and in your code, see if that's faster.

tomnexus
  • 7,617
  • 3
  • 19
  • 35
  • I believe you are correct it seems as if my data and clock pins are reversed but upon switching them the LEDs stopped responding entirely. I tried it with the code both how I had it and the reversed order you sent. I'm not quite sure what's causing that. – Billathekilla Mar 19 '21 at 22:43
  • Another Interesting note is that even though the LEDs aren't changing the code is still running to completion much faster with the original Adafruit code. I can have the pins completely off the board and the reversed order code runs much slower. Unfortunately the LEDs won't respond without the reversed order. – Billathekilla Mar 19 '21 at 23:13
  • 1
    Have you turned on SPI on the Pi boot options? Look in sudo raspi-config . Perhaps it's not enabled, and python assumes it is...? – tomnexus Mar 20 '21 at 01:20
  • I'm not sure, but I don't think that's the issue. When I first started working with the Pi I went to Preferences->RaspberryPi Config->Interfaces and enabled SPI there. Do I also need to run a command with sudo to enable it? – Billathekilla Mar 20 '21 at 02:03
  • 1
    The SPI port showed as enabled in the GUI, but I followed your suggestion to go ahead and do it through raspi-config and it fixed it! The time has gone from 3.3 seconds down to .07 seconds. Thank You so much for taking the time to help! – Billathekilla Mar 20 '21 at 02:43