Skip to content

Commit

Permalink
Merge pull request #72 from taartspi/next_work7
Browse files Browse the repository at this point in the history
update NeoPixel.  Use Pi4 specific SPI baud. No longer modify /boot/c…
  • Loading branch information
taartspi authored Feb 15, 2024
2 parents bb56f1f + 782f1e4 commit 13e5377
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 12 deletions.
15 changes: 12 additions & 3 deletions src/main/java/com/pi4j/devices/neopixel94v/NeoPixel94V.java
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@

import com.pi4j.context.Context;
import com.pi4j.io.spi.Spi;
import com.pi4j.io.spi.SpiBus;
import com.pi4j.io.spi.SpiConfig;
import com.pi4j.io.spi.SpiMode;
import com.pi4j.util.Console;
Expand Down Expand Up @@ -89,6 +90,12 @@ public class NeoPixel94V extends Component {
* Default frequency of a WS2812 Neopixel Strip
*/
private final int frequency = 6400000;
/**
* Default frequency of a WS2812 Neopixel Strip
*/
private static final int DEFAULT_FREQUENCY_PI3 = 800_000; //use this for a Pi4
private static final int DEFAULT_FREQUENCY_PI4 = 500_000; //use this for a Pi4

/**
* between each rendering of the strip, there has to be a reset-time where nothing is written to the SPI
*/
Expand Down Expand Up @@ -184,9 +191,10 @@ private SpiConfig buildSpiConfig(Context pi4j, int channel, int frequency) {
return Spi.newConfigBuilder(pi4j)
.id("SPI" + 1)
.name("LED Matrix")
.bus(SpiBus.BUS_0)
.address(channel)
.mode(SpiMode.MODE_0)
.baud(frequency) // bit-banging from Bit to SPI-Byte
.baud(8 * DEFAULT_FREQUENCY_PI4) // bit-banging from Bit to SPI-Byte
.provider("pigpio-spi")
.build();

Expand Down Expand Up @@ -369,16 +377,17 @@ public void setBrightness(double brightness) {
/**
* Helper Class specific for only LEDStrips and matrices
* can calculate different colors, and gets the individual color channels
* G R B
*/
public class PixelColor {
public static final int WHITE = 0xFFFFFF;
public static final int RED = 0x00FF00;
public static final int ORANGE = 0xFFC800;
public static final int ORANGE = 0x66CC00;
public static final int YELLOW = 0xFFFF00;
public static final int GREEN = 0xFF0000;
public static final int LIGHT_BLUE = 0xadd8e6;
public static final int BLUE = 0x0000FF;
public static final int PURPLE = 0x800080;
public static final int PURPLE = 0x008080;
public static final int PINK = 0xFFC0CB;
public static final int Color_COMPONENT_MAX = 0xff;
private static final int WHITE_MASK = 0xffffff;
Expand Down
13 changes: 4 additions & 9 deletions src/main/java/com/pi4j/devices/neopixel94v/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@

# NeoPixel94V GRB Stick


## Wiring: As coded this program uses SPI_0

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

# NOTE:
At present this code uses the SPI.
The timing is calculated for the Pi4 hardware.

NEOPIXEL WS2812B uses the following timing to represent a '1' or a '0' bit. To
accomplish in SPI, a '1' sends a byte0b11111000 and a '0' sends a byte 0b11000000.
When the array of bytes are sent via SPI at a specific frequency the WS2812B
interprets the bytes as correctly timed 0's and 1's.
To accomplish the SPI frequency is set to 6400000. This frequency will vary
dependent upon the PI throttling. To lock the frequency to the desired value:

PI4 : Add the following to /boot/config.txt
core_freq=250
core_freq_min=250
To accomplish the SPI frequency is set to 8*500_000.

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

Pulse duration to represent a one or a zero.
int32_t highTime0NanoSeconds, 400 ns
Expand Down

0 comments on commit 13e5377

Please sign in to comment.