WS2801 LEDs not responding to encoder

Description

My 50 count of WS2801 LEDs will not illuminate or respond to inputs from the rotary encoder while running my code. I see from the serial monitor output that the "Test message", "Mode: ", "Calling displayRainbowPattern()", "Encoder: ", and "Button state: " functions work but none of the debugging output displays. I've run the LEDs on an example code while pulling power directly from the Arduino Uno successfully. The wiring, power, components, and part of my code appear to work but the LEDs do not illuminate. Any assistance is greatly appreciated.

Steps To Reproduce Problem

  1. Open a sketch window and input the code I've listed in the section titled "Arduino Sketch".
  2. Connect the encoder and LEDs to an Arduino Uno per the instructions listed in the "Arduino Sketch".
  3. Connect one end of a USB-B to USB-A cable to the Arduino Uno and the other end to a desktop.
  4. Upload code.
  5. See if the LEDs turn on and respond to the encoder inputs.

Hardware & Software

Board Shield(s)/module(s): Arduino Uno
IDE: Arduino 1.8.8
LEDs: 12mm Diffused Flat Digital RGB LED Pixels (two strands of 25) - WS2801
Rotary Encoder: 12mm Incremental Rotary Encoder PEC11 Series 2 Channel
Power: LEDs are connected directly to the Arduino Uno, as is the encoder, and the Arduino is powered through USB-B cable to an ACER desktop running Windows 10

Arduino Sketch

#include <Encoder.h>
#include <Adafruit_WS2801.h>

const int NUM_LEDS = 50;            // number of LEDs in strand
const int DATA_PIN = 11;            // data pin for WS2801 strand
const int CLOCK_PIN = 13;           // clock pin for WS2801 strand
const int BRIGHTNESS = 255;         // brightness of all leds
const int WHEEL_SIZE = 256;         // how many entries in the color wheel
const boolean MOVE_LIGHT = false;   // move one light around or keep all lights on
const int ENCODER_PIN_1 = 2;
const int ENCODER_PIN_2 = 3;
const int ENCODER_BUTTON = 4;        // Button pin for the encoder

Adafruit_WS2801 strip = Adafruit_WS2801(NUM_LEDS, DATA_PIN, CLOCK_PIN);
Encoder encoder(ENCODER_PIN_1, ENCODER_PIN_2);
int mode = 0;
long lastPush = 0;
int autoPosition = 0;

void initializeToBlack() {
  for (int i =0; i < NUM_LEDS; i++) {
   strip.setPixelColor(i, 0);
  }  
}

void setup() {
    
    Serial.begin(9600);
  // Print a test message to the serial monitor
    Serial.println("Test message");
    
    
    pinMode(ENCODER_BUTTON, INPUT);
    digitalWrite(ENCODER_BUTTON, HIGH); //turn pullup resistor on
    
    strip.begin();
    initializeToBlack();
    strip.show();    
}

long normalize(long value, long radix) {
  long rval = value % radix;
  if (rval < 0) return radix + rval;
  else return rval; 
}


void loop() {
    Serial.print("Mode: ");
    Serial.println(mode);

    // Add debug statement
    Serial.println("Calling displayRainbowPattern()");
    
    // Handle different modes
    switch (mode) {
        case 0:
            // Mode 0: Turn off all LEDs
            initializeToBlack();
            break;
        case 1:
            // Mode 1: Control LED color with rotary encoder
            // Implement code to set LED color based on encoder position
            // For example:
            // setLedColorBasedOnEncoder();
            break;
        case 2:
            // Mode 2: Display rainbow pattern on all LEDs
            displayRainbowPattern();
            break;
        case 3:
            // Mode 3: Move one LED along the strip
            // Implement code to move LED along the strip
            // For example:
            // moveSingleLED();
            break;
        case 4:
            // Mode 4: Move multiple LEDs along the strip
            // Implement code to move multiple LEDs along the strip
            // For example:
            // moveMultipleLEDs();
            break;
        default:
            // Handle unknown mode
            break;
    }
    
    // Show the updated LED colors
    strip.show();
    
        // Print out the encoder reading
    Serial.print("Encoder: ");
    Serial.println(encoder.read());

    // Print out the state of the encoder button
    Serial.print("Button state: ");
    Serial.println(digitalRead(ENCODER_BUTTON));

    // Delay to avoid flooding the serial monitor
    delay(500); // Adjust the delay as needed
    
    // Remaining loop code remains unchanged
}

// Function declaration for colorWheel()
uint32_t colorWheel(float intensity, byte wheelPos);

// Function definition for displayRainbowPattern()
void displayRainbowPattern() {
    for (int i = 0; i < NUM_LEDS; i++) {
        // Calculate color based on position in the rainbow
        long colorValue = normalize(i * 5, WHEEL_SIZE);
        // Set LED color
        strip.setPixelColor(i, colorWheel(BRIGHTNESS, colorValue));

        // Debugging output
        Serial.print("Setting LED ");
        Serial.print(i);
        Serial.print(" to color (R, G, B): ");
        Serial.print(strip.getPixelColor(i) >> 16 & 0xFF); // Red
        Serial.print(", ");
        Serial.print(strip.getPixelColor(i) >> 8 & 0xFF);  // Green
        Serial.print(", ");
        Serial.println(strip.getPixelColor(i) & 0xFF);      // Blue
    }
}

Errors or Incorrect Output

No errors are displayed in the IDE.

You will need external power for the WS2812. 50 x 60mA = 3000mA = 3A. if you use external power with insufficient current, you will get twinkles of various colors in various WS2812... a friend told me.

(this drawing was lifted from one of the forum users)

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.