Go Down

Topic: multiple instances of ShiftPWM ? (Read 2457 times) previous topic - next topic

AdmiralCrunch

Hi there,

I have 3x HC595-Shift-Registers connected in a row (via Pin-Q[h])
.. each HC595 should control the PWM of one color (R,G, and B).

I use ShiftPWM and everything works fine, except that the Data-Pin of all HC595 alwys recieved the same data.. but I would need to control Data-Inputs to each HC595 seperately..

Is there a possibility to achieve this? Would I need 3 instances of ShiftPWM (if so, how would this look like in code?.. i mean, like in the example I only define the pins and include the libary(?))

DuinoPerson

To have each shift register control 1 colour, add this code or replace the current code:
  
Code: [Select]
  ShiftPWM.SetAmountOfRegisters(3);
  ShiftPWM.SetPinGrouping(8);
  ShiftPWM.Start(75, 255);

It will set the pin grouping to 8 pins each, or 1 shift register. This will also allow you to daisychain your shift registers. You can change the ShiftPWM.Start() however.

AdmiralCrunch

To have each shift register control 1 colour, add this code or replace the current code:
 
Code: [Select]
  ShiftPWM.SetAmountOfRegisters(3);
  ShiftPWM.SetPinGrouping(8);
  ShiftPWM.Start(75, 255);

It will set the pin grouping to 8 pins each, or 1 shift register. This will also allow you to daisychain your shift registers. You can change the ShiftPWM.Start() however.
Hi,

I did this.. but with wierd behaviour..
(have unwired everything except Red, for debugging)
when I do in the loop:
Code: [Select]

ShiftPWM.SetAll(0);
ShiftPWM.SetRGB(0,100,0,0);
delay(500);
ShiftPWM.SetRGB(1,100,0,0);
delay(500);
ShiftPWM.SetRGB(2,100,0,0);
delay(500);
ShiftPWM.SetRGB(3,100,0,0);
delay(500);



..the first LED goes on
.. the second LED goes on
.. the sixth LED goes on (dafuq!? .. oO)
.. the seventh LED goes on (:/)


DuinoPerson

#3
Jan 27, 2017, 08:29 am Last Edit: Jan 27, 2017, 08:35 am by DuinoPerson
I don't know what's happening. However, try debugging it. Some debugging ideas are:
1) Switching the shift registers for new ones.
2) Only using 1 shift register, setPinGrouping(2) and 2 LED's.
3) Seeing if they behave normally under the shiftOut() function.
4) Uploading the ShiftPWM_Non_Blocking example sketch and testing that.
You might also have a buggy version of the library. However, 4 LED's did come on, just not the right ones.

AdmiralCrunch

#4
Jan 27, 2017, 11:02 pm Last Edit: Jan 27, 2017, 11:53 pm by AdmiralCrunch
I don't know what's happening. However, try debugging it. Some debugging ideas are:
1) Switching the shift registers for new ones.
2) Only using 1 shift register, setPinGrouping(2) and 2 LED's.
3) Seeing if they behave normally under the shiftOut() function.
4) Uploading the ShiftPWM_Non_Blocking example sketch and testing that.
You might also have a buggy version of the library. However, 4 LED's did come on, just not the right ones.
1) I have switched the registers to totally new ones.. same


2) Did this,.. with just more wierd behaviour oO
.. when I do
Code: [Select]

  ShiftPWM.SetRGB(0,10,0,0);
  delay(500); 
  ShiftPWM.SetRGB(0,0,10,0);         
  delay(500); 
  ShiftPWM.SetRGB(0,0,0,10); 
  delay(500);
  ShiftPWM.SetAll(0);
  delay(500);

..the first LED should light up in red, green and blue.. right? .. okay, it does.. but to get the LEDs doing what the code says the pin-assignment has to be:

HC595: -    LED:
Q1      ->   red
Q3      ->   green
Q4      ->   blue

.. now i do the same with the second LED:
Code: [Select]

  ShiftPWM.SetRGB(1,10,0,0);
  delay(500); 
  ShiftPWM.SetRGB(1,0,10,0);         
  delay(500); 
  ShiftPWM.SetRGB(1,0,0,10); 
  delay(500);
  ShiftPWM.SetAll(0);
  delay(500);


now the pin-assignment has to be:

Q2 -> red
Q5 ->  ?? i don't know.. a signal comes from here, but with a ..delay.. I thought first, it will be the blue signal, but there is no signal on any pin when I do
Code: [Select]

ShiftPWM.SetRGB(1,0,0,10);



where is my blue signal?? oO ..

DuinoPerson

#5
Jan 28, 2017, 05:35 am Last Edit: Jan 30, 2017, 12:27 am by DuinoPerson
Try 3) and 4). Also, Q0 -> LED 1 red, Q1 -> LED 2 red, Q2 -> LED 1 green, Q3 -> LED 2 green, etc. If 3) doesn't work properly, then something is very badly broken. If 4) doesn't work and 3) does, then it's the library. Or maybe the Arduino is at the heart of the problem, it's happened to me with servos. You are using a PCB Arduino right?
EDIT: I'm using the library demonstrated here: https://www.youtube.com/watch?v=eyhpEVQhKLc, and it's worked fine for me. Also, make sure that the data and clock aren't swapped. I've done similar things once or twice...

AdmiralCrunch

Try 3) and 4). Also, Q0 -> LED 1 red, Q1 -> LED 2 red, Q2 -> LED 1 green, Q3 -> LED 2 green, etc. If 3) doesn't work properly, then something is very badly broken. If 4) doesn't work and 3) does, then it's the library. Or maybe the Arduino is at the heart of the problem, it's happened to me with servos. You are using a PCB Arduino right?
Hi,

Yes i use PCB-Arduino, but somehoe the whole IC acts strange.. I use the UTC U74HC595AG shiftregisters..

in every tutorial they teach to connect QE to GND, but when I do so, the IC stops working.. as if it yould be activeHigh.. (also the IC does not work when connectet to 5V ).. the stangest thing is, I really have to pull the jumper-wire out of the breadboard to get the IC working ..oO
 
.. I tried the same with a Mega and a Teensy

.. I changed the IC's to new ones..

.. i reduced the circuit to just one IC and 8 LEDs

nothing :(

3) Seeing if they behave normally under the shiftOut() function.
no it somehow behaves strange.. something always lights up, but never what I want :/

4) Uploading the ShiftPWM_Non_Blocking example sketch and testing that.
I did, same here.. isn't that the same as the standard example but with millis() instead of dealy() ? ..

DuinoPerson

#7
Feb 06, 2017, 02:53 am Last Edit: Feb 06, 2017, 11:23 am by DuinoPerson
Sorry for the late (ish) reply. If it's not your Arduino, make sure your shift registers have the same clock as the 74HC595's. As the library (and shiftOut!) were designed for 74HC595's, that's the problem I think.
EDIT: The clock on the 595's clocks in data when it is raised high.

AdmiralCrunch

#8
Feb 07, 2017, 02:45 pm Last Edit: Feb 08, 2017, 11:28 am by AdmiralCrunch
Sorry for the late (ish) reply. If it's not your Arduino, make sure your shift registers have the same clock as the 74HC595's. As the library (and shiftOut!) were designed for 74HC595's, that's the problem I think.
EDIT: The clock on the 595's clocks in data when it is raised high.
Hi,

I now got the IC runnig with shiftOut() .. but still there is this wierd behaviour with shiftPWM.
Somehow, the ShiftPWM.SetPinGrouping() does not what it shoud do:
Code: [Select]

void setup() {
  Serial.begin(9600);
  ShiftPWM.SetAmountOfRegisters(3);
  ShiftPWM.SetPinGrouping(8);
  ShiftPWM.Start(75, 255); 
}

void loop() {
    ShiftPWM.SetAll(0);
    delay(500);
   
    ShiftPWM.SetRGB(0,100,0,0);
    delay(500);
   
    ShiftPWM.SetRGB(0,0,100,0); 
    delay(500);
   
    ShiftPWM.SetRGB(0,0,0,100);
    delay(500);
}

should light me up LED 1 in red.. then in green... then in blue.. correct?
.. but look what it does instead https://youtu.be/8IctLHeVx6o

DuinoPerson

This is the example sketch, which I modified for your setup. If it doesn't work, your library is very broken. Or maybe your shift registers are a little bit more lax/strict about their timing than 595's. However, I still think that you should try the one I linked. If neither work, then your shift registers or arduino aren't compatible with the library. Again, if you have a different Arduino, try that. I've never had trouble with it using a Freetronics Eleven (R3) Uno clone and 595's.

AdmiralCrunch

#10
Feb 09, 2017, 08:23 am Last Edit: Feb 09, 2017, 08:31 am by AdmiralCrunch
Hi,

first.. thank you for your time :)

second.. no, does not work :/ .. I think I will try other 74hc595-ICs before giving up :/

AdmiralCrunch

#11
Feb 09, 2017, 09:17 pm Last Edit: Feb 09, 2017, 09:30 pm by AdmiralCrunch
Hi again :)

I just wanted to thank you all .. you guys rock!! :)

finally I got it running on the UNO  and

Code: [Select]

const int ShiftPWM_latchPin=8;
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(9600); 
  ShiftPWM.SetAmountOfRegisters(numRegisters);
  ShiftPWM.SetPinGrouping(8); 
  ShiftPWM.Start(pwmFrequency,maxBrightness);
}


void loop() {
  ShiftPWM.SetAll(0); 
  //ShiftPWM.PrintInterruptLoad(); 
  //ShiftPWM.OneByOneFast();

  delay(500);

  ShiftPWM.SetRGB(0,100,0,0);
  delay(500);

  ShiftPWM.SetRGB(0,0,100,0);
  delay(500);

  ShiftPWM.SetRGB(0,0,0,100);
  delay(500);

  ShiftPWM.SetRGB(1,100,0,0);
  delay(500);

  ShiftPWM.SetRGB(5,0,100,0);
  delay(500);

  ShiftPWM.SetRGB(7,100,0,100);
  delay(500); 
}


does exactly what it should! :)

the problem was, like GrumpyMike supposed in a other thread, I took the wrong pins.. big thanks Mike :))  .. it helped me with a problem I have been struggeling for weeks now :)

..now it runs in SPI-mode and everything is fine.. except.. I need to get it now running on a teensy3.2 :D .. but the teensy-libary has a strange bug.. Paul Stoffregen from pjrc acknowledged it.. so now I have to wait until he fixes it.

in the end.. maybe one more question.. there is the SetRGB() and the SetHSV() .. but what is the difference?

DuinoPerson

#12
Feb 19, 2017, 11:13 am Last Edit: Feb 26, 2017, 03:48 am by DuinoPerson
Sorry I didn't reply. Been busy + school = not much time. Anyway, to answer the question setHSV() is to set the HSV values, or hue-saturation-value (brightness). To understand what the hue is just imagine a colour wheel. setRGB() is to set the RGB values, or red-green-blue.
Also, make sure that the data and clock aren't swapped. I've done similar things once or twice...
Erm... I did mention the pins... I can never remember whether Xbee tx -> Arduino rx or tx myself though, so can't blame you.
EDIT: According to the example sketch:
 
Code: [Select]

// Clock and data pins are pins from the hardware SPI, you cannot choose them yourself if you use the hardware SPI.
// Data pin is MOSI (Uno and earlier: 11, Leonardo: ICSP 4, Mega: 51, Teensy 2.0: 2, Teensy 2.0++: 22)
// Clock pin is SCK (Uno and earlier: 13, Leonardo: ICSP 3, Mega: 52, Teensy 2.0: 1, Teensy 2.0++: 21)

// You can choose the latch pin yourself.
const int ShiftPWM_latchPin=8;

// ** uncomment this part to NOT use the SPI port and change the pin numbers. This is 2.5x slower **
// #define SHIFTPWM_NOSPI
// const int ShiftPWM_dataPin = 11;
// const int ShiftPWM_clockPin = 13;

Go Up