CharliePlexing on a ATTINY10

by WilkoL in Circuits > Microcontrollers

1397 Views, 3 Favorites, 0 Comments

CharliePlexing on a ATTINY10

wheel_or_dice.JPG

This mini project combines a two things I had never done before. The first is CharliePlexing, the second is making (a kind of) die. In the 1980's and maybe even later, making electronic dice was pretty popular. I have seen them in the magazine Elektor and no doubt they appeared in other magazine such as Nuts and Volts too. Although I was a beginner with electronics at that time and those projects were clearly aimed at beginners I never made one. Now, after several decades I have :-)

The other thing, CharliePlexing I hadn't tried either, I knew it existed and I knew how it works but there never was a reason to use it. Now there was.

Code is now available on GitLab:

https://gitlab.com/WilkoL/charlieplexing-on-a-attiny10

Supplies

ATTINY10

Resistors 5 x 1kohm, 1 x 10kohm and 1 x 1Mohm (smd 0805)

Capacitor 100n (smd 0805)

2032 battery holder (plus battery)

Momentary button

PCB

ATTINY10s Are Small

attiny10_microcontrollers_are_small.JPG

For another project I had bought a few ATTINY10 microcontrollers, and they really are tiny! A 9V block battery next to it looks like a towering skyscraper. But they are still big enough that I can hand-solder them. (When I buy parts I always buy more than I need, I do break parts. My "Wall-Of-Shame" contains too many parts where the "Magic-Smoke" has escaped from.)

So I had some spare ATTINY10 microcontrollers and the idea of making a dice. An electronic dice needs seven dots, three on either side and one in the middle. The microcontroller has six pins, but you can use just three of them, VCC and GND are needed to power it and /RESET can only be used if you can program it with a programmer that supplies 12V to this pin during the programming session. I do not have a programmer (yet) that can do that. So I just had those three pins.

CharliePlexing to the Rescue

1280px-3-pin_Charlieplexing_with_common_resistors.svg.png
schematic.JPG

With CharliePlexing and three pins you can control just six leds, one short for a die! But with six leds you can show the numbers 1 to 6 by nummering them and lighting just one of them. That's how this die works. Or maybe I should call it a "Small Wheel-of-Fortune"?

But wait! We also need a button to start it, so we are still one pin short.

This is fixed by relying on the speed of a microcontroller, one pin is switched from output to input several times a second for a very short time, human eyes are too slow to notice that.

More shortages and randomness

The ATTINY10 isn't just tiny in size and number of pins, it also has a tiny flash memory (1 KByte) and even smaller amount of ram (32 Bytes) A program that uses a (pseudo) random generator would probably not fit in this microcontroller. So I chose to use the randomness of the time the button is pressed, as long as it is pressed the microcontroller rotates through the numbers 1 to 6, and thus the led that is switched on. When you release the button the rotation slows down for a few seconds and stops at a random number, just like a small "Wheel-of-Fortune".

Power and LEDS

cr2032.jpg
IMG_5201.JPG

Electronic die / wheel-of-fortune need to be small and work on a battery, but not an AA or a 9V block battery, those are way too big. A CR2032 button battery has a nice format. That meant that the pcb had to be big enough for a CR2032 battery holder. The first design I made was 30 x 30 mm but I decided that it could be smaller and made one of a square inch (2.54 x 2.54 mm), hello Hackaday :-). Usually I do not design a pcb at all, but making something this small with perfboard and a microcontroller of this shape is too difficult, and the price of a pcb this size (if made in China) is so low, it costed me less than 7 euro to have 5 pcbs made and shipped.

The fact that it works on a CR2032 battery and that there is no power switch also means that the device needs to use as few electrons as possible and go into sleep mode when not used. As it is now it uses about 1 mA when in use and a few uA in sleep mode, so the battery will last long enough.

Using a 3V battery means that there is never more than those 3V for the leds, so blue and white leds will only work for a short time with a fresh battery (3.1V) A green and a red led need less voltage (I have measured between 1.8V and 2.4V). The green leds I have produce quite a lot of light with 1 mA, the red leds are a bit dimmer with that much current but still ok.

The Code and How to Flash the ATTINY10

atmel_studio.JPG
programming_5V.JPG
programming_done.JPG
progrramming_jig.JPG
wires_for_programming.JPG

To conserve energy the clock of the microcontroller is reduced to 1 MHz, unneccesary peripherals disabled and all ports set to inputs when in sleep mode. Every round of the main loop ( while(1) ) all ports are set to inputs for some 2 milli seconds and the state of the button is checked, after that the current selected number determines ( switch(number) ) which ports are set to outputs and which one of those ports will be high or low.
When timeout has reached 0 (after a few seconds) all ports are set to inputs again, but with pullup resistors and Pin-Change-Interrupt is enabled. In Power-Down-Mode the microcontroller only reacts to an external signal. When you press the button one input will change from high (with the pullup resistor) to low and this will wake the microcontroller.

PROGRAMMING
The leds, together with the 1k resistors place too much load on the programmer to succesfully program the ATTINY10. So solder the leds after programming and the battery holder last. Oh, programming the ATTINY10 works only when it is powered with 5V, it will not work on 3.3V.

Downloads

PCB

pcb_layout.JPG
3d_view.JPG

The pcb is designed in Kicad. I have selected 0805 size resistors and capacitors because that is the smallest size I can comfortably solder by hand. In Kicad you can choose to make all pads a bit bigger by selecting the "HandSolder" footprints. The battery holder is placed on the backside (of course), all other parts are on the topsize.
The way I solder the parts to the pcb is to put a little solder on one pad and then move the part to this pad and re-heat the solder when the part is in the right position, this works fine for the resistors, capacitors as well as the microcontroller. If I accidentally short some pins of the microcontroller it is fixed with some de-soldering braid.

I do not place the leds and the battery holder until I have programmed the microcontroller. The battery holder somewhat overlaps the programming pads (testpads) but that isn't too bad. But you cannot solder the leds when the holder is in place! While I had designed the pcb for 3mm leds, it turns out that 5mm leds also fit, but hey do they look huge!

Soldering Step by Step

one_pad_for_tiny10.JPG
one_pin_soldered-2.JPG
one_pad_for_R_C_soldered.JPG
R_C_one_side_soldered.JPG
R_C_both_sides_soldered-2.JPG
test_pads_for_programming.JPG
5mm_leds_placed_soldered.JPG
5mm_leds_are_huge.JPG

This is how I do it.

Videos

wheel-of-fortune / dice with green leds
wheel-of-fortune with red (5mm) leds