tinue / apa102-pi

Pure Python library to drive APA102 LED stripes; Use with Raspberry Pi.
GNU General Public License v2.0
201 stars 71 forks source link

connecting APA102 LED and BSS138 level shifter #57

Closed Chandan-kumar-R closed 1 year ago

Chandan-kumar-R commented 1 year ago

I am having trouble getting my APA102 LED to work with a BSS138 level shifter. The APA102 LED has four wires (5V, GND, DI, and CI) and the BSS138 level shifter has ten wires (Hv, B1, B2, B3, B4, GND, LV, A1, A2, A3, A4). I am using a Raspberry Pi 4 as my controller.

I have followed the following steps to connect my APA102 LED and BSS138 level shifter:

  1. Vcc (5V) from APA102 LED is connected to Hv on BSS138 level shifter.
  2. GND from APA102 LED is connected to GND on BSS138 level shifter on the HV side.
  3. DI from APA102 LED is connected to B1 on BSS138 level shifter.
  4. CI from APA102 LED is connected to B2 on BSS138 level shifter.
  5. 3V from Raspberry Pi 4 is connected to LV on BSS138 level shifter.
  6. GND from Raspberry Pi 4 is connected to GND on BSS138 level shifter on the LV side.
  7. GPIO 20 from Raspberry Pi 4 is connected to A1 on BSS138 level shifter.
  8. GPIO 21 from Raspberry Pi 4 is connected to A2 on BSS138 level shifter.

I have also tried using the following code to control the LED:

from apa102_pi.driver import apa102
import signal
import sys
import time
import random

strip = apa102.APA102(num_led=5, order='rgb')

# Define a function to handle `Ctrl+C` signal
def signal_handler(sig, frame):
    strip.clear_strip()
    strip.cleanup()
    sys.exit(0)

# Register the `Ctrl+C` signal handler
signal.signal(signal.SIGINT, signal_handler)

def all_led():
    strip.set_pixel_rgb(0,  0x0000FF)
    strip.set_pixel_rgb(1,  0xFF0000)  # Red
    strip.set_pixel_rgb(2, 0x00FF00)  # Green
    strip.set_pixel_rgb(3, 0x00FF00)  # Green
    strip.set_pixel_rgb(4, 0x0000FF)  # Blue
    strip.set_pixel_rgb(5,  0x0000FF)
    strip.show()

def blink_all():
    for i in range(5):
        color = random.randint(0, 0xFFFFFF)
        strip.clear_strip()
        for j in range(5):
            if i == j:
                strip.set_pixel_rgb(j, color)
            else:
                strip.set_pixel_rgb(j, 0x000000)
        strip.show()
        time.sleep(0.5)

try:
    while True:
        all_led()
        time.sleep(1)
        blink_all()

except KeyboardInterrupt:
    # Turn off the LEDs and cleanup the GPIO pins when
        strip.clear_strip()
        strip.cleanup()

Note: Led works fine without using bss138 level shifter. Can anyone provide some guidance? Thank you for your help

Chandan-kumar-R commented 1 year ago

It wasn't working because there was voltage drop in the level shifter so I connected external power supply to HV side of the level shifter and it works now