2

I have a strip of WS2811 adressable RGB leds and I am trying to control them using my raspberry pi. I am programming in java. To access the GPIO I am using a java library called Pi4j (version 1.2; java 8). This version has built-in PWM control.

My question is the following: How can I send the data to the leds trough a GPIO pin?

(I am still a beginner when it comes to physical computing, so please be gentle)

error13660
  • 120
  • 7

1 Answers1

0

I haven't used NeoPixels directly on a Pi before (though I have many times used FadeCandy which is a USB LED controller that also does some nice dithering/frame blending).

Driving NeoPixels isn't as straight forward as plain PWM on individual LEDs.

There's a good Adafruit RaspberryPi NeoPixel wiring/coding tutorial. The notes on wiring/power are super useful. Even though the code is in Python, it's still useful to test/run.

Having a quick look at the pi4j documentation, while it has all the "ingredients", it doesn't have built-in support for NeoPixels. Doing a quick search I spotted the diozero library which seems to have support for NeoPixels.

I haven't tested diozero, but it's worth giving it a go.

George Profenza
  • 50,687
  • 19
  • 144
  • 218
  • Yeah, it definitely states that it has support, but i just can't find it among the provided classes nor the examples. – error13660 Nov 16 '21 at 22:32
  • Hmmm, true, the docs could use some detail :) Nonetheless, might be able to get something done with the [`WS281x`](https://github.com/mattjlewis/diozero/blob/efed6ccf52670ad499f38a8a3027723ad761b534/diozero-ws281x-java/src/main/java/com/diozero/ws281xj/rpiws281x/WS281x.java) class. I would try the simplest constructor first (`WS281x(int gpioNum, int brightness, int numPixels) ;`), then try a "blink" test calling `setPixelColour(int pixel, int colour)` to set the 1st LED green for example, then call `render()` to send the pixel data to the strip, set the green LED off, render() and repeat... – George Profenza Nov 16 '21 at 22:48
  • 1
    ...actually, digging deeper, try running [this test](https://github.com/mattjlewis/diozero/blob/efed6ccf52670ad499f38a8a3027723ad761b534/diozero-ws281x-java/src/main/java/com/diozero/ws281xj/sampleapps/WS281xTest.java). Be sure to double check the pin matches your configuration as well (notice the test uses pin 10, but has pin 18 commented out: it might be there for a reason ;) . HTH – George Profenza Nov 16 '21 at 22:51
  • 2
    Thank you so much, you might just saved my weird programmers' christmas! – error13660 Nov 17 '21 at 15:36
  • 1
    =))) my pleasure! (last time I've programmed NeoPixels was last xmas :))). when you're happy with the lights share a photo! Have fun! – George Profenza Nov 17 '21 at 15:58
  • Give me a Discord or an e-mail and i will send the pictures. It's alive! My Discord is: error13660 #7183 so you don't have to put yours here, where everyone can see it. – error13660 Dec 31 '21 at 16:01
  • @error13660 Nice! Please send the pictures to my email which you can find [on my website](https://sensori.al/) – George Profenza Jan 01 '22 at 03:44