Skip to content

Commit d17f117

Browse files
committed
try to import bitbangio if busio SPI is not available
1 parent 409e909 commit d17f117

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

adafruit_dotstar.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -85,17 +85,23 @@ def __init__(self, clock, data, n, *, brightness=1.0, auto_write=True,
8585
pixel_order=BGR, baudrate=4000000):
8686
self._spi = None
8787
try:
88-
self._spi = busio.SPI(clock, MOSI=data)
88+
try:
89+
self._spi = busio.SPI(clock, MOSI=data)
90+
except (NotImplementedError, ValueError):
91+
import bitbangio
92+
self._spi = bitbangio.SPI(clock, MOSI=data)
93+
8994
while not self._spi.try_lock():
9095
pass
9196
self._spi.configure(baudrate=baudrate)
9297

93-
except (NotImplementedError, ValueError):
98+
except (NotImplementedError, ValueError, ImportError):
9499
self.dpin = digitalio.DigitalInOut(data)
95100
self.cpin = digitalio.DigitalInOut(clock)
96101
self.dpin.direction = digitalio.Direction.OUTPUT
97102
self.cpin.direction = digitalio.Direction.OUTPUT
98103
self.cpin.value = False
104+
99105
self._n = n
100106
# Supply one extra clock cycle for each two pixels in the strip.
101107
self.end_header_size = n // 16

0 commit comments

Comments
 (0)