Go Down

Topic: ShiftPWM oddity (Read 42 times) previous topic - next topic

miryokuteki

I've run into a strange issue with using ShiftPWM (a modified version of the RGB_Test example) to control some RGB LED strips... The output from the SN74HC595 is only working with all channels at once (ex: Trying to set just an individual color, no matter what RGB/HSV value and/or method called, the strip lights up white). One may think at first that the issue is due to wiring, but here's the twist... If I don't use the ShiftPWM library and simply address the SN74HC595 manually (slightly altered AdaFruit shift register code) on the same pins (not changing anything about the wiring setup, only code), each channel of the RGB strip is addressed independently and functions exactly as it should.

I've used ShiftPWM on another creation (code included below) that uses the exact same pin setup and initialization code and have no trouble whatsoever. The only difference is that this problem is occurring on an Arduino Uno, whereas the perfectly functional one is running on a Nano. The serial monitor does not return any errors, either. If anyone has any idea what could be going on, I'd be very grateful, as I would not have to endure the tedium of coding the fade routines myself and can just use ShiftPWM's goodness. Thanks!

*** To answer a couple of quick questions that may negate the need to post a schematic, I am using a decoupling capacitor within millimeters of the VCC pin on the shift register and 220ohm resistors on the base of the transistors. The problematic setup may only be lighting white, but it does fade and flash as it should without flickering (and the AdaFruit code works fine), so I know it must be set up correctly.



*Code from AdaFruit that controls the individual RGB channels just fine, no wiring changes.
Code: [Select]
int latchPin = 8;
int clockPin = 12;
int dataPin = 11;
 
byte leds = 0;
 
void setup()
{
  pinMode(latchPin, OUTPUT);
  pinMode(dataPin, OUTPUT); 
  pinMode(clockPin, OUTPUT);
}
 
void loop()
{
  leds = 0;
  updateShiftRegister();
  delay(500);
  for (int i = 0; i < 8; i++)
  {
    bitSet(leds, i);
    updateShiftRegister();
    delay(500);
  }
}
 
void updateShiftRegister()
{
   digitalWrite(latchPin, LOW);
   shiftOut(dataPin, clockPin, LSBFIRST, leds);
   digitalWrite(latchPin, HIGH);
}




* Code from ShiftPWM RGB_Test example that works incorrectly, as described above:
Code: [Select]
const int ShiftPWM_latchPin=8;
#define SHIFTPWM_NOSPI
const int ShiftPWM_dataPin=11;
const int ShiftPWM_clockPin=12;
const bool ShiftPWM_invertOutputs = false;
const bool ShiftPWM_balanceLoad = false;
#include <ShiftPWM.h>

unsigned char maxBrightness = 255;
unsigned char pwmFrequency = 75;
int numRegisters = 1;
int numRGBleds = numRegisters*8/3;

void setup(){
  Serial.begin(9600);
  ShiftPWM.SetAmountOfRegisters(numRegisters);
  //ShiftPWM.SetPinGrouping(1);
  ShiftPWM.Start(pwmFrequency,maxBrightness);
  ShiftPWM.PrintInterruptLoad();
}

void loop()
{   
  ShiftPWM.SetRGB(0,255,0,0); delay(2000);
  ShiftPWM.SetRGB(0,0,0,0); delay(2000);
}




* Code on the other device that works flawlessly:
Code: [Select]
const int ShiftPWM_latchPin=8;
#define SHIFTPWM_NOSPI
const int ShiftPWM_dataPin=11;
const int ShiftPWM_clockPin=12;
const bool ShiftPWM_invertOutputs = false;
const bool ShiftPWM_balanceLoad = false;
#include <ShiftPWM.h>
unsigned char maxBrightness = 255;
unsigned char pwmFrequency = 75;
int numRegisters = 3;
int numRGBleds = numRegisters*8/3;

void setup() {
  Serial.begin(115200);
  ShiftPWM.SetAmountOfRegisters(numRegisters);
  ShiftPWM.Start(pwmFrequency,maxBrightness);
  ShiftPWM.SetPinGrouping(1);
  ShiftPWM.SetAll(0);
}

void loop() {
  ShiftPWM.SetRGB(0,255,0,0);
  delay(1000);
  ShiftPWM.SetRGB(0,0,0,0);
  delay(1000);
}

Go Up