Arduino Forum

Using Arduino => LEDs and Multiplexing => Topic started by: jmstech1 on Jan 15, 2019, 05:21 am

Title: Controlling 2 RGB stips with 1 UNO. Is it possible?
Post by: jmstech1 on Jan 15, 2019, 05:21 am
Hi everyone! I'm new here and to Arduino but loving it!

I've played with some simple coding samples and managed to power up a 1/2 meter strip of 5050 RGB lights...changing colours etc through pins 4,5,6. But can I also power up a second strip of RGB through pins 11, 12 and 13 at the same time? Having them flash at different times? Maybe it's been done before but I'm a newbie. :D

Thanks for any help in advance!!

John
Title: Re: Controlling 2 RGB stips with 1 UNO. Is it possible?
Post by: pert on Jan 15, 2019, 05:50 am
Yes, you can do that.
Title: Re: Controlling 2 RGB stips with 1 UNO. Is it possible?
Post by: Wawa on Jan 15, 2019, 06:02 am
Flashing (on/off) can be done with any pin,
but only the PWM pins 3, 5, 6, 9, 10, and 11 can be used for brightness control.
Leo..
Title: Re: Controlling 2 RGB stips with 1 UNO. Is it possible?
Post by: jmstech1 on Jan 15, 2019, 07:06 am
Thank you Pert and Leo for answering that question which has been bugging me for days! Are there samples of codes I can analyze?

Right now I'm tinkering with simple codes like:

int redPin = 5;
int greenPin = 6;
int bluePin = 3;
 
//uncomment this line if using a Common Anode LED
//#define COMMON_ANODE

void setup() {
    pinMode(redPin, OUTPUT);
  pinMode(greenPin, OUTPUT);
  pinMode(bluePin, OUTPUT); 
}

void loop() {
    setColor(255, 0, 0);  // red
  delay(1000);
  setColor(0, 255, 0);  // green

etc..

Wondering if I'm heading in the wrong direction with my limited knowledge on coding.

Greatly appreciate the fast response here. Wasn't expecting that!

John
 
Title: Re: Controlling 2 RGB stips with 1 UNO. Is it possible?
Post by: Grumpy_Mike on Jan 15, 2019, 07:26 am
Quote
Are there samples of codes I can analyze?
Yes you have just posted it. Unfortunately you have not posted it all and correctly. See the how to use this forum sticky post. It looks like you are using a libiary but you missed that from your code. There is no need to use a libiary simply use an analogWrite for each PWM pin you want to set.


Simply add the extra pins like you have the origional ones. What are you using to drive the LED strips? Transistors or FETs? You can't run the strips off just the outputs.
Title: Re: Controlling 2 RGB stips with 1 UNO. Is it possible?
Post by: pert on Jan 15, 2019, 08:20 am
I assumed you weren't using PWM since in the first post you said you were using pin 4, which doesn't have PWM functionality. Now I see you're actually using pins 3, 5, 6.

I recommend studying File > Examples > 02.Digital > BlinkWithoutDelay and the associated tutorial:
https://www.arduino.cc/en/Tutorial/BlinkWithoutDelay (https://www.arduino.cc/en/Tutorial/BlinkWithoutDelay)
And use the millis() technique instead of delay(). That will make it easy to flash each strip independently without any timing interference between the two.
Title: Re: Controlling 2 RGB stips with 1 UNO. Is it possible?
Post by: jmstech1 on Jan 15, 2019, 08:28 am
Hi Grumpy_Mike,

Yes my bad for not posting all the codes. I am using FETs to drive these lights on a bread board. 6 in total with resistors to accommodate each.

pert: OK so I will check the link out to give me something to study. Once again greatly appreciate the great help here! :D

John
Title: Re: Controlling 2 RGB stips with 1 UNO. Is it possible?
Post by: jmstech1 on Jan 17, 2019, 05:15 am
OK so looking over the 2 types of examples suggested, I'm not too sure which is the best method I should go about. My goal is to use 2 strips of 5050 RGB LEDs. Each strips needs to 3 wires (red, green blue) connected to Arduino for instructions. Both LED strips share ground on the breadboard so I got that covered. Getting 1 LED strip to work is easy but trying to have 2 LED strips alternate flash is where I'm stumped.

John
Title: Re: Controlling 2 RGB stips with 1 UNO. Is it possible?
Post by: pert on Jan 17, 2019, 06:04 am
OK so looking over the 2 types of examples suggested, I'm not too sure which is the best method I should go about.
I suggested the BlinkWithoutDelay example. What was the other one?
Title: Re: Controlling 2 RGB stips with 1 UNO. Is it possible?
Post by: Grumpy_Mike on Jan 17, 2019, 09:34 am
If you want to extend what you have done and you want us to help then you have to post all your code. You are using some sort of library that you have not said what it is. The full code will contain a #include statement and that will tell us what libiary you are using.
Title: Re: Controlling 2 RGB stips with 1 UNO. Is it possible?
Post by: jmstech1 on Jan 18, 2019, 07:23 am
Hi guys,

Ok so here is the codes and hopefully I will see the light here... no pun intended. :D

John


Code: [Select]

/*
JMSTECH RGB LED test1
*/
 
int redPin = 5;
int greenPin = 6;
int bluePin = 3;
 
//uncomment this line if using a Common Anode LED
//#define COMMON_ANODE

void setup() {
    pinMode(redPin, OUTPUT);
  pinMode(greenPin, OUTPUT);
  pinMode(bluePin, OUTPUT); 
}

void loop() {
    setColor(255, 0, 0);  // red
  delay(1000);
  setColor(0, 255, 0);  // green
  delay(1000);
  setColor(0, 0, 255);  // blue
  delay(1000);
  setColor(255, 255, 0);  // yellow
  delay(1000); 
  setColor(80, 0, 80);  // purple
  delay(1000);
  setColor(255, 255, 255);  // white
  delay(1000);
  setColor(0, 255, 255);  // aqua
  delay(100);
  setColor(0, 0, 0);  // off
  setColor(0, 255, 255);  // aqua
  delay(100);
  setColor(0, 0, 0);  // off
  delay(100);
  setColor(0, 255, 255);  // aqua
  delay(100);
  setColor(0, 0, 0);  // off
  delay(500);
  setColor(0, 255, 255);  // aqua
  delay(500);
  setColor(0, 0, 0);  // off
  delay(500);
  setColor(0, 255, 255);  // aqua
  delay(700);
  setColor(0, 0, 0);  // off
  delay(700);
  setColor(0, 255, 255);  // aqua
  delay(700);
  setColor(0, 0, 0);  // off
  delay(700);
  setColor(0, 255, 255);  // aqua
  delay(700);
  setColor(0, 0, 0);  // off
  setColor(0, 255, 255);  // aqua
  delay(100);
  setColor(0, 0, 0);  // off
  setColor(0, 255, 255);  // aqua
  delay(1000);
  setColor(0, 0, 0);  // off
  delay(1000);
 
}
 
void setColor(int red, int green, int blue)
{
  #ifdef COMMON_ANODE
    red = 255 - red;
    green = 255 - green;
    blue = 255 - blue;
  #endif
  analogWrite(redPin, red);
  analogWrite(greenPin, green);
  analogWrite(bluePin, blue); 

}
Title: Re: Controlling 2 RGB stips with 1 UNO. Is it possible?
Post by: Grumpy_Mike on Jan 18, 2019, 12:23 pm
Well the code is quite appalling and I would not start from this point.

However, this is the simplest way to extend your code to add another strip. Basically the pin numbers are put in an array and the array index is passed to the setColor function, by the way you spelled colour wrong.

Code: [Select]


/*
JMSTECH RGB LED test1
*/
 
byte redPin[] = {5,11};
byte greenPin[] = {6,12};
byte bluePin[] = {3,13};
 
//uncomment this line if using a Common Anode LED
//#define COMMON_ANODE

void setup() {
    pinMode(redPin, OUTPUT);
  pinMode(greenPin, OUTPUT);
  pinMode(bluePin, OUTPUT);
}

void loop() {
  setColor(255, 0, 0,0);  // red strip 0
  setColor(255, 0, 0,1);  // red strip 1
  delay(1000);
  setColor(0, 255, 0,0);  // green strip 0
  delay(1000);
  setColor(0, 0, 255,1);  // blue strip 1
  delay(1000);
  setColor(255, 255, 0, 0);  // yellow strip 0
  delay(1000);
  setColor(80, 0, 80,1);  // purple strip 1
  delay(1000);
  setColor(255, 255, 255,0);  // white strip 0
  delay(1000);
  setColor(0, 255, 255, 1);  // aqua strip 1
  delay(100);
  setColor(0, 0, 0, 0);  // off strip 0
  setColor(0, 0, 0, 1);  // off strip 1
  setColor(0, 255, 255, 1);  // aqua strip 1
  delay(100);
  setColor(0, 0, 0, 1);  // off strip 1
  delay(1000);
 // rest of code missing due to being fed up you get the idea by now.
}
 
void setColor(byte red, byte green, byte blue, byte strip)
{
  #ifdef COMMON_ANODE
    red = 255 - red;
    green = 255 - green;
    blue = 255 - blue;
  #endif
  analogWrite(redPin[strip], red);
  analogWrite(greenPin[strip], green);
  analogWrite(bluePin[strip], blue);

}

Title: Re: Controlling 2 RGB stips with 1 UNO. Is it possible?
Post by: jmstech1 on Jan 18, 2019, 04:37 pm
Ahhh... Thanks Mike, will try this out tonight after work! Oh....I didn't spell colour wrong...lol, thats me fooling around with sample code made by others. I think there is a American version of "color" and Canadian version of "colour". To-mae-toes, to-maa-toes... :-P

John
Title: Re: Controlling 2 RGB stips with 1 UNO. Is it possible?
Post by: Grumpy_Mike on Jan 18, 2019, 04:41 pm
Quote
. I think there is a American version of "color" and Canadian version of "colour".
Indeed there is an American version but I am English and seeing I am the one giving the advice, I win.  ;)
Title: Re: Controlling 2 RGB stips with 1 UNO. Is it possible?
Post by: jmstech1 on Jan 18, 2019, 05:12 pm
Yes....you win. I can't argue with that. Hahaha!!!
Title: Re: Controlling 2 RGB stips with 1 UNO. Is it possible?
Post by: jmstech1 on Jan 20, 2019, 03:26 am
Hi Mike,

Just like to say thanks again for the help! Worked like a charm! :D

John