0
\$\begingroup\$

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?

datasheet: bss138 https://cdn-shop.adafruit.com/datasheets/BSS138.pdf

apa102: datasheetapa102

\$\endgroup\$
1
  • \$\begingroup\$ Attaching the datasheet links and adding a schematic/block diagram will help get answers \$\endgroup\$
    – sai
    Commented May 3, 2023 at 10:14

2 Answers 2

1
\$\begingroup\$

The FET level shiter is just wrong kind of level shifter for your high speed unidirectional push-pull data signal. By default the library seems to use 8 MHz clock speed.

As per the library instructions, use a slower clock or suitable level shifter.

\$\endgroup\$
2
  • \$\begingroup\$ i have reduced the clock speed to 1500000hz but it still doesn't make any difference. @Justme \$\endgroup\$
    – Dragon
    Commented May 3, 2023 at 11:53
  • 1
    \$\begingroup\$ It may not work because 1.5 MHz is still very high for FET level shifters, especially if they have weak pull-ups and long wires. We don't know which resistors your shifter uses. \$\endgroup\$
    – Justme
    Commented May 3, 2023 at 12:06
1
\$\begingroup\$

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

\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.