I had some left over ATTiny85s from a different project, and came across some nice little spherical frosted glass Christmas tree ornaments and thought, "Hey, if I stuck an LED in there, it'd light up really nice." I ordered some of the clear "Piranha" RGB LEDs (here https://www.adafruit.com/products/314) and am now trying to figure out how to program my ATTiny85s to control it.
Problem is, I have been trying to use the HLT groups' Arduino core for ATTinys and realized that it only supports 2 PWM pins. Does anyone have any tips for how I can control an RGB using an ATTiny85 while still relying on an Arduino core? I'm afraid I don't have much desire to learn how to program microcontrollers directly with C in AVR Studio just yet, it was not fun at all the last time I tried.
Controlling an RGB LED with an ATTiny85
Moderators: adafruit_support_bill, adafruit
Please be positive and constructive with your questions and comments.
- jasonwebb
- Posts: 111
- Joined: Sat Sep 10, 2011 2:15 pm
Re: Controlling an RGB LED with an ATTiny85
Just found out that the ATTiny85 only has two PWM pins, not three. I tried using the Arduino Tiny core from http://code.google.com/p/arduino-tiny/, but that doesn't get around the fact that the ATTiny85 only ahs two PWM pins.
Does anyone have any tips that I can use to get three PWM channels out of an ATTiny85? To my knowledge, the SoftPWM library doesn't work on this core, but maybe something similar?
Does anyone have any tips that I can use to get three PWM channels out of an ATTiny85? To my knowledge, the SoftPWM library doesn't work on this core, but maybe something similar?
- cstratton
- Posts: 294
- Joined: Wed Sep 29, 2010 3:52 pm
Re: Controlling an RGB LED with an ATTiny85
How fast do you need to do the PWM?
The tiny85 can be clocked pretty fast (at expense of power of course) so you might be able to do it in software, either by a delay loop or by using a timer interrupt.
The tiny85 can be clocked pretty fast (at expense of power of course) so you might be able to do it in software, either by a delay loop or by using a timer interrupt.
- jasonwebb
- Posts: 111
- Joined: Sat Sep 10, 2011 2:15 pm
Re: Controlling an RGB LED with an ATTiny85
I'm not sure how fast is necessary. Fast enough to not have visible flicker?
The cores I have tried (HLT's and the Arduino Tiny) both clock the ATTiny85 at 8mhz, so I wonder if that is fast enough?
The cores I have tried (HLT's and the Arduino Tiny) both clock the ATTiny85 at 8mhz, so I wonder if that is fast enough?
-
- Posts: 46
- Joined: Sun Oct 23, 2011 11:17 am
Re: Controlling an RGB LED with an ATTiny85
That's not so. I have a board running in front of my keyboard right now driving a 3-color LED. PWM pins are 3 (OC1B), 5 (OC0A), and 6 (OC0B). I'm sorry I can't divulge much detail -- it's a joint venture with a local merchant who made the boards and is handling sales.zenwebb wrote:Just found out that the ATTiny85 only has two PWM pins, not three. I tried using the Arduino Tiny core from http://code.google.com/p/arduino-tiny/, but that doesn't get around the fact that the ATTiny85 only ahs two PWM pins.
Does anyone have any tips that I can use to get three PWM channels out of an ATTiny85? To my knowledge, the SoftPWM library doesn't work on this core, but maybe something similar?
I like Arduino for lashing things up fast -- command-driven test drivers and the like are a joy with Arduini, but as you found, you eventually get to the end of what it does. My production stuff winds up going straight to the AVR, controlling Timers and interrupts directly. A few hours with the data sheet will clue you in. Good Hunting.
- jasonwebb
- Posts: 111
- Joined: Sat Sep 10, 2011 2:15 pm
Re: Controlling an RGB LED with an ATTiny85
Unfortunately, I only have a basic knowledge of straight AVR programming, and have had a lot of bad experiences trying to learn (not exactly "beginner friendly" ). I guess this will be a good way for me to start learning!
I was glancing through the datasheet for the ATTiny85 earlier, and only found references to "two independent PWM channels", but they use those three pins you mentioned as outputs. For an absolute beginner to raw microcontroller programming (with a very limited conceptual knowledge of comparators, timers, interrupts, etc), what is a good way to learn the things I need to learn to complete a project like this? Seems like the "open source" community could really benefit from a collection of articles about transitioning from Arduino into raw AVR programming, because its a bit of a harsh jump for people like me!
I was glancing through the datasheet for the ATTiny85 earlier, and only found references to "two independent PWM channels", but they use those three pins you mentioned as outputs. For an absolute beginner to raw microcontroller programming (with a very limited conceptual knowledge of comparators, timers, interrupts, etc), what is a good way to learn the things I need to learn to complete a project like this? Seems like the "open source" community could really benefit from a collection of articles about transitioning from Arduino into raw AVR programming, because its a bit of a harsh jump for people like me!
-
- Posts: 46
- Joined: Sun Oct 23, 2011 11:17 am
Re: Controlling an RGB LED with an ATTiny85
That is what they say. They've left out the "Features" section for Timer/Counter1. It can do two PWMs as well -- except that it has to share one output pin with T/C0. Here's the initialization code I used to get 3 PWM channels out of T/C0 and T/C1. It ultimately comes out of the Datasheet doc2586, once that document has been digested:zenwebb wrote:[ ... ]
I was glancing through the datasheet for the ATTiny85 earlier, and only found references to "two independent PWM channels", but they use those three pins you mentioned as outputs. For an absolute beginner to raw microcontroller programming (with a very limited conceptual knowledge of comparators, timers, interrupts, etc), what is a good way to learn the things I need to learn to complete a project like this? Seems like the "open source" community could really benefit from a collection of articles about transitioning from Arduino into raw AVR programming, because its a bit of a harsh jump for people like me!
Code: Select all
DDRB = 1<<4 | 1<<1 | 1<<0; // outputs for LED PWMs
// Init T0, T1 for PWM control of LEDs
TCCR0A = 3<<COM0A0 | 3<< COM0B0 | 3<<WGM00; // PWMs low until compare-match
TCCR0B = 0<<WGM02 | 2<<CS00; // clock with Fosc/8
TCCR1 = 0<<PWM1A | 0<<COM1A0 | 4<<CS10; // clock with Fosc/8
GTCCR = 1<<PWM1B | 2<<COM1B0; // PWM low until compare-match
That idea -- a document to help people from Arduino Processing over to native AVR -- seems like a very good one. I've started to sketch in something.. I'll see whether I can make it look any good.
Cheers.
- cstratton
- Posts: 294
- Joined: Wed Sep 29, 2010 3:52 pm
Re: Controlling an RGB LED with an ATTiny85
I can think of a number of complications, but something that might be rather interesting would be a tool that could take an arduino sketch and dump out a stand alone C (or at least C++) project, ie, expanding macros and collecting functions into one or fewer files. To be informative, it might also want to optionally take out the multi-platform abstractions, leaving just code for the chip actually in use.mwilson wrote:That idea -- a document to help people from Arduino Processing over to native AVR -- seems like a very good one. I've started to sketch in something.. I'll see whether I can make it look any good.
-
- Posts: 472
- Joined: Tue Jan 08, 2008 12:43 am
Re: Controlling an RGB LED with an ATTiny85
Atmel has a software PWM application note.
For one example implementation, which uses sigma-delta modulation to dither the PWM value to increase color depth, see one of my projects:
https://github.com/Entropy512/I2C_RGB
WARNING: The I2C USI slave interface in the project above is unstable - it has a bad habit of hanging the bus. That's one of the reasons it hasn't been updated in so long...
For one example implementation, which uses sigma-delta modulation to dither the PWM value to increase color depth, see one of my projects:
https://github.com/Entropy512/I2C_RGB
WARNING: The I2C USI slave interface in the project above is unstable - it has a bad habit of hanging the bus. That's one of the reasons it hasn't been updated in so long...
-
- Posts: 58
- Joined: Sun Dec 06, 2009 11:12 pm
Re: Controlling an RGB LED with an ATTiny85
Maybe you could look at the blinkM for inspiration or ideas, since it's based on an ATtiny85 and RGB LED PWM control is really what the whole thing is dedicated to?
The code that runs on the ATtiny85 is not open source though.
The schematic for the BlinkM is open, I think - it's included in the manual, IIRC.
The code that runs on the ATtiny85 is not open source though.
The schematic for the BlinkM is open, I think - it's included in the manual, IIRC.
- burpees_NH
- Posts: 74
- Joined: Wed Dec 15, 2010 5:31 pm
Re: Controlling an RGB LED with an ATTiny85
Yes and no.
There's open source code that works similar to BlinkM (but to be clear, it is "not" blinkM).
Please see: http://www.instructables.com/id/Ghetto- ... ce-BlinkM/
I am building these myself right now. Well, after I finish assembling and testing my USBtinyISP.
There's open source code that works similar to BlinkM (but to be clear, it is "not" blinkM).
Please see: http://www.instructables.com/id/Ghetto- ... ce-BlinkM/
I am building these myself right now. Well, after I finish assembling and testing my USBtinyISP.
- jasonwebb
- Posts: 111
- Joined: Sat Sep 10, 2011 2:15 pm
Re: Controlling an RGB LED with an ATTiny85
That's PERFECT! Thanks!
- burpees_NH
- Posts: 74
- Joined: Wed Dec 15, 2010 5:31 pm
Re: Controlling an RGB LED with an ATTiny85
Most welcome, glad I could help. Do post your result if you get a chance.zenwebb wrote:That's PERFECT! Thanks!
I got this link from watching the Hack A Day website, by the way.
If you don't already follow HAD, it's probably the best place for "Great idea...I'm going to bookmark that and try it later".
- motocoder
- Posts: 15
- Joined: Tue Jul 23, 2013 12:49 am
Re: Controlling an RGB LED with an ATTiny85
WARNING - INCORRECT INFORMATION IN THIS THREAD
Earlier in this thread, someone says that the attiny85 only supports 2 hardware PWM outputs. This is NOT TRUE. Dont' get duped by this like I did, and waste time on an inferior software-based PWM algorithm. The attiny85 indeed supports 3 PWM channels - enough to control an RGB LED. If you are using the Arduino software to program the chip, you need to update the "core" files for this processor in order to make use of all 3 channels. Details can be found at:
http://forum.arduino.cc/index.php/topic,134754.0.html
or you can download the updated core directly from:
https://code.google.com/p/arduino-tiny/
and then follow the instructions in the README file to install it.
Earlier in this thread, someone says that the attiny85 only supports 2 hardware PWM outputs. This is NOT TRUE. Dont' get duped by this like I did, and waste time on an inferior software-based PWM algorithm. The attiny85 indeed supports 3 PWM channels - enough to control an RGB LED. If you are using the Arduino software to program the chip, you need to update the "core" files for this processor in order to make use of all 3 channels. Details can be found at:
http://forum.arduino.cc/index.php/topic,134754.0.html
or you can download the updated core directly from:
https://code.google.com/p/arduino-tiny/
and then follow the instructions in the README file to install it.
- zener
- Posts: 4567
- Joined: Sat Feb 21, 2009 2:38 am
Please be positive and constructive with your questions and comments.