From 20b4421d8bc4f4daf35bdcb0de52afcca592be18 Mon Sep 17 00:00:00 2001 From: Luka Dojcinovic <56648891+Luka-D@users.noreply.github.com> Date: Wed, 18 Dec 2024 11:19:00 -0500 Subject: [PATCH 1/5] Added function to display to LEDs Added display_to_LEDs function and the dictionary to map array indices to the proper LED array indices. Signed-off-by: Luka Dojcinovic <56648891+Luka-D@users.noreply.github.com> --- QuantumRaspberryTie.qk1.py | 54 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 54 insertions(+) diff --git a/QuantumRaspberryTie.qk1.py b/QuantumRaspberryTie.qk1.py index 7edaa56..c348bd4 100644 --- a/QuantumRaspberryTie.qk1.py +++ b/QuantumRaspberryTie.qk1.py @@ -286,6 +286,17 @@ # scale lets us do a simple color rotation of hues and convert it to RGB in pixels +# LED array indices to map to pixel list +LED_array_indices = { + 0: 32, 1: 39, 2: 40, 3: 47, 4: 48, 5: 55, 6: 56, 7: 63, + 8: 33, 9: 38, 10: 41, 11: 46, 12: 49, 13: 54, 14: 57, 15: 62, + 16: 34, 17: 37, 18: 42, 19: 45, 20: 50, 21: 53, 22: 58, 23: 61, + 24: 35, 25: 36, 26: 43, 27: 44, 28: 51, 29: 52, 30: 59, 31: 60, + 32: 156, 33: 155, 35: 148, 35: 147, 36: 140, 37: 139, 38: 132, 39: 131, + 40: 157, 41: 154, 42: 149, 43: 146, 44: 141, 45: 138, 46: 133, 47: 130, + 48: 158, 49: 153, 50: 150, 51: 145, 52: 142, 53: 137, 54: 134, 55: 129, + 56: 159, 57: 152, 58: 151, 59: 144, 60: 143, 61: 136, 62: 135, 63: 128, +} #---------------------------------------------------------------------------- # Create a SVG rendition of the pixel array @@ -371,6 +382,45 @@ def resetrainbow(show=False): hat.set_pixels(pixels) if DualDisplay: hat2.set_pixels(pixels) +def display_to_LEDs(pixel_list, LED_array_indices): + try: + print("importing neopixel library...") + import board + import neopixel_spi as neopixel + except Exception as e: + print("Error importing neopixel library: ", e) + + try: + # Neopixel constants + NUM_PIXELS = 192 + PIXEL_ORDER = neopixel.RGB + BRIGHTNESS = 1.0 + + # Neopixel initialization + spi = board.SPI() + + pixels = neopixel.NeoPixel_SPI( + spi, + NUM_PIXELS, + pixel_order=PIXEL_ORDER, + brightness=BRIGHTNESS, + auto_write=False, + ) + except Exception as e: + print("Error initilizating Neopixel board: ", e) + + for index, pixel in enumerate(pixel_list): + # Get RGB data from pixel list + red, green, blue = pixel[0], pixel[1], pixel[2] + + # Get the corresponding index position on the LED array + LED_index = LED_array_indices[index] + + # Set the appropriate pixel to the RGB value + pixels[LED_index] = (red, green, blue) + + # Display image after all pixels have been set + pixels.show() #---------------------------------------------------------------- @@ -427,6 +477,10 @@ def showqubits(pattern='0000000000000000'): pixels[p]=[255,0,0] qubits=pixels qubitpattern=pattern + + # Test for LED array + display_to_LEDs(pixels, LED_array_indices) + hat.set_pixels(pixels) # turn them all on <== THIS IS THE STEP THAT WRITES TO THE MAIN 8x8 Hat array write_svg_file(pixels, svgpattern, 2.5, False) if DualDisplay: hat2.set_pixels(pixels) # <== THIS WRITES THE PATTERN TO A SECONDARY 8x8 DISPLAY From 7b66255f8a5eab9ad271afde25ab445efbb26802 Mon Sep 17 00:00:00 2001 From: Luka Dojcinovic <56648891+Luka-D@users.noreply.github.com> Date: Wed, 18 Dec 2024 11:23:10 -0500 Subject: [PATCH 2/5] Removed duplicate 35 index Signed-off-by: Luka Dojcinovic <56648891+Luka-D@users.noreply.github.com> --- QuantumRaspberryTie.qk1.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/QuantumRaspberryTie.qk1.py b/QuantumRaspberryTie.qk1.py index c348bd4..a2f85e3 100644 --- a/QuantumRaspberryTie.qk1.py +++ b/QuantumRaspberryTie.qk1.py @@ -292,7 +292,7 @@ 8: 33, 9: 38, 10: 41, 11: 46, 12: 49, 13: 54, 14: 57, 15: 62, 16: 34, 17: 37, 18: 42, 19: 45, 20: 50, 21: 53, 22: 58, 23: 61, 24: 35, 25: 36, 26: 43, 27: 44, 28: 51, 29: 52, 30: 59, 31: 60, - 32: 156, 33: 155, 35: 148, 35: 147, 36: 140, 37: 139, 38: 132, 39: 131, + 32: 156, 33: 155, 34: 148, 35: 147, 36: 140, 37: 139, 38: 132, 39: 131, 40: 157, 41: 154, 42: 149, 43: 146, 44: 141, 45: 138, 46: 133, 47: 130, 48: 158, 49: 153, 50: 150, 51: 145, 52: 142, 53: 137, 54: 134, 55: 129, 56: 159, 57: 152, 58: 151, 59: 144, 60: 143, 61: 136, 62: 135, 63: 128, From 7637d2b912a21ab80e0e57bd87847a21451f4b2b Mon Sep 17 00:00:00 2001 From: Luka Dojcinovic <56648891+Luka-D@users.noreply.github.com> Date: Thu, 2 Jan 2025 10:27:21 -0500 Subject: [PATCH 3/5] Added support for -neopixel flag and added UseNeo var --- QuantumRaspberryTie.qk1.py | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/QuantumRaspberryTie.qk1.py b/QuantumRaspberryTie.qk1.py index a2f85e3..69b24a4 100644 --- a/QuantumRaspberryTie.qk1.py +++ b/QuantumRaspberryTie.qk1.py @@ -383,13 +383,6 @@ def resetrainbow(show=False): if DualDisplay: hat2.set_pixels(pixels) def display_to_LEDs(pixel_list, LED_array_indices): - try: - print("importing neopixel library...") - import board - import neopixel_spi as neopixel - except Exception as e: - print("Error importing neopixel library: ", e) - try: # Neopixel constants NUM_PIXELS = 192 @@ -479,7 +472,8 @@ def showqubits(pattern='0000000000000000'): qubitpattern=pattern # Test for LED array - display_to_LEDs(pixels, LED_array_indices) + if UseNeo: + display_to_LEDs(pixels, LED_array_indices) hat.set_pixels(pixels) # turn them all on <== THIS IS THE STEP THAT WRITES TO THE MAIN 8x8 Hat array write_svg_file(pixels, svgpattern, 2.5, False) @@ -941,6 +935,7 @@ def StartQuantumService(): # If new output devices are added this needs to be expanded and showqubits updated to handle it if '-e' in parameter: UseEmulator = True # force use of the SenseHat emulator even if hardware is installed if '-dual' in parameter: DualDisplay = True + if '-neopixel' in parameter: UseNeo = True if '-select' in parameter: # SelectBackend is a special interactive prompt that appears for choosing the backend by name at the last moment during its instantiation SelectBackend = True @@ -990,6 +985,14 @@ def StartQuantumService(): sleep(1) else: SenseHatEMU = True +if UseNeo: + print("importing neopixel library...") + try: + import board + import neopixel_spi as neopixel + except Exception as e: + print("Error importing neopixel library: ", e) + else: if DualDisplay: # if you have a Sensehat but want the emulator running also. #Note that the svg file is always written, so you can open the ./svg/qubits.html file instead From 88ab5a7020b0418ac28badb51e409b3ee63ef6aa Mon Sep 17 00:00:00 2001 From: Luka Dojcinovic <56648891+Luka-D@users.noreply.github.com> Date: Wed, 22 Jan 2025 14:45:43 -0500 Subject: [PATCH 4/5] Moved neopixel setup code to Step 2 Signed-off-by: Luka Dojcinovic <56648891+Luka-D@users.noreply.github.com> --- QuantumRaspberryTie.qk1.py | 37 ++++++++++++++++++------------------- 1 file changed, 18 insertions(+), 19 deletions(-) diff --git a/QuantumRaspberryTie.qk1.py b/QuantumRaspberryTie.qk1.py index 69b24a4..ac709c1 100644 --- a/QuantumRaspberryTie.qk1.py +++ b/QuantumRaspberryTie.qk1.py @@ -383,25 +383,6 @@ def resetrainbow(show=False): if DualDisplay: hat2.set_pixels(pixels) def display_to_LEDs(pixel_list, LED_array_indices): - try: - # Neopixel constants - NUM_PIXELS = 192 - PIXEL_ORDER = neopixel.RGB - BRIGHTNESS = 1.0 - - # Neopixel initialization - spi = board.SPI() - - pixels = neopixel.NeoPixel_SPI( - spi, - NUM_PIXELS, - pixel_order=PIXEL_ORDER, - brightness=BRIGHTNESS, - auto_write=False, - ) - except Exception as e: - print("Error initilizating Neopixel board: ", e) - for index, pixel in enumerate(pixel_list): # Get RGB data from pixel list red, green, blue = pixel[0], pixel[1], pixel[2] @@ -992,6 +973,24 @@ def StartQuantumService(): import neopixel_spi as neopixel except Exception as e: print("Error importing neopixel library: ", e) + try: + # Neopixel constants + NUM_PIXELS = 192 + PIXEL_ORDER = neopixel.RGB + BRIGHTNESS = 1.0 + + # Neopixel initialization + spi = board.SPI() + + pixels = neopixel.NeoPixel_SPI( + spi, + NUM_PIXELS, + pixel_order=PIXEL_ORDER, + brightness=BRIGHTNESS, + auto_write=False, + ) + except Exception as e: + print("Error initilizating Neopixel board: ", e) else: if DualDisplay: # if you have a Sensehat but want the emulator running also. From b125ca2eed185813ee82ca2b3d89d060eb0aa47d Mon Sep 17 00:00:00 2001 From: Luka Dojcinovic <56648891+Luka-D@users.noreply.github.com> Date: Wed, 22 Jan 2025 14:49:45 -0500 Subject: [PATCH 5/5] Renamed pixels to neopixel_array Signed-off-by: Luka Dojcinovic <56648891+Luka-D@users.noreply.github.com> --- QuantumRaspberryTie.qk1.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/QuantumRaspberryTie.qk1.py b/QuantumRaspberryTie.qk1.py index ac709c1..81b6e4e 100644 --- a/QuantumRaspberryTie.qk1.py +++ b/QuantumRaspberryTie.qk1.py @@ -391,10 +391,10 @@ def display_to_LEDs(pixel_list, LED_array_indices): LED_index = LED_array_indices[index] # Set the appropriate pixel to the RGB value - pixels[LED_index] = (red, green, blue) + neopixel_array[LED_index] = (red, green, blue) # Display image after all pixels have been set - pixels.show() + neopixel_array.show() #---------------------------------------------------------------- @@ -982,7 +982,7 @@ def StartQuantumService(): # Neopixel initialization spi = board.SPI() - pixels = neopixel.NeoPixel_SPI( + neopixel_array = neopixel.NeoPixel_SPI( spi, NUM_PIXELS, pixel_order=PIXEL_ORDER,