Introduction: Arduino Attiny85 Charlieplexing


It's rainning leds...

Last week I saw in a shop a curious thing: a small microcontroller like Attiny85 (8 pins) controlling 20 leds with a rain effect!!

An impossible thing working with the famous Charlieplexing algorithm.

Step 1: A Bit of Theory

The schematic of the raining leds is based on geometric figures: the polygons. Each vertices are controlled by one digital pin of a microcontroller and the edges are made of LED mounted paralell and inverted. So for 5 pins, you control 5 vertices and 10 edges of 2 leds each: 20 leds. A wiki article deals with the polygons:

To control each LED you have to polarize the LED you want to light on (+ on a vertice anode and - on the vertice kathod) and apply high impedance on the other vertices.

I use an attiny 85 programmed with the arduino sketch. So it uses 5 pins for 20 leds. If you want more: 6 pins for 30 leds, 7 pins for 42 leds, 8 for 56 leds...use an atmega328p/644p/1284p.

So each led, one by one (D1 to D20) are switched on and the fade off every four leds to give a rain effect with a random cycle. You can see it in the truth table i tried to make.

Step 2: The Schematic

5 pins are used for the 5 vertices, 2 pins for the power supply and 1 pin for the Charlie plexing algorithm. Respect the number of the led to make the circuit (D1 to D20).

Step 3: Programming the Attiny85 (8MHz Internal Clock): Burn the Bootloader

You need first to upload the sketch arduino in this microcontroller.

1- connect arduino uno to your PC

2- launch arduino UNO

3- select the good com port

4- file/example/arduino as ISP

5- download it to arduino uno

6- Download the “ATtiny” folder from this GitHub repository:

- In your Arduino sketchbook folder create a new sub-folder called “hardware”

- Put the “ATtiny” folder inside this “hardware” folder

- You should end up with folder structure like this: “Documents > Arduino > hardware > attiny”

- Quit and restart the Arduino software
- Look inside the “Tools > board” menu and you should see the ATtiny entries

7- Wiring your ISP connection
ATtiny —– Arduino

Pin PB2 (SCK) —– Pin 13

Pin PB1 (MISO) —– Pin 12

Pin PB0 (MOSI) —– Pin 11

Pin PB5 (Reset) —– Pin 10

Plus (VCC) —– +5V

Minus (GND) —– GND

10uF Capcitor: not necessary

Arduino pins: RESET —-||—- GND

8- Burn Bootloader:

- Select “ATtiny85 (8 MHz internal clock)” from the “Tools > Board” menu

- Select “Arduino as ISP“ from the “Tools > Programmer” menu

- Select “Burn Bootloader” from the “Tools” menu

9- if this message is displayed your Attiny85 can be programmed now with aduino sketch.

Here, a good website:

Step 4: The Charlieplexing Program

You need to download the library entropy.h supplied here.

The Charlieplexing program is here:

You've got all you need to work your 20 leds rain effect!!!

It's rainning leds!!!

In the program:

- HIGH state with: pinMode(pin,OUTPUT); digitalWrite(pin, HIGH);

- LOW state with: pinMode(pin,OUTPUT); digitalWrite(pin, LOW);

- high impedance Z state with: pinMode(pin,INPUT);

Step 5: Conclusion

Thanx for all interesting and working tutorials on the net.