Arduino Forum

Using Arduino => Project Guidance => Topic started by: daaf1984 on Dec 04, 2012, 07:14 pm

Title: 12 LED Charlieplexed Snowfall with AtTiny85
Post by: daaf1984 on Dec 04, 2012, 07:14 pm
Hello,

I only found one topic about this, but it's done with 20 ports.

What I want to do:
•Create a charlieplexed row of 12 LED's driven by a AtTiny85 chip (PWM).

What I have managed yet:
•Create a working charlieplexed row with some code found on the web
•create a working sketch with 4 (software)PWM pins.

What are my problems:
•Combine chalieplex and the 4 pins S-PWM
•Create an 'animation' of a shooting star/snowdrop with tail and a delayed end drop.
(like this video)

http://www.youtube.com/watch?v=sFrOMbQ4LXU (http://www.youtube.com/watch?v=sFrOMbQ4LXU)


This are the codes I found:

The falling animation (No Charlieplex)

Code: [Select]
void setup() {
    for (uint8_t pin=0; pin<5; ++pin) {
        pinMode(pin, OUTPUT);
    }
}

uint8_t brightness(const int8_t led, const int8_t pos) {   
    switch (abs(led-pos)) {
        case 0:     return 32;
        case 1:     return 16;
        case 2:     return 6;
        case 3:     return 2;
        default:    return 1;
    }
}

void pulse_width_modulation(const uint8_t pos) {
    for(uint8_t times=0; times<100; ++times) {
        for (uint8_t pass=0; pass<32; ++pass) {
            for (int8_t led=0; led<20; ++led) {
                digitalWrite(led, (brightness(led, pos) > pass));
            }
        }
    }
}

void loop() {
    static uint8_t pos=0;

    while(pos<12) {
        pulse_width_modulation(pos);
        ++pos;
    }
delay(1000);

   pos=0;
}


A code with PWM (no SPWM) Lighting one after an other

Code: [Select]
/*
* Arrays containing the pin numbers used in
* each charlieplexed matrix. In this case, both
* matrices are the same size, and this code will
* not work properly if this is not the case.
*/

int charlie1[4] = { 1, 2, 3, 4};
int numPins = sizeof(charlie1)/sizeof(int);
int dropLed = 0;


void setup() {
  // Set all pins to output-
  for(int i = 0; i < numPins; i++) {
    pinMode(charlie1[i], OUTPUT);
    pinMode(dropLed, OUTPUT);
  }
}





void fadeSingle(int pinArray[],
                int source, int sink,
                int dir, int del) {
  /*
   * Fade a single charlieplexed LED in or out.
   * pinArray[] = Array of PWM pin numbers
   * source = Index of the source pin in the array
   * sink = Index of the sink pin in the array
   * dir = Direction of fade. 0 = Down; 1 = Up.
   * del = Fade delay(microseconds)
   */
  // Set pin modes
  pinMode(pinArray[source], OUTPUT);
  pinMode(pinArray[sink], OUTPUT);

  // Set the sink pin to low straight away
  digitalWrite(pinArray[sink], LOW);

  // Find any other pins in the array, and disable them
  // by setting them to INPUT
  for(int pin = 0; pin < numPins; pin++) {
    if(pin != source && pin != sink) {
      pinMode(pinArray[pin], INPUT);
    }
  }

  // Now fade the source pin in or out
  if(dir > 0) {
    for(int fadeVal = 0; fadeVal < 256; fadeVal++) {
      analogWrite(pinArray[source], fadeVal);
      delayMicroseconds(del);
    }
  } else {
    for(int fadeVal = 255; fadeVal >= 0; fadeVal--) {
      analogWrite(pinArray[source], fadeVal);
      delayMicroseconds(del);
    }
  }
 
 
 
}


void loop() {
  // Fade through all permutation
  allPermsFade();
  //for (int i=0; i>255; i--);
//  analogWrite (dropLed, 255);
//  delay(1000);
//   // fade out from max to min in increments of 5 points:
//  for(int fadeValue = 255 ; fadeValue >= 0; fadeValue -=5) {
//    // sets the value (range from 0 to 255):
//    analogWrite(dropLed, fadeValue);         
//    // wait for 30 milliseconds to see the dimming effect   
//    delay(30);                           
//  }
//  delay(2000);
}



void allPermsFade() {
  /*
   * Loop through all permutations, fading
   * each in then out with a 2ms delay between
   * increments
   */
  for(int i = 0; i < numPins; i++) {
    for(int j = 0; j < numPins; j++) {
      if(i == j) {
        continue;
      }
      fadeSingle(charlie1, i, j, 1, 500);
      fadeSingle(charlie1, i, j, 0, 500);
    }
  }
}

Title: Re: 12 LED Charlieplexed Snowfall with AtTiny85
Post by: strykeroz on Jan 02, 2013, 03:12 pm
Hi,

I really liked the effect in that video and think it will be something worthy to add to the xmas lights display next year.  As per my PM I decided to take a crack at it.

Firstly I found that adding complexity like trying to implement a PWM over the top of charlieplexing on the ATTiny85 introduced flickering in the LEDs that were at lower brightness levels.  For that reason I simplified it to manipulating the duty cycle for each of the LEDs in the "tail" of the animation so they were on for fewer of the charlieplexing cycles.

This code uses 5 ATTiny pins, and drives an array of 20 LEDs.  It uses no additional libraries, and compiles to 1,786 bytes so it would be possible to use the ATTiny45 also.  I've only tested it at 8MHz.  I use the Arduino-Tiny cores.  The "snowflakes" are 5 LEDs long, with diminishing brightness in the tail, and the animation slows toward the bottom where they collapse into each other.  While I think this does a halfway okay approximation of what is in your video, it can be simply tweaked.  Apologies I have no way to video this, but hope you find it useful for adapting to your project.
Code: [Select]
/*
  ____ _                _ _            _           ____   ___                         
/ ___| |__   __ _ _ __| (_) ___ _ __ | | _____  _|___ \ / _ \ ___ _ __   _____      __
| |   | '_ \ / _` | '__| | |/ _ \ '_ \| |/ _ \ \/ / __) | | | / __| '_ \ / _ \ \ /\ / /
| |___| | | | (_| | |  | | |  __/ |_) | |  __/>  < / __/| |_| \__ \ | | | (_) \ V  V /
\____|_| |_|\__,_|_|  |_|_|\___| .__/|_|\___/_/\_\_____|\___/|___/_| |_|\___/ \_/\_/ 
                                |_|                                                   

Charlieplexing 20 LEDs using 5 ATTiny85 pins with fading by
varying the duty cycle of each LED in the 'tail'.

ATTiny85 connections
Leg  Function
1    Reset, no connection
2    D3 GREEN
3    D4 ORANGE
4    GND
5    D0 WHITE
6    D1 BLUE
7    D2 YELLOW
8    +5V

Tested on ATTiny85 running at 8MHz.
*/

// each block of 4 LEDs in the array is groupled by a common anode (+, long leg)
// for simplicity of wiring on breadboard, using a colour code
#define GREEN 0
#define ORANGE 1
#define WHITE 2
#define BLUE 3
#define YELLOW 4

const unsigned long displayTime = 80;         // milliseconds to spend at each focus LED in descent

// pin definitions {GREEN, ORANGE, WHITE, BLUE, YELLOW}
const int charliePin[5] = {
  3, 4, 0, 1, 2};

// Charlieplexed LED definitions (current flowing from-to pairs)
const int LED[20][2] = {
  {ORANGE, GREEN},                            // 0 (GREEN GROUP)
  {WHITE, GREEN},                             // 1
  {BLUE, GREEN},                              // 2
  {YELLOW, GREEN},                            // 3
  {GREEN, ORANGE},                            // 4 (ORANGE GROUP)
  {WHITE, ORANGE},                            // 5
  {BLUE, ORANGE},                             // 6
  {YELLOW, ORANGE},                           // 7
  {GREEN, WHITE},                             // 8 (WHITE GROUP)
  {ORANGE, WHITE},                            // 9
  {BLUE, WHITE},                              // 10
  {YELLOW, WHITE},                            // 11
  {GREEN, BLUE},                              // 12 (BLUE GROUP)
  {ORANGE, BLUE},                             // 13
  {WHITE, BLUE},                              // 14
  {YELLOW, BLUE},                             // 15
  {GREEN, YELLOW},                            // 16 (YELLOW GROUP)
  {ORANGE, YELLOW},                           // 17
  {WHITE, YELLOW},                            // 18
  {BLUE, YELLOW}                              // 19
};

// other
int current = 0;                              // LED in array with current focus
int previous = 0;                             // previous LED that was lit
unsigned long loopCount = 0;                  // used to determine duty cycle of each LED

void setup() {
  randomSeed(analogRead(0));
}

void loop() {
  loopCount=0;
  unsigned long timeNow = millis();
  while(millis()- timeNow < (displayTime+current*2)) {  // animation slows toward end
    loopCount++;
    if (current > 19) charlieON(19); else charlieON(current);
    // each member of tail has reduced duty cycle
    if(!(loopCount % 3)) if(current-1 >=0 && current-1 < 19) charlieON(current-1);
    if(!(loopCount % 6)) if(current-2 >=0 && current-2 < 19) charlieON(current-2);
    if(!(loopCount % 9)) if(current-3 >=0 && current-3 < 19) charlieON(current-3);
    if(!(loopCount % 12)) if(current-4 >=0 && current-4 < 19) charlieON(current-4);
  }

  current++;
  if(current==23) {                          // start over
    current = 0;
    charlieON(-1);                           // all off
    delay(random(3000));                     // after a short pause
  }
}

// --------------------------------------------------------------------------------
// turns on LED #thisLED.  Turns off all LEDs if the value passed is out of range
//
void charlieON(int thisLED) {
  // turn off previous (reduces overhead, only switch 2 pins rather than 5)
  pinMode(charliePin[LED[previous][0]], INPUT);
  pinMode(charliePin[LED[previous][1]], INPUT);
  // turn on the one that's in focus
  if(thisLED >= 0 && thisLED <= 19) {
    pinMode(charliePin[LED[thisLED][0]], OUTPUT);
    pinMode(charliePin[LED[thisLED][1]], OUTPUT);
    digitalWrite(charliePin[LED[thisLED][0]], LOW);
    digitalWrite(charliePin[LED[thisLED][1]], HIGH);
  }
  previous = thisLED;
}
Thanks for the inspiration, hope you find this useful.  For the BoM I used 20x blue 5mm LEDs, 5x 100 Ohm resistors, a 0.1uF capacitor for decoupling, the ATTiny85 and a nest of wires.

Cheers ! Geoff
Title: Re: 12 LED Charlieplexed Snowfall with AtTiny85
Post by: strykeroz on Jan 02, 2013, 11:59 pm
I started to construct a diagram in Fritzing to explain how the wiring for the above worked, but it soon became as covered in wire as the real thing.  So, attached is a diagram showing just the green and orange channels and I hope it's easy enough to extrapolate from there.

Each group of 4 LEDs shares a direct connection to one pin without a resistor, with the 4 anodes linked.  Then the other legs are connected via a resistor to the other colours in the sequence green, orange, white, blue, yellow (always in this order, but omitting of course the colour that the anodes are).

So the green group has green to the anodes, then the cathodes in left to right sequence are orange, white, blue & yellow.  The orange group has orange to the anodes, with green, white, blue & yellow to the cathodes left to right.  White group's cathodes are sequenced green, orange, blue & yellow; the blue group's cathodes go green, orange, white & yellow; and the yellow group's cathodes go green, orange, white & blue.

I found colour coding made setting out the breadboard very simple, but repetitive.  I started with the row of 20 LEDs, each with the flat side to the right.  Once constructed a simple sketch walking the LEDs down the array on the Uno was used to test it, then I moved the connections to the ATTiny85 on the breadboard.

HTH, Geoff

Title: Re: 12 LED Charlieplexed Snowfall with AtTiny85
Post by: daaf1984 on Jan 03, 2013, 09:25 am
Hi Geoff,

Wow, thanks for this new years gift :)

I will build it right away to test it.

But I think your fritzing scheme is not quite right...
I only see 2 resistors and only two lines are connected to the Attiny, but I think I will find out.

Ok, I'm gonna bring down my breadboard, LED's an my wires down and try it out.

Thanks!!

Dave
Title: Re: 12 LED Charlieplexed Snowfall with AtTiny85
Post by: daaf1984 on Jan 03, 2013, 09:43 am
Sorry, It was early...

I didn't read it very well. ;)

You just made 2 'lines'

Title: Re: 12 LED Charlieplexed Snowfall with AtTiny85
Post by: daaf1984 on Jan 03, 2013, 11:14 am
Hi,

IT WORKS! :D

Video:

http://www.youtube.com/watch?v=CQZCV_FX3-E (http://www.youtube.com/watch?v=CQZCV_FX3-E)

Speed = 30 in the video

Thank you SOOOOOOOO much!
I'm now trying to set a random speed... But I can't get it to work right now. But tonight I will try again. I have to go to work now...

Next step: Make a PCB and order tons of white-blue Leds ;)

Title: Re: 12 LED Charlieplexed Snowfall with AtTiny85
Post by: strykeroz on Jan 03, 2013, 03:22 pm
Hi Dave

Glad you liked it.  As my first taste of charlieplexing I have to admit this is already giving me ideas for new things to try.  I like your idea of randomising the speed too.  Still trying different effects here, and I'll have to try this with 5 RGB LEDs too.

Please update this thread when you get the PCBs.  

All the best with your project ! Geoff
Title: Re: 12 LED Charlieplexed Snowfall with AtTiny85
Post by: daaf1984 on Jan 04, 2013, 12:13 am
Hmm...

I'v noticed a problem...

After about 20-30 runs (falls)I have a 'bounce back' at the bottom.
I include the video here..

Do you have an idea or someone else?

http://www.youtube.com/watch?v=sVCDoIFEWkU (http://www.youtube.com/watch?v=sVCDoIFEWkU)

Thanks, Dave
Title: Re: 12 LED Charlieplexed Snowfall with AtTiny85
Post by: strykeroz on Jan 04, 2013, 12:42 am
Yes, I think I have an idea...might have cut one too many lines out of the code.  Will see if I can reproduce tonight, and send an update.

Edit: have been running mine here for 38mins so far with that problem not showing up.  I do sometimes see odd things from ATTiny projects where the power isn't decoupled - do you have a 0.1uF cap between VCC & GND on yours?  Also there are notes about charlieplexing that mention the current limiting resistors are critical to ensure stray LEDs don't light - did you use something other than the 100R that I used on my blue LEDs for your green array?
Title: Re: 12 LED Charlieplexed Snowfall with AtTiny85
Post by: strykeroz on Jan 04, 2013, 04:26 am
Hi Dave

That's roughly an hour and a half now running without that anomaly showing here.  I'll keep it going...

Geoff
Title: Re: 12 LED Charlieplexed Snowfall with AtTiny85
Post by: strykeroz on Jan 04, 2013, 04:45 am
Hi Dave,

Here's something you can try.  This is the extra line I took out as it didn't have a negative impact on my array, but it might be causing your issue.
Code: [Select]
/ --------------------------------------------------------------------------------
// turns on LED #thisLED.  Turns off all LEDs if the value passed is out of range
//
void charlieON(int thisLED) {
  // turn off previous (reduces overhead, only switch 2 pins rather than 5)
  digitalWrite(charliePin[LED[previous][1]], LOW);   // <-- ADD THIS LINE
  pinMode(charliePin[LED[previous][0]], INPUT);
  pinMode(charliePin[LED[previous][1]], INPUT);
  // turn on the one that's in focus
  if(thisLED >= 0 && thisLED <= 19) {
    pinMode(charliePin[LED[thisLED][0]], OUTPUT);
    pinMode(charliePin[LED[thisLED][1]], OUTPUT);
    digitalWrite(charliePin[LED[thisLED][0]], LOW);
    digitalWrite(charliePin[LED[thisLED][1]], HIGH);
  }
  previous = thisLED;
}
I suspect the reason you're seeing what you're seeing is that even though the pin that was previously set high is now in input mode, that would have it with the internal pull-up resistor on, so rather than being a true high impedance mode, it would have a small +ve signal.  If the LED and resistors are matched as they are for my blue array, there wouldn't be enough current to cause an issue but if the resistor value is slightly mismatched a signal would still get out enough to run an LED dimly.  Your video seems to show the LED being run as bright as the head of the animation so that's probably not the reason...but it's worth trying perhaps.

Let me know how you go
Geoff
Title: Re: 12 LED Charlieplexed Snowfall with AtTiny85
Post by: funkyguy4000 on Jan 04, 2013, 06:37 am
I was looking for this exact thing! Bump so I can receive updates!
Title: Re: 12 LED Charlieplexed Snowfall with AtTiny85
Post by: daaf1984 on Jan 04, 2013, 08:43 am
Hi Geoff,

First of all I think it's funny that you help me out from the other end of the world.
Thanks again!

I added the line and i'v made a static delay of 500mS, so it runs fast a high number of falls en let it run for 10 minutes now.
It still works! :D

So the extra line worked!

Thanks!!!

Dave
Title: Re: 12 LED Charlieplexed Snowfall with AtTiny85
Post by: strykeroz on Jan 04, 2013, 03:17 pm
Hi Dave

I'm glad that has you all sorted out now.

Shout out again when you have your project in a more permanent way - very much looking forward to seeing what you do with it.

Cheers ! Geoff
Title: Re: 12 LED Charlieplexed Snowfall with AtTiny85
Post by: daaf1984 on Jan 05, 2013, 11:11 am
Hi Geoff,

I thought the problem was solved, but it isn't...
But I think, I'v found the problem.

It's the Random function, and probably Randomseed (analogRead, 0);

0 is also used as D0 out. So I have to make a separate random generator.
Still have to find out, but there is a lot on the web about that.

If I skip the random function and just use 'delay' there is no problem.


I also added something:
The last led fading out, instead of just turning of.

I just fooled arround with the code and it doesn't make sence to me why its working, but is IS working.

Fist of all, add 'void fade' :

Code: [Select]
void fade (int thisLED){

    digitalWrite(charliePin[LED[10][1]], LOW);
    for(int fadeVal = 0; fadeVal< 255; fadeVal++) {
      analogWrite (charliePin [LED[19][0]],fadeVal);
      delay (2);
 
  }
}


Then add this line here:

Code: [Select]

  current++;
  if(current==23) {                          // start over
    fade(current-1);  // <----- ADD THIS LINE
    current = 0;
    charlieON(-1);                           // all off
    //delay(random(3000));              // after a short pause (commented this line temporary and used
delay(2000);                                 // delay instead
}




Greets, Davy

Title: Re: 12 LED Charlieplexed Snowfall with AtTiny85
Post by: strykeroz on Jan 05, 2013, 01:59 pm
Hi Dave,

I specifically made this turn that last LED off rather than fade it.  That is done by this line:
Code: [Select]
if (current > 19) charlieON(19); else charlieON(current);so rather than the focus LED which is the head of the animation going off the bottom, it stays at 19 until the animation is complete and the tail has collapsed into it.  If you want the head to keep going so the last LED fades, change that line to simply:
Code: [Select]
charlieON(current);
If you want the last LED to fade after the tail goes away, suggest you use the charlieplexing duty cycle to do that.  If the Analogwrite is working that is simply good fortune that the particular ATTiny pin referenced in the array at that point is one of the PWM pins.  That won't work the length of the array therefore since one of the 5 pins used for controlling the LEDs isn't PWM capable.

I'm surprised by your findings on the randomseed().  Analog pin 0 is actually leg 1 on the chip, which is disconnected.  My thoughts were that worst case, even if it always returned the same value as that seed it will still generate a pseudorandom sequence, though it will have a sequence that will repeat every run.  It isn't electrically connected to the LEDs so I need convincing it can be playing a part in flashing any lights.

I am not seeing your issue, as yet.  Will try to break it tomorrow and report back.

Geoff
Title: Re: 12 LED Charlieplexed Snowfall with AtTiny85
Post by: daaf1984 on Jan 05, 2013, 07:58 pm
Quote
I'm surprised by your findings on the randomseed().  Analog pin 0 is actually leg 1 on the chip, which is disconnected.  My thoughts were that worst case, even if it always returned the same value as that seed it will still generate a pseudorandom sequence, though it will have a sequence that will repeat every run.  It isn't electrically connected to the LEDs so I need convincing it can be playing a part in flashing any lights.


analog 0 in actually pin 5 on the Attiny... try it with the fade sketch. :)

I will try tomorrow the thing you said about the fading and also the random generator.
Title: Re: 12 LED Charlieplexed Snowfall with AtTiny85
Post by: strykeroz on Jan 06, 2013, 01:28 am
Sorry mate recheck the chart.  pin 5 is DIGITAL 0, see next to pin 1 it says it's D5 and A0, so digital 5 or analog 0.  Pin 5 is not an analog pin, but it's used for AREF.
Title: Re: 12 LED Charlieplexed Snowfall with AtTiny85
Post by: Coding Badly on Jan 06, 2013, 03:14 am
Code: [Select]
  randomSeed(analogRead(0));

Did you disable RESET?  If not the pin very likely always reads 1023 because of the internal pullup.

Assuming there is enough Flash available, this is a good way to initialize random...
http://arduino.cc/forum/index.php/topic,66206.msg537783.html#msg537783

If you want a truly random seed...
http://code.google.com/p/avr-hardware-random-number-generation/
Title: Re: 12 LED Charlieplexed Snowfall with AtTiny85
Post by: strykeroz on Jan 06, 2013, 04:06 am
Thanks cb.  I hadn't, but then wasn't too concerned if the sequence was repeating each run.  Will definitely check out the EEPROM and entropy methods for my Xmas lights tho.
Title: Re: 12 LED Charlieplexed Snowfall with AtTiny85
Post by: strykeroz on Jan 06, 2013, 03:40 pm
Hi Dave

Here's a modification, adding in the entropy library to give a random randomseed().  This has both a randomised delay between snowflakes, and a randomised speed of the drop.  I've also added a fade-out for the end after the tail collapses.
Code: [Select]
#include <Entropy.h>
// downloaded from http://code.google.com/p/avr-hardware-random-number-generation/

/*
   ____ _                _ _            _           ____   ___                         
  / ___| |__   __ _ _ __| (_) ___ _ __ | | _____  _|___ \ / _ \ ___ _ __   _____      __
| |   | '_ \ / _` | '__| | |/ _ \ '_ \| |/ _ \ \/ / __) | | | / __| '_ \ / _ \ \ /\ / /
| |___| | | | (_| | |  | | |  __/ |_) | |  __/>  < / __/| |_| \__ \ | | | (_) \ V  V /
  \____|_| |_|\__,_|_|  |_|_|\___| .__/|_|\___/_/\_\_____|\___/|___/_| |_|\___/ \_/\_/ 
                                 |_|                                                   

Charlieplexing 20 LEDs using 5 ATTiny85 pins with fading by
varying the duty cycle of each LED in the 'tail'.

ATTiny85 connections
Leg  Function
1    Reset, no connection
2    D3 GREEN
3    D4 ORANGE
4    GND
5    D0 WHITE
6    D1 BLUE
7    D2 YELLOW
8    +5V

Tested on ATTiny85 running at 8MHz.
*/

// each block of 4 LEDs in the array is groupled by a common anode (+, long leg)
// for simplicity of wiring on breadboard, using a colour code
#define GREEN 0
#define ORANGE 1
#define WHITE 2
#define BLUE 3
#define YELLOW 4

// pin definitions {GREEN, ORANGE, WHITE, BLUE, YELLOW}
const int charliePin[5] = {
  3, 4, 0, 1, 2};

// Charlieplexed LED definitions (current flowing from-to pairs)
const int LED[20][2] = {
  {
    ORANGE, GREEN      }
  ,                            // 0 (GREEN GROUP)
  {
    WHITE, GREEN      }
  ,                             // 1
  {
    BLUE, GREEN      }
  ,                              // 2
  {
    YELLOW, GREEN      }
  ,                            // 3
  {
    GREEN, ORANGE      }
  ,                            // 4 (ORANGE GROUP)
  {
    WHITE, ORANGE      }
  ,                            // 5
  {
    BLUE, ORANGE      }
  ,                             // 6
  {
    YELLOW, ORANGE      }
  ,                           // 7
  {
    GREEN, WHITE      }
  ,                             // 8 (WHITE GROUP)
  {
    ORANGE, WHITE      }
  ,                            // 9
  {
    BLUE, WHITE      }
  ,                              // 10
  {
    YELLOW, WHITE      }
  ,                            // 11
  {
    GREEN, BLUE      }
  ,                              // 12 (BLUE GROUP)
  {
    ORANGE, BLUE      }
  ,                             // 13
  {
    WHITE, BLUE      }
  ,                              // 14
  {
    YELLOW, BLUE      }
  ,                             // 15
  {
    GREEN, YELLOW      }
  ,                            // 16 (YELLOW GROUP)
  {
    ORANGE, YELLOW      }
  ,                           // 17
  {
    WHITE, YELLOW      }
  ,                            // 18
  {
    BLUE, YELLOW      }                              // 19
};

// other
int current = 0;                              // LED in array with current focus
int previous = 0;                             // previous LED that was lit

void setup() {
  Entropy.Initialize();
  randomSeed(Entropy.random());
}

void loop() {
  unsigned long loopCount = 0;                          // used to determine duty cycle of each LED
  unsigned long timeNow = millis();                     //
  unsigned long displayTime = 10 + random(90);          // milliseconds to spend at each focus LED in descent
  while(millis()- timeNow < (displayTime+current*2)) {  // animation slows toward end
    loopCount++;
    // the "snowflake" gets full duty cycle.  When it gets to the end, hold it at the end until the tail collapses
    if (current > 19) charlieON(19);
    else charlieON(current);
    // each member of tail has reduced duty cycle, and never get to the final position
    if(!(loopCount % 3)) if(current-1 >=0 && current-1 < 19) charlieON(current-1);
    if(!(loopCount % 6)) if(current-2 >=0 && current-2 < 19) charlieON(current-2);
    if(!(loopCount % 9)) if(current-3 >=0 && current-3 < 19) charlieON(current-3);
    if(!(loopCount % 12)) if(current-4 >=0 && current-4 < 19) charlieON(current-4);
  }

  current++;
  if(current==23) {                          // start over
    // now fade out the snowflake in that final position #19
    for(int dutyCycle = 3; dutyCycle <= 15; dutyCycle += 3) {
      loopCount = 0;
      timeNow = millis();
      while(millis() - timeNow < (displayTime+current*2)) { // fade out as slow as animation has achieved by now
        loopCount++;
        if(!(loopCount % dutyCycle)) charlieON(19);
        else charlieOFF(19);
      }
    }
    current = 0;
    charlieOFF(19);                          // turn off the remaining (possibly) lit LED
    delay(100 + random(3000));               // and then rinse, repeat...after a short pause
  }
}

// --------------------------------------------------------------------------------
// turns on LED #thisLED.  Turns off all LEDs if the value passed is out of range
//
void charlieON(int thisLED) {
  // turn off previous (reduces overhead, only switch 2 pins rather than 5)
  digitalWrite(charliePin[LED[previous][1]], LOW);   // ensure internal pull-ups aren't engaged on INPUT mode
  pinMode(charliePin[LED[previous][0]], INPUT);
  pinMode(charliePin[LED[previous][1]], INPUT);

  // turn on the one that's in focus
  if(thisLED >= 0 && thisLED <= 19) {
    pinMode(charliePin[LED[thisLED][0]], OUTPUT);
    pinMode(charliePin[LED[thisLED][1]], OUTPUT);
    digitalWrite(charliePin[LED[thisLED][0]], LOW);
    digitalWrite(charliePin[LED[thisLED][1]], HIGH);
  }
  previous = thisLED;
}

// --------------------------------------------------------------------------------
// turns off LED #thisLED. 
//
void charlieOFF(int thisLED) {
  digitalWrite(charliePin[LED[thisLED][1]], LOW);   // ensure internal pull-ups aren't engaged on INPUT mode
  pinMode(charliePin[LED[thisLED][0]], INPUT);
  pinMode(charliePin[LED[thisLED][1]], INPUT);
}
New compile size is 3,130 bytes which means we've still got plenty of space on the ATTiny85 if you wanted the display to do more.

Thanks again to Coding Badly for the random links.  I had to use one that was completely internal to the uC since we have no spare legs, and this method will ensure these snowflakes are far more effective where several are side by side.

Cheers ! Geoff
Title: Re: 12 LED Charlieplexed Snowfall with AtTiny85
Post by: daaf1984 on Jan 06, 2013, 05:45 pm
Ah, that was my mistake then...

But You have delivered beautiful work!!

I think I don't need to tweak it, but maybe I will finetune it.
The delay works great, but I like it faster, so I turned the random delay down to 20 ;)

I'm gonna work on a test PCB now and hope to fit it in a clear hose of tube.
I want to make 10 or more :)

Again, THANKS!!


Title: Re: 12 LED Charlieplexed Snowfall with AtTiny85
Post by: strykeroz on Jan 07, 2013, 02:23 pm
Hi Dave

Glad you've found it useful.  I have put this, and my take on a Larson scanner (Knight Rider's KITT) effect using the same 20-LED charlieplex array up on github.
https://github.com/strykeroz/ATTiny85-20-LED-KITT

Looking forward to seeing your next project update.

Cheers ! Geoff
Title: Re: 12 LED Charlieplexed Snowfall with AtTiny85
Post by: dtokez on Jan 07, 2013, 05:37 pm
I was wondering about a similar effect I had seen at a shopping centre over christmas. I think there were more LED's than 20 though and the motion looked extremely fluid. I will upload the video I took when I get home
Title: Re: 12 LED Charlieplexed Snowfall with AtTiny85
Post by: daaf1984 on Jan 07, 2013, 06:39 pm

I was wondering about a similar effect I had seen at a shopping centre over christmas. I think there were more LED's than 20 though and the motion looked extremely fluid. I will upload the video I took when I get home


This is possible if you use more pins:

Formula is Number of charlieplexed LED's = N * (N-1)


2 IO Ports allows 2 LEDs, LEDs = 2 * ( 2 - 1 )
3 IO Ports allows 6 LEDs, LEDs = 3 * ( 3 - 1 )
5 IO Ports allows 20 LEDs, LEDs = 5 * ( 5 - 1 )
6 IO Ports allows 30 LEDs, LEDs = 6 * ( 6 - 1 )
7 IO Ports allows 42 LEDs, LEDs = 7 * ( 7 - 1 )
8 IO Ports allows 56 LEDs, LEDs = 8 * ( 8 - 1 )
9 IO Ports allows 72 LEDs, LEDs = 9 * ( 9 - 1 )
10 IO Ports allows 90 LEDs, LEDs = 10 * ( 10 - 1 )
And so on...

Only restriction is you number of IO pins on your IC

Title: Re: 12 LED Charlieplexed Snowfall with AtTiny85
Post by: dtokez on Jan 08, 2013, 01:52 pm
Interesting. I don't understand how it works at the moment but I will have to look further into it!

Here is the short video I took of the ones I saw

https://dl.dropbox.com/u/33809233/Movie.mp4 (https://dl.dropbox.com/u/33809233/Movie.mp4)
Title: Re: 12 LED Charlieplexed Snowfall with AtTiny85
Post by: strykeroz on Jan 08, 2013, 02:27 pm
That effect looks awesome.  Since I still had the 20 LED array set up I had a play.  Here's a completely underwhelming 20 LED approximation...
Code: [Select]

// each block of 4 LEDs in the array is groupled by a common anode (+, long leg)
// for simplicity of wiring on breadboard, using a colour code
#define GREEN 0
#define ORANGE 1
#define WHITE 2
#define BLUE 3
#define YELLOW 4

// pin definitions {GREEN, ORANGE, WHITE, BLUE, YELLOW}
const int charliePin[5] = {
 3, 4, 0, 1, 2};

// Charlieplexed LED definitions (current flowing from-to pairs)
const int LED[20][2] = {
 {ORANGE, GREEN},                            // 0 (GREEN GROUP)
 {WHITE, GREEN},                             // 1
 {BLUE, GREEN},                              // 2
 {YELLOW, GREEN},                            // 3
 {GREEN, ORANGE},                            // 4 (ORANGE GROUP)
 {WHITE, ORANGE},                            // 5
 {BLUE, ORANGE},                             // 6
 {YELLOW, ORANGE},                           // 7
 {GREEN, WHITE},                             // 8 (WHITE GROUP)
 {ORANGE, WHITE},                            // 9
 {BLUE, WHITE},                              // 10
 {YELLOW, WHITE},                            // 11
 {GREEN, BLUE},                              // 12 (BLUE GROUP)
 {ORANGE, BLUE},                             // 13
 {WHITE, BLUE},                              // 14
 {YELLOW, BLUE},                             // 15
 {GREEN, YELLOW},                            // 16 (YELLOW GROUP)
 {ORANGE, YELLOW},                           // 17
 {WHITE, YELLOW},                            // 18
 {BLUE, YELLOW}                              // 19
};

// other
int current = 0;                              // LED in array with current focus
int previous = 0;                             // previous LED that was lit
const unsigned long displayTime = 15;         // milliseconds to spend at each focus LED in descent
const int lineLength = 10;                    // how many LEDs to light maximum


void setup() {
}

void loop() {
 unsigned long timeNow = millis();           //
 while(millis()- timeNow < displayTime) {    // animation slows toward end
   for(int thisLED = current; thisLED > current - lineLength; thisLED--) {
     if (thisLED >= 0 && thisLED <= 19) charlieON(thisLED);
   }
 }
 current++;
 if(current==19+lineLength) {               // start over
   current = 0;
   charlieOFF(19);                          // turn off the remaining (possibly) lit LED
   delay(1200);                             // and then rinse, repeat...after a short pause
 }
}

// --------------------------------------------------------------------------------
// turns on LED #thisLED.  Turns off all LEDs if the value passed is out of range
//
void charlieON(int thisLED) {
 // turn off previous (reduces overhead, only switch 2 pins rather than 5)
 digitalWrite(charliePin[LED[previous][1]], LOW);   // ensure internal pull-ups aren't engaged on INPUT mode
 pinMode(charliePin[LED[previous][0]], INPUT);
 pinMode(charliePin[LED[previous][1]], INPUT);

 // turn on the one that's in focus
 if(thisLED >= 0 && thisLED <= 19) {
   pinMode(charliePin[LED[thisLED][0]], OUTPUT);
   pinMode(charliePin[LED[thisLED][1]], OUTPUT);
   digitalWrite(charliePin[LED[thisLED][0]], LOW);
   digitalWrite(charliePin[LED[thisLED][1]], HIGH);
 }
 previous = thisLED;
}

// --------------------------------------------------------------------------------
// turns off LED #thisLED.  
//
void charlieOFF(int thisLED) {
 digitalWrite(charliePin[LED[thisLED][1]], LOW);   // ensure internal pull-ups aren't engaged on INPUT mode
 pinMode(charliePin[LED[thisLED][0]], INPUT);
 pinMode(charliePin[LED[thisLED][1]], INPUT);
}
It just moves a block of lineLength LEDs down the array repeatedly.  If nothing else it proves more than 20 LEDs and an ATTiny85 were used in your video :)

Geoff
Title: Re: 12 LED Charlieplexed Snowfall with AtTiny85
Post by: dtokez on Jan 08, 2013, 04:00 pm
Yeah I'm not sure how many LED's but I'd think maybe even almost 100?
Title: Re: 12 LED Charlieplexed Snowfall with AtTiny85
Post by: funkyguy4000 on Jan 16, 2013, 02:44 am
There any more progress on this?
Have you been able to run more than one string?
Title: Re: 12 LED Charlieplexed Snowfall with AtTiny85
Post by: strykeroz on Jan 16, 2013, 02:52 am
I've created a couple of these - one on a test rig and one permanently which became a KITT type Larsson scanner.  To run multiple strands I'll be putting an ATTiny85 at the top of each with Vcc and GND shared across them from a wall wart.  While they'll run independently, the slight randomisation in the speed and delay between falls should create a reasonable effect across the windows at the front of our house.

Measuring up the 4 windows I'll be running these in leads me to think I'll need 30 of them, so 600 white LEDs...the project is approved by the minister for finance and war so it's just a matter of sourcing the bits and dedicating the time.  I'm actually very happy I have a 10 month project window on delivering this one :)

Geoff

Title: Re: 12 LED Charlieplexed Snowfall with AtTiny85
Post by: funkyguy4000 on Jan 16, 2013, 06:41 am
Okay, so my suspicions were true. 
Just a side question: what ATtiny package do you use for permanent applications?  Do you use the PDIP, SOIC or the SSOP?
Title: Re: 12 LED Charlieplexed Snowfall with AtTiny85
Post by: strykeroz on Jan 16, 2013, 06:46 am
I still use socketed PDIP and program the uC via a shield using a Uno for my programmer.  I certainly have time up my sleeve to get boards made for this, but the requirement is so simple, and since I have some 1" square perfboards that will do the job splendidly, I doubt I'll bother.

Geoff
Title: Re: 12 LED Charlieplexed Snowfall with AtTiny85
Post by: daaf1984 on Jan 16, 2013, 08:30 am
I'm working on a PCB with SOIC and on board programming.

My width is now 12 mm and 29 cm length. I will make 20 of them. ;)

I will post when I finish the drawing.

Dave
Title: Re: 12 LED Charlieplexed Snowfall with AtTiny85
Post by: strykeroz on Jan 16, 2013, 08:45 am

I'm working on a PCB with SOIC and on board programming.

My width is now 12 mm and 29 cm length. I will make 20 of them. ;)

I will post when I finish the drawing.

Dave
Hi Dave

That being the case - I might be able to treble your order if that's okay.  I'll PM you, but I can see these being very handy so would be interested in grabbing 40, or at least getting 40 made if you'd prefer not to have to worry about logistics.

Cheers ! Geoff
Title: Re: 12 LED Charlieplexed Snowfall with AtTiny85
Post by: daaf1984 on Jan 25, 2013, 04:29 pm
Hello All,

I have done the prototype for the snowfall.
I've made a video of it. (at the bottom)
Note that I didn't trim the board to size.

I will also share the Fritzing file with all of you.
It's 2 layers and this is the part list:

• 1 ATTiny 45 @ 8Mhz (SMD SOIC)
• 1 100 nF capacitor (SMD 0805)
• 5 100 Ohm restistors (SMD 0805)
• 20 diffuse cold white LEDs 3mm
• JST-2 connector (optional)

I've broken out the ISP pins to the side of the board, so you clip a programmer clip on, or just solder wires to the pads and (re)program the ATTiny.



Have fun!

Fritzing Files:
Scheme: www.zwavelstokje.nl/Site/diversen/Charlie20SnowzijkantSO08-EIAJ-29cm_schema.jpg (http://www.zwavelstokje.nl/Site/diversen/Charlie20SnowzijkantSO08-EIAJ-29cm_schema.jpg)

.FZZ file: www.zwavelstokje.nl/Site/diversen/Charlie20SnowzijkantSO08-EIAJ-29cm.fzz (http://www.zwavelstokje.nl/Site/diversen/Charlie20SnowzijkantSO08-EIAJ-29cm.fzz)

http://www.youtube.com/watch?v=MDtojFW7IK0 (http://www.youtube.com/watch?v=MDtojFW7IK0)
Title: Re: 12 LED Charlieplexed Snowfall with AtTiny85
Post by: funkyguy4000 on Jan 25, 2013, 06:06 pm
Ohhh nice!

How long did it take you to make the board and put it together?
Title: Re: 12 LED Charlieplexed Snowfall with AtTiny85
Post by: daaf1984 on Jan 25, 2013, 07:30 pm

Ohhh nice!

How long did it take you to make the board and put it together?


From scratch: about 2 hours. But it was just to test.
I've ordered 30 PCBs in China today. White mask, black silk. :)

I will post when I have them.
Title: Re: 12 LED Charlieplexed Snowfall with AtTiny85
Post by: strykeroz on Jan 26, 2013, 11:47 am
I've been having quite a bit of fun with this ATTiny charlieplexing.  Aside from the KITT Larson scanner thing, most recently have made a little EMF detector (originally showcased here for Arduino (http://www.aaronalai.com/emf-detector))

With apologies for the lame iPad photo quality, here's that one constructed, and another take on the 20 LEDs, arranged in a square which runs a sketch that loops around changing direction every 0.5 to 5sec.

Dave thanks again for the original inspiration.
Geoff
Title: Re: 12 LED Charlieplexed Snowfall with AtTiny85
Post by: daaf1984 on Feb 08, 2013, 03:32 pm
The PCB's Arrived!
Title: Re: 12 LED Charlieplexed Snowfall with AtTiny85
Post by: daaf1984 on Feb 14, 2013, 11:19 am
I ran into some difficulties;

I made pads at the side of the board to program them as ISP.
When I designed it, I didn't mention the pitch, so the ended up useless...
Or I should solder 6 wires every time to each board.

So I googled and found this: http://hackaday.com/2010/11/18/build-your-own-soic-progamming-clip/ (http://hackaday.com/2010/11/18/build-your-own-soic-progamming-clip/)

So, now I've programmed them all before I solder them. Saves me a lot of time.

Later this week I will post the pictures of the results. ;)

Title: Re: 12 LED Charlieplexed Snowfall with AtTiny85
Post by: michaelsteinbach on Jun 03, 2013, 07:02 am
Strykeroz, I know this thread is sorta old-ish but I wanted to thank you for your Larson code.  I borrowed it and modified it for a 40-led circuit.
The 40 leds are my cars 3rd taillight.  I will program this to be a normal brakelight but when the car is stopped, they will start scanning back and forth.

Here's a video of my circuit in action.
http://www.youtube.com/watch?v=c_tHc5Vl_Gw (http://www.youtube.com/watch?v=c_tHc5Vl_Gw)

~Mike
Title: Re: 12 LED Charlieplexed Snowfall with AtTiny85
Post by: strykeroz on Jun 06, 2013, 01:53 am
Thanks for sharing Mike - that looks great.  Love the soundtrack too.  I'm pretty sure that high level tail light wouldn't pass a roadworthy here - but VERY pleased it's okay somewhere!

I'm overdue for an update here too I guess.  Since last posting I've had two versions of the circuitboard made up at Seeed.  The first was to prove that my new EagleCAD skills actually translated okay to the real world.  When it came back fine I've moved to the smaller 50x31mm board in the DP sick-of-beige (http://dangerousprototypes.com/docs/Sick_of_Beige_standard_PCB_sizes_v1.0) PCB size which is far more compact, and I added a footprint for a 2.1mm DC jack sharing the space of one of the two screw terminals.

The idea is these boards will daisy-chain together for power with the end board in a chain having a wall wart plugged in via the 2.1mm jack.  Each is standalone with a diode for polarity protection.  At the bottom are two groups of 0.1mm spaced terminals for the string of LEDs to connect to, via a row of holes for strain relief.  The larger hole at the top centre takes a curtain hook or ring, to hold it to a curtain rail on the inside of a window.

In the attached photos you'll see two of the boards populated along with the front and back view.  In the group shot the board at the upper right is the v0.1 first attempt for scale.

In coming weeks I'm going to make up these first 10 to get a look at how the massed effect appears.  Once that's done I'll be ordering a batch of 50 more in black to complete the job.  I'm not looking forward too much to soldering 1200 white LEDs...but it appears we do suffer for our art  XD

Will post a video of the effect when done,
Geoff
Title: Re: 12 LED Charlieplexed Snowfall with AtTiny85
Post by: Coding Badly on Jun 06, 2013, 02:54 am

Are the PCBs holes for the barrel jack the correct size?  They look huge.  Did you use the Adafruit Eagle library?
Title: Re: 12 LED Charlieplexed Snowfall with AtTiny85
Post by: strykeroz on Jun 06, 2013, 02:57 am

Are the PCBs holes for the barrel jack the correct size?  They look huge.  Did you use the Adafruit Eagle library?
They are huge.  That's one of the libraries I have installed so it's quite possible that's where the part came from.  I suspect from your observation that's a known issue?

It did work out okay though.
Geoff
Title: Re: 12 LED Charlieplexed Snowfall with AtTiny85
Post by: Coding Badly on Jun 06, 2013, 03:04 am
I suspect from your observation that's a known issue?


Well, it's known to me.  I have not found anyone else who has had problems.  I did create an issue for it on Github/adafruit.

Quote
It did work out okay though.


Yeah but having it the correct size (probably #) works so much better.  If you want, I can dig up my version which (hopefully #) is correct.


# I have not yet made up boards since correcting the footprint.
Title: Re: 12 LED Charlieplexed Snowfall with AtTiny85
Post by: strykeroz on Jun 06, 2013, 03:10 am

If you want, I can dig up my version which (hopefully #) is correct.

# I have not yet made up boards since correcting the footprint.
That would be great - thanks.  And happy to be the lab rat for sure.

Cheers ! Geoff
Title: Re: 12 LED Charlieplexed Snowfall with AtTiny85
Post by: Coding Badly on Jun 06, 2013, 05:52 am

I have no idea how to extract the one part so I'm attaching the entire library.

PJ-102A is the part number.  It's the Eagle Package for this...
http://www.digikey.com/product-detail/en/PJ-102A/CP-102A-ND/275425

I believe it is the same or very similar to the one you are using.
Title: Re: 12 LED Charlieplexed Snowfall with AtTiny85
Post by: daaf1984 on Jun 06, 2013, 09:28 am
Time flies....

I should have posted my version long time ago...
So I will do it right now ;)

Ik looks great Strykeroz! You did a great job.

Here are mine:

Measurements: 1x29 Cm
Used components:
• 1 ATTiny 45 @ 8Mhz (SMD SOIC)
• 1 100 nF capacitor (SMD 0805)
• 5 100 Ohm restistors (SMD 0805)
• 20 diffuse cold white LEDs 3mm
Title: Re: 12 LED Charlieplexed Snowfall with AtTiny85
Post by: daaf1984 on Jun 06, 2013, 09:30 am
I'd just took one that wasn't cleaned up...
You can see the flux around the solder.. ;)

Here an other picture:
Title: Re: 12 LED Charlieplexed Snowfall with AtTiny85
Post by: darrenmathews on Oct 26, 2013, 03:31 am
I just read this entire thread. I'm impressed, you guys do awesome work.

How can I get the pcb files to have my own made?
Title: Re: 12 LED Charlieplexed Snowfall with AtTiny85
Post by: strykeroz on Oct 26, 2013, 04:37 am
Hi,

Thanks for your interest.  I've not actually gone back to this project for several months - time flies - have a big box of LEDs sitting beside me here that needs to be assembled before December though  :)

How can I get the pcb files to have my own made?

I've just updated github (https://github.com/strykeroz/ATTiny85-20-LED-snowflakes) with the EagleCAD schematic and board as well as a zip file that can be sent to Seeed Studios (http://www.seeedstudio.com/depot/fusion-pcb-service-2-layers-p-835.html?cPath=70_71) (that's where I had mine made) without any further work.  Note this is still with the bigger pad Adafruit 2.1mm component discussed above and produces a board in the sick-of-beige 50x31mm (http://dangerousprototypes.com/docs/Sick_of_Beige_standard_PCB_sizes_v1.0) shape.

Not sure if Dave has published his somewhere as yet...

Cheers ! Geoff
Title: Re: 12 LED Charlieplexed Snowfall with AtTiny85
Post by: daaf1984 on Oct 28, 2013, 08:54 pm
Hi all,

Funny, here just the same, only finished 5 of them and still need something to weatherproof it. ;)

But I did posted my layout on the Fritzing site:
http://fritzing.org/projects/charlieplex-snowfallshooting-star-20-leds (http://fritzing.org/projects/charlieplex-snowfallshooting-star-20-leds)

Take a look at it and have fun with it!

Dave
Title: Re: 12 LED Charlieplexed Snowfall with AtTiny85
Post by: strykeroz on Oct 28, 2013, 09:49 pm

...and still need something to weatherproof it. ;)
Hi Dave

I've had some success with some test circuits embedding them in casting resin (here's a link to the brand I bought (http://www.recochem.com.au/index.php/products/consumer_products/fibreglass/item/diggers_casting_embedding_resin) but you're sure to have an equivalent local to you).  After several months the resin remains clear, and the circuit protected.  I can see some of the circuitry has changed colour due, I presume, to corrosion where I didn't get all the flux off. 

Overall I think that's a method I'll continue to use for weatherproofing LED circuits, and my results can only improve.

Cheers ! Geoff
Title: Re: 12 LED Charlieplexed Snowfall with AtTiny85
Post by: daaf1984 on Oct 29, 2013, 08:14 am
Hi,

That's a good idea!! I have clear resin here, so I will do a test run. :D

Did you made a mold or brushed it over?


Dave
Title: Re: 12 LED Charlieplexed Snowfall with AtTiny85
Post by: strykeroz on Oct 29, 2013, 09:10 am
Hi Dave, for my tests I actually used small circuits which fit nicely into icecube trays...so I had a mold that did the job just great. Maybe you could form a mold out of Sugru or similar for yours?

Geoff
Title: Re: 12 LED Charlieplexed Snowfall with AtTiny85
Post by: daaf1984 on Feb 23, 2014, 10:40 am
After some considerations, I decided to use clear tubing for weatherproofing.
Just seal the bottom and top with acrylic rod.

If something occurs, it's easier to re-solder, than using resin.