Skip to content

Commit 13e5377

Browse files
authored
Merge pull request #72 from taartspi/next_work7
update NeoPixel. Use Pi4 specific SPI baud. No longer modify /boot/c…
2 parents bb56f1f + 782f1e4 commit 13e5377

2 files changed

Lines changed: 16 additions & 12 deletions

File tree

src/main/java/com/pi4j/devices/neopixel94v/NeoPixel94V.java

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@
3939

4040
import com.pi4j.context.Context;
4141
import com.pi4j.io.spi.Spi;
42+
import com.pi4j.io.spi.SpiBus;
4243
import com.pi4j.io.spi.SpiConfig;
4344
import com.pi4j.io.spi.SpiMode;
4445
import com.pi4j.util.Console;
@@ -89,6 +90,12 @@ public class NeoPixel94V extends Component {
8990
* Default frequency of a WS2812 Neopixel Strip
9091
*/
9192
private final int frequency = 6400000;
93+
/**
94+
* Default frequency of a WS2812 Neopixel Strip
95+
*/
96+
private static final int DEFAULT_FREQUENCY_PI3 = 800_000; //use this for a Pi4
97+
private static final int DEFAULT_FREQUENCY_PI4 = 500_000; //use this for a Pi4
98+
9299
/**
93100
* between each rendering of the strip, there has to be a reset-time where nothing is written to the SPI
94101
*/
@@ -184,9 +191,10 @@ private SpiConfig buildSpiConfig(Context pi4j, int channel, int frequency) {
184191
return Spi.newConfigBuilder(pi4j)
185192
.id("SPI" + 1)
186193
.name("LED Matrix")
194+
.bus(SpiBus.BUS_0)
187195
.address(channel)
188196
.mode(SpiMode.MODE_0)
189-
.baud(frequency) // bit-banging from Bit to SPI-Byte
197+
.baud(8 * DEFAULT_FREQUENCY_PI4) // bit-banging from Bit to SPI-Byte
190198
.provider("pigpio-spi")
191199
.build();
192200

@@ -369,16 +377,17 @@ public void setBrightness(double brightness) {
369377
/**
370378
* Helper Class specific for only LEDStrips and matrices
371379
* can calculate different colors, and gets the individual color channels
380+
* G R B
372381
*/
373382
public class PixelColor {
374383
public static final int WHITE = 0xFFFFFF;
375384
public static final int RED = 0x00FF00;
376-
public static final int ORANGE = 0xFFC800;
385+
public static final int ORANGE = 0x66CC00;
377386
public static final int YELLOW = 0xFFFF00;
378387
public static final int GREEN = 0xFF0000;
379388
public static final int LIGHT_BLUE = 0xadd8e6;
380389
public static final int BLUE = 0x0000FF;
381-
public static final int PURPLE = 0x800080;
390+
public static final int PURPLE = 0x008080;
382391
public static final int PINK = 0xFFC0CB;
383392
public static final int Color_COMPONENT_MAX = 0xff;
384393
private static final int WHITE_MASK = 0xffffff;

src/main/java/com/pi4j/devices/neopixel94v/README.md

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@
3434

3535
# NeoPixel94V GRB Stick
3636

37-
37+
## Wiring: As coded this program uses SPI_0
3838

3939
1. mvn clean package
4040
2. cd target/distribution
@@ -43,19 +43,14 @@ Parm -t traceLevel
4343

4444
# NOTE:
4545
At present this code uses the SPI.
46+
The timing is calculated for the Pi4 hardware.
47+
4648
NEOPIXEL WS2812B uses the following timing to represent a '1' or a '0' bit. To
4749
accomplish in SPI, a '1' sends a byte0b11111000 and a '0' sends a byte 0b11000000.
4850
When the array of bytes are sent via SPI at a specific frequency the WS2812B
4951
interprets the bytes as correctly timed 0's and 1's.
50-
To accomplish the SPI frequency is set to 6400000. This frequency will vary
51-
dependent upon the PI throttling. To lock the frequency to the desired value:
52-
53-
PI4 : Add the following to /boot/config.txt
54-
core_freq=250
55-
core_freq_min=250
52+
To accomplish the SPI frequency is set to 8*500_000.
5653

57-
Similar changes for previous model PIs are not supplied. Also, no
58-
performance testing was performed to determine possible impacts
5954

6055
Pulse duration to represent a one or a zero.
6156
int32_t highTime0NanoSeconds, 400 ns

0 commit comments

Comments
 (0)