Hi, I am trying to build some electronic dice for playing RISK. For this I need to connect 45 leds(21 red, 14 blue and 5 3pin duoleds), 13 buttons and a 2x16 LCD (HD44870 type). My first thought was to use 7x74HC595 shift registers for the ouput to the LEDS and LCD, and 2x74HC165 for the buttons. These I would then cascade together into one Attiny85.
But then I remembered I might be able to multiplex the shift registers for the LEDS (7x7) and the inputs(4x4), so I only need a total of three 74HC595 and only one 74HC165. Can I still cascade them all together, or should I use an Atmega328p instead of the Attiny85 and connect the lcd, buttons and leds all on their own pins?
Also when I multiplex the leds I will need to add a darlington driver array right? And due to the brightness difference of the different leds I would have to add different resistors to specific leds, or could the brightness be controlled using the refreshrate?
edit: a schematic of the idea, and a smaller version for easier view purposes.
Leo24DF:
Hi, I am trying to build some electronic dice for playing RISK. For this I need to connect 45 leds(21 red, 14 blue and 5 3pin duoleds), 13 buttons and a 2x16 LCD...should I use an Atmega328p instead...
Does sound like a 328 might be simpler! How would the leds be used, how many at once?
Maybe if you attached an Export of the schematic, sized for about 1000 wide.
74HC595 is limited to 70mA total current source or sink, size your resistors accordingly.
I don't know if you could view the schematic, the resolution is a bit high and the bbcode I used to resize the image does not seem to work properly. But the link to imgur is there now.
I was trying to use the ULN2003A as a current sink because of the limitations of the 74CH595, and read somewhere that it should work this way.
The 16pin header in the top, goes to a 16x2 LCD module btw.
4899x3492 - that's like 5 screens wide by 4 tall.
Export in eagle, under Area select Window, then decrease the resolution so its ~1000 wide x whatever.
So you have changed the design from an attiny85 to an atmega328. But you still have all those shift registers. I count 14 unused pins on the atmega. What will you be using those for?
I honestly could not make up my mind of what to use them for. The easiest solution would be to discard the 74HC165N's altogether and connect all the buttons on the atmega328.
After doing that I would have only 2 unused pins left.
Edit: Apparantly it's four pins, as in the edited schematic.
Also It seems that I have connected the ULN2003 the wrong way around right?
Yes,the ULN2003 needs to have the Is connected to the shift register, the Qs connected to the LED cathodes, and Gnd connected to Gnd. COM is left open.
Reset needs a 10K to Vcc.
If you move two switches off the Rx & Tx pins to the free PortC pins, and add a cap with one end connected to the reset pin and the other end to a header with Rx, Tx, Vcc, Gnd, you can connect an offboard USB/Serial adapter and download sketches into a bootloaded processor without having to pull it out of the board for every software change.
I've been thinking, and I recon you could do all that with no shift registers. Just the uln2003 to sink current from the common cathodes.
Extend your current led matrix to include the bicolour leds (2 more rows) and the switches (2 rows, bypassing the uln). So that's 9 rows x 7 columns. Drive the 9 rows directly from 9 atmega pins. Drive the uln2003 directly using 7 more pins from the atmega. Use 8 of the 9 row pins to drive the lcd in 8 bit mode. One more atmega pin for the lcd enable line.
Not 100% sure on this yet, but would save you alot of chips and complexity!
I have tried to put the switches and duo leds in the matrix, only I am not sure how I should connect the lcd module ( standard 2x16 arduino lcd library compatible type). This seems about right, since writing to the lcd is only possible when the 'write enable line' is high right?
Yes, that looks pretty much like I was imagining. Excellent work.
I would free up the tx and rx lines as Bob suggested. You have 3 other lines to use instead.
I think the lcd connections look fine. Can't remember exactly which pin is which off top of my head, but I remember 6 are needed for 4 bit mode. Strictly speaking I think it reads the data on a falling edge on the enable pin, but essentially you are correct.
So what do you think of the idea?
Can anyone see any problems with this approach. Obviously some careful coding will be needed...
I have edited the schematic, and added a 5 pin connector which is supposed to go to a ttl-232 usb interface. And I have almost finished a pcb layout for it, although the multiplexing is not making a pretty layout very easy. Hopefully this schematic is completely correct now.
Looks good but I think we still need at least one extra set of experienced eyes to look over the design. Anyone?
A simplification to consider: is 16MHz speed or precise timing required for this design? I doubt it, in which case you could ditch the crystal & caps and use the internal 8MHz clock. That would free up 2 more pins, not that they seem to be needed!
Its great that you have pcb layout nearly complete, but to me that feels like running before you can walk. I'm never that confident. I always prototype on breadboard first. You will need quite a few breadboards clipped together for this one! I like to start with my nano 3.0 on the breadboard, then later substitute a bare atmega328 (either with bootloader, or load up arduinoISP on the nano and use that to program the atmega).
Well the 16mhz crystal and two caps are really not in my way atm. And well I have worked on a layout for each iteration of the schematics you see here. Just for practice purposes, this is my first layout work using eagle after all.
But I will breadboard parts of the schematic tonight to see if it works, since I guess I have all parts now, except the 2x16 LCD which got delayed.
All good then, barring any advice to the contrary from other forum members?
Looking forward to seeing something working when you have it.
In terms of the sketch, I think I would start with a simple loop to perform the multiplexing, just getting all leds lit simultaneously to begin with. Check for acceptable levels of brightness and flickering. Then move on to indiviual control of the leds, trying out a few pre-determined or random patterns. After that, build in the key-scanning, echoing the switch statuses back to the PC. Obviously leave the lcd stuff until that arrives! Then finally add the actual game code. In other words don't try to code it all at once and then struggle to de-bug it, but I'm sure you know that.
I am running into a problem, how can you use 'digitalread' if a switch is being pressed when all pins are set to pinmode'ouput'? Is this possible using a workaround? Or should I build a seperate 3x4 matrix for the switches alone?