I'm fairly new to the Raspberry Pi and WLED world.
I'm trying to use a Raspberry Pi3 to control a strip of WS2811 LEDS (controlled in groups of 3) using the pigpio library. I have the latest bookworm os installed as well as all the appropriate libraries, to my knowledge.
I have a seperate 12 volt power supply for the LED strip and have tried connecting to GPIO 12 and 18 for PWM control but have no results. I have seperate power supplies for the LEDS strip (12vdc) and 5 volts for the data signal, as well as the Pi power supply. I've connected the commons of all of these to pi ground pin 14.
I have installed a voltage shifter on between the GPIO pin and the LED din, to go from 3.3 volts to 5 volts.
I also disable the audio as apparently this will interfere with the PWM signal to the LED strip. I'm automatically starting the PIGpio daemon from the code posted below.
I'm not getting any leds turning on, but when I remove the ground from the led stip all of them will light up, white, but I have no control of them.
Any help or suggestions would be greatly appreciated, including if a Pi is not the right tool for this project.
This is code ( + several variations) that I've been working with.
I'm trying to use a Raspberry Pi3 to control a strip of WS2811 LEDS (controlled in groups of 3) using the pigpio library. I have the latest bookworm os installed as well as all the appropriate libraries, to my knowledge.
I have a seperate 12 volt power supply for the LED strip and have tried connecting to GPIO 12 and 18 for PWM control but have no results. I have seperate power supplies for the LEDS strip (12vdc) and 5 volts for the data signal, as well as the Pi power supply. I've connected the commons of all of these to pi ground pin 14.
I have installed a voltage shifter on between the GPIO pin and the LED din, to go from 3.3 volts to 5 volts.
I also disable the audio as apparently this will interfere with the PWM signal to the LED strip. I'm automatically starting the PIGpio daemon from the code posted below.
I'm not getting any leds turning on, but when I remove the ground from the led stip all of them will light up, white, but I have no control of them.
Any help or suggestions would be greatly appreciated, including if a Pi is not the right tool for this project.
This is code ( + several variations) that I've been working with.
Code:
# to start pigpiod manually - sudo systemctl start pigpiodimport pigpioimport timeimport subprocess# ConfigurationLED_PIN = 12 # GPIO 12 (pin 32) - WS2811 dataNUM_LEDS = 5 # Set to 20 as per requirementSLEEP_TIME = 3 # Time to keep LEDs on# Ensure pigpiod startsdef start_pigpiod(): # make sure only 1 instance of pigpiod is running subprocess.run(["sudo", "pkill", "pigpiod"], check=False) # Kill existing daemon subprocess.run(["sudo", "pigpiod"], check=True) time.sleep(1) # Wait for pigpio to start# Function to create WS2811-compatible bitstreamdef encode_ws2811_byte(byte): # Converts a byte (8 bits) to the WS2811 waveform: # - A '1' bit is ~0.85µs high, ~0.4µs low. # - A '0' bit is ~0.4µs high, ~0.85µs low. bits = [] for i in range(8): if (byte & (1 << (7 - i))) != 0: # Bit is 1 bits.append(pigpio.pulse(1 << LED_PIN, 0, 800)) # High for 0.8µs bits.append(pigpio.pulse(0, 1 << LED_PIN, 450)) # Low for 0.45µs else: # Bit is 0 bits.append(pigpio.pulse(1 << LED_PIN, 0, 400)) # High for 0.4µs bits.append(pigpio.pulse(0, 1 << LED_PIN, 850)) # Low for 0.85µs return bits# Function to send WS2811 datadef send_ws2811_data(pi, led_pin, led_data): pi.wave_clear() # Clear previous waves pulses = [] for color in led_data: grb = (color[1], color[0], color[2]) # Convert RGB to GRB for byte in grb: pulses.extend(encode_ws2811_byte(byte)) # Add a reset pulse (50µs low) pulses.append(pigpio.pulse(0, 1 << led_pin, 50000)) # Create and send the waveform pi.wave_add_generic(pulses) wave_id = pi.wave_create() if wave_id >= 0: pi.wave_send_once(wave_id) while pi.wave_tx_busy(): time.sleep(0.001) # Wait for completion pi.wave_delete(wave_id)# Main programtry: start_pigpiod() pi = pigpio.pi() if not pi.connected: print("Failed to connect to pigpio daemon") exit() RED = (255, 0, 0) # RGB (Will be sent as GRB) OFF = (0, 0, 0) print("Turning on 5 LEDs RED") send_ws2811_data(pi, LED_PIN, [RED] * NUM_LEDS) time.sleep(SLEEP_TIME) print("Turning LEDs OFF") send_ws2811_data(pi, LED_PIN, [OFF] * NUM_LEDS) input("Press Enter to exit...")except KeyboardInterrupt: print("Stopping...")finally: send_ws2811_data(pi, LED_PIN, [OFF] * NUM_LEDS) # Turn off LEDs pi.stop() subprocess.run(["sudo", "systemctl", "stop", "pigpiod"], check=True) print("pigpiod daemon stopped")
Statistics: Posted by Busch123 — Tue Feb 18, 2025 6:46 pm — Replies 0 — Views 17