From 782f1e422dd124488f971f52d671f8119e90b24c Mon Sep 17 00:00:00 2001 From: Tom Aarts Date: Thu, 15 Feb 2024 13:10:28 -0600 Subject: [PATCH] update NeoPixel. Use Pi4 specific SPI baud. No longer modify /boot/config.txt --- .../com/pi4j/devices/neopixel94v/NeoPixel94V.java | 15 ++++++++++++--- .../java/com/pi4j/devices/neopixel94v/README.md | 13 ++++--------- 2 files changed, 16 insertions(+), 12 deletions(-) diff --git a/src/main/java/com/pi4j/devices/neopixel94v/NeoPixel94V.java b/src/main/java/com/pi4j/devices/neopixel94v/NeoPixel94V.java index 46bed9a..51be5ea 100644 --- a/src/main/java/com/pi4j/devices/neopixel94v/NeoPixel94V.java +++ b/src/main/java/com/pi4j/devices/neopixel94v/NeoPixel94V.java @@ -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; @@ -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 */ @@ -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(); @@ -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; diff --git a/src/main/java/com/pi4j/devices/neopixel94v/README.md b/src/main/java/com/pi4j/devices/neopixel94v/README.md index 3769b91..9ee31ce 100644 --- a/src/main/java/com/pi4j/devices/neopixel94v/README.md +++ b/src/main/java/com/pi4j/devices/neopixel94v/README.md @@ -34,7 +34,7 @@ # NeoPixel94V GRB Stick - +## Wiring: As coded this program uses SPI_0 1. mvn clean package 2. cd target/distribution @@ -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