Go Down

Topic: Help needed: Bi-color LED fading for Christmas tree (Read 281 times) previous topic - next topic

lanzer

Hello everyone, have a noob question and would like some pointers on how to get started on a project.

I recently got a christmas tree that has the 2 pin bicolor LED's, but its got a piss poor controller which can only blink the 2 colors back and forth.

I'm trying to setup a controller which can:

- drive 2 pin bi-color LED's running on 29v, powered by a 29v 0.6A adapter
- fade between one color to another using PWM
- Have control over the time it takes to fade from one polarity to another

I'll probably need a DC step down buck converter to drive the arduino, and I've found a very good example for driving the color fading through (https://github.com/wolfgang42/bicolorled).  The tricky part is figuring out how to make use of the PWM voltage to drive LED's from its own power supply.

I'm a programmer used to OOP and I'd love to spend the time and learn how to get started, and would like to ask for some pointers on where to look for projects that have similar properties, whether on the PWM aspect or on driving LED's with it's own power supply.  Also any suggestions on hardware would be appreciated.

Thank you in advance for any suggestions and pointers!

-Lanzer

sterretje

#1
Jan 12, 2019, 08:49 pm Last Edit: Jan 12, 2019, 08:49 pm by sterretje
Quote
The tricky part is figuring out how to make use of the PWM voltage to drive LED's from its own power supply.
You will need an H-bridge to be able to drive the led-pins in both directions.
If you understand an example, use it.
If you don't understand an example, don't use it.

Electronics engineer by trade, software engineer by profession. Trying to get back into electronics after 15 years absence.

lanzer

You will need an H-bridge to be able to drive the led-pins in both directions.
Oh, sounds like the L298N is exactly what I need!  Thank you!

lanzer

Took a little while to learn all the basics and how to debug, but everything is up and running thanks to your help!

I've put together a short guide for noobs like me who wants to do the same thing:

https://lanzerdiy.wordpress.com/2019/01/16/arduino-led-christmas-light-controller/



Yes, our Christmas tree is still up! :D

septillion

Haha, great job! Not only to get it working but also the post and having the tree still up :p

Couple remarks/questions:
-You could have used the hardware PWM just fine :)

- I'm missing a schematic ;)

- Uhmm:
Code: [Select]
const int pinCount = 2;
const byte pins[pinCount] = {5};

So using pin 0 then?
Use fricking code tags!!!!
I want x => I would like x, I need help => I would like help, Need fast => Go and pay someone to do the job...

NEW Library to make fading leds a piece of cake
https://github.com/septillion-git/FadeLed

lanzer

I have no idea what the hardware PWM is, can you elaborate? (like using analogWrite?)

Makes sense to include the schematic too.  Will slap something together in Photoshop :)

You caught the part that I had trouble with and took a while to debug.

The pins array has just one value so the pin count variable should be 1 instead of 2, but the moment I set that value to 1, the color would fade out but not back in.  Somehow defining a count of 2 would suppress the issue, and I left it that way.

Turns out the bug is caused by the portion where I told handlePWM to ignore all blinking logic if the brightness is at 100 or zero.  During the 5 seconds where brightness is at 100 or 0, It omits the logic but the TickCounter kept incrementing.  So by the time it resume the logic, TickCounter had ran away and became a negative value and screwed everything up.

And of course if there's only one pin I really should get rid of the array and loops, though I have a lighted tree topper and I might add another pin later.

All those nasty issues are fixed, and the fading is nice and smooth now. :)  Thanks for looking over the code!

septillion

analogWrite() IS the hardware PWM. And yes, that name is stupid and should have been pwmWrite() or something :)

And with a schematic I can look over the code in more detail if you like :)
Use fricking code tags!!!!
I want x => I would like x, I need help => I would like help, Need fast => Go and pay someone to do the job...

NEW Library to make fading leds a piece of cake
https://github.com/septillion-git/FadeLed

lanzer

Analog write is definitely a confusing name.  Took a while for me to figure out that it's actually digital signal output.

I've slapped together a schematic, hope it works:



If I can actually use analog write but somehow be able to have pin 5 be the opposite polarity, then I'd be in business.


septillion

Yeah, you can do that if you connect them to the same timer. I would use timer1 or timer2 for that so you can also increase the PWM frequency. If you connect it to pin 9 and pin 10 you can use the following in setup:

Code: [Select]
TCCR1A = (TCCR1A & 0b00001111) | COM1A1 | COM1B1 | COM1B0; //makes the two outputs inverse
TCCR1B = (TCCR1B & 0b11111000) | 0x02; //sets PWM frequency to 3,9kHz


Now if you set pin 9 and 10 to the same duty cycle (via analogWrite()) they will be each others inverse.
Use fricking code tags!!!!
I want x => I would like x, I need help => I would like help, Need fast => Go and pay someone to do the job...

NEW Library to make fading leds a piece of cake
https://github.com/septillion-git/FadeLed

Go Up