Offline
Newbie
Karma: 0
Posts: 26
|
 |
« on: September 26, 2012, 05:49:07 am » |
Introductions are awkward, straight to business:
I need some advice on how to control 14 leds, with the smallest possible microprocessor. I'd rather not buy an arduino mini just for this project, as this is a school project. I haven't written any code yet, but I was thinking I could just count the time within the loop.
I discovered that it is possible to shrink your projects, by uploading your sketches into single chips, such as the ATtiny85. Now that's small enough, but it only has 6 I/O pins, and I need to control 14 leds. Unless I can find a 14 I/O chip that's relatively small, I'm going to need some help from you guys. I googled around and read something about an LED matrix, but I really don't get the idea, since it seems to require the same amount of outputs anyway. I guess it makes the code clearer.
TL;DR: What's the simplest way of controlling 14 LEDs with the smallest possible configuration?
|
|
|
|
« Last Edit: September 26, 2012, 06:04:46 am by iDroid »
|
Logged
|
|
|
|
|
Global Moderator
Boston area, metrowest
Online
Brattain Member
Karma: 270
Posts: 17051
Available for Design & Build services
|
 |
« Reply #1 on: September 26, 2012, 07:53:11 am » |
atmega328, 16 mhz crystal, two 22pf caps, three 100nF caps. 14 resistors, 14 LEDs.
|
|
|
|
|
Logged
|
|
|
|
|
Copenhagen, Denmark
Offline
God Member
Karma: 21
Posts: 886
Have you testrun your INO file today?
|
 |
« Reply #2 on: September 26, 2012, 09:48:39 am » |
atmega328, 16 mhz crystal, two 22pf caps, three 100nF caps. 14 resistors, 14 LEDs. A board to mount the stuff on. And access to someone else's system with a serial line to program it. Easier if the atmega328 already has a bootloader programmed.
|
|
|
|
|
Logged
|
|
|
|
|
Offline
Newbie
Karma: 0
Posts: 26
|
 |
« Reply #3 on: September 26, 2012, 10:27:08 am » |
atmega328, 16 mhz crystal, two 22pf caps, three 100nF caps. 14 resistors, 14 LEDs.
Thanks, but isn't the the ATmega series quite large, compared to Attiny? ATtiny 40 seems to have a max 18 I/O pins and it's definetely smaller. Do I need the crystal and caps if I'll end up using this one? What about the program to turn the leds on, can you suggest anything "smoother" than a bunch of if - structures? A board to mount the stuff on. And access to someone else's system with a serial line to program it. Easier if the atmega328 already has a bootloader programmed.
Right, that's pretty obvious. I've got a friend who has an Uno, so I can program the chip with it, right?
|
|
|
|
|
Logged
|
|
|
|
|
Valencia, Spain
Offline
Faraday Member
Karma: 72
Posts: 2501
|
 |
« Reply #4 on: September 26, 2012, 12:28:15 pm » |
atmega328, 16 mhz crystal, two 22pf caps, three 100nF caps. 14 resistors, 14 LEDs.
Thanks, but isn't the the ATmega series quite large, compared to Attiny? ATtiny 40 seems to have a max 18 I/O pins and it's definetely smaller. Do I need the crystal and caps if I'll end up using this one? What about the program to turn the leds on, can you suggest anything "smoother" than a bunch of if - structures? The smallest one with 14 pins would be an ATtiny4313. PS: You don't really need the crystal, they work just fine with their internal clock. The only time you need an external crystal is when you need accurate timing for, eg. serial communications. If you want a smaller AVR chip (Tiny84 or Tiny85) then you'll need an external 16 channel LED driver. I think the smallest 16 channel chip has 24 pins (eg. TLC5925). Right, that's pretty obvious. I've got a friend who has an Uno, so I can program the chip with it, right?
You can do it that way So long as he doesn't mind you pulling it apart. The best way to work with bare chips is to get an "ISP Programmer". They cost about $12 and when you have one you don't lose any flash memory to bootloaders, etc. PS: The ATtiny85 only really has five usable pins. You can use six pins but after you reconfigure the reset pin for I/O you can't upload any more software without a special device to configure it back again.
|
|
|
|
|
Logged
|
No, I don't answer questions sent in private messages...
|
|
|
|
Valencia, Spain
Offline
Faraday Member
Karma: 72
Posts: 2501
|
 |
« Reply #5 on: September 26, 2012, 12:32:27 pm » |
PPS: You could also do it with an ATtiny84 and a technique called "charlieplexing". It allows you to control (eg.) six LEDs with only three pins but it's tricky to get right. See: https://en.wikipedia.org/wiki/Charlieplexing
|
|
|
|
|
Logged
|
No, I don't answer questions sent in private messages...
|
|
|
|
Offline
Newbie
Karma: 0
Posts: 4
|
 |
« Reply #6 on: September 26, 2012, 01:44:17 pm » |
Using charleplexing, you can control up to 20 LEDs with 5 pins. This would be your best bet. I recently put some code up on Github that makes it relatively painless: https://github.com/marcuserronius/ChuckPlex/tree/1.0… as for controlling the LEDs, I'd make arrays organizing the relevant LEDs. Split the time up into separate decimal components, and extract the extract the place values of the ON bits from each, use them as indices for the LEDs array, i.e.: int digit1[] = {1,2}; int digit2[] = {3,4,5,6}; int digit3[] = {7,8,9}; int digit4[] = {10,11,12,13}; […] for(i=0;i<4;i++){ if(bitRead(timeDigit2,i){ // turn on LED digit2[i] } }
Something like that, maybe. If you go with multiplexing the LEDs, this *might* end up causing too much flicker, in which case you could build a list of LEDs to turn on and cycle them until the next time the time changes.
|
|
|
|
|
Logged
|
|
|
|
|
Offline
Newbie
Karma: 0
Posts: 29
|
 |
« Reply #7 on: September 28, 2012, 11:42:57 am » |
As you are building a BCD clock I would use an ATTiny with at least 8 outputs and arrange your leds on a 4x4 grid (with gaps where you dont need LEDs)
Then you can use 4 of your outputs for your rows and four for you columns and you have an easier solution than charlieplexing. You would need to row scan the rows of the 4x4 matrix but there are loads of tutorials on how to do that on these forums and on the net.
Something like X X X X X X X X X X X X X Hours Minutes
HTH
|
|
|
|
|
Logged
|
|
|
|
|
Anaheim CA.
Offline
Edison Member
Karma: 34
Posts: 2405
Experienced old Whitebeard with a Full head of Hair...
|
 |
« Reply #8 on: September 29, 2012, 04:52:45 pm » |
An RC oscillator isn't going to make a very accurate clock... Not at all. Go read the notes on RC frequency vs temperature and supply voltage variations. What you propose to do would be neat... as long as it didn't have to keep time.
Bob
|
|
|
|
|
Logged
|
“The solution of every problem is another problem.” -Johann Wolfgang von Goethe
|
|
|
|
Offline
Newbie
Karma: 0
Posts: 26
|
 |
« Reply #9 on: December 19, 2012, 09:37:10 am » |
Alright, hope this post isn't too old yet, because OP is here to deliver... Somewhat. So I got this set up on a breadbord with the Arduino Uno, just to see how the code works. I'm using the millis() function to count milliseconds from the time when the program started. Every 1000 milliseconds, it adds one to seconds, every 60 seconds it adds one to minutes and so on. Each LED is connected to it's own digital pin on the Uno and lights up accordingly with basic if functions. Right now there's only one button to set minutes on digital pin 0, but I plan to add one for hours as well when its time to shrinkify this project to the ATtiny2313. The reference page says that this millis() function overflows after approximately 50 days, how badly does this affect the clocks accuracy? I'm building the schematic with Eagle now. Do I need any other components, suchs as caps, in order for the ATtiny to work properly? Thanks for your help guys! EDIT: Will the buttons work with the ATtiny? I wired them (Or "it" at this time) as instructed on this page.
|
|
|
|
« Last Edit: December 19, 2012, 09:52:20 am by iDroid »
|
Logged
|
|
|
|
|
Copenhagen, Denmark
Offline
God Member
Karma: 21
Posts: 886
Have you testrun your INO file today?
|
 |
« Reply #10 on: December 19, 2012, 10:05:57 am » |
I tried something with using millis() to run a clock. That had a longterm drift (a minute or so every day). That was with an (older) Arduino with a crystals - the newers ones have something else that is not as regular.
Get an RTC chip, maybe on on a breakoutboard w/battery, and use it. (I dont know if you can get something that will interface easily with the ATTiny). By the way, I could set the 24 hour clock using just one push button (and some patientence)
|
|
|
|
|
Logged
|
|
|
|
|
Offline
Newbie
Karma: 0
Posts: 26
|
 |
« Reply #11 on: December 19, 2012, 10:40:36 am » |
Okay, I'll try to get one of those in my hands.
Well patience... doesn't quite belong in my vocabulary. Besides, it isn't very convenient if you have room for two buttons. I'll be setting the time in the code anyway before I upload it. I'm adding the button mainly for demonstration.
|
|
|
|
|
Logged
|
|
|
|
|
Copenhagen, Denmark
Offline
God Member
Karma: 21
Posts: 886
Have you testrun your INO file today?
|
 |
« Reply #12 on: December 19, 2012, 10:44:31 am » |
You will need to (re)set the time sometime. Daylightsaving f.ex. Or a powerloss, battery change. The "patience" was that my little onebutton algorithm involved waiting for a few secs for it to advance to the next digit and entering 9 required - yes, nine pushes.
|
|
|
|
|
Logged
|
|
|
|
|
Grand Blanc, MI, USA
Online
Faraday Member
Karma: 47
Posts: 2574
"We're a proud service of the Lost Electricity Reclamation Agency"
|
 |
« Reply #13 on: December 19, 2012, 10:50:03 am » |
The reference page says that this millis() function overflows after approximately 50 days, how badly does this affect the clocks accuracy?
Not at all. Search the forum, discussions on why this is not a problem constitute approximately 42% of the posts on the forum 
|
|
|
|
|
Logged
|
|
|
|
|
Offline
Newbie
Karma: 0
Posts: 26
|
 |
« Reply #14 on: December 19, 2012, 11:01:17 am » |
You will need to (re)set the time sometime. Daylightsaving f.ex. Or a powerloss, battery change. The "patience" was that my little onebutton algorithm involved waiting for a few secs for it to advance to the next digit and entering 9 required - yes, nine pushes.
Oh, I thought you meant pushing the minute button 60 times to advance one hour  Well, that's convenient enough. May I ask how did you do it? The reference page says that this millis() function overflows after approximately 50 days, how badly does this affect the clocks accuracy?
Not at all. Search the forum, discussions on why this is not a problem constitute approximately 42% of the posts on the forum  Okay, thanks!
|
|
|
|
|
Logged
|
|
|
|
|
|