Arduino Forum

Forum 2005-2010 (read only) => General => Exhibition => Topic started by: alansmk on Jun 23, 2010, 07:24 am

Title: :) my first not-so-good persistence of vision
Post by: alansmk on Jun 23, 2010, 07:24 am
My first Arduino project: a classic persistence of vision display.

Definitely disappointed; it seems a lot worse than other ones i have seen people make. :(
but i think i will try again with another design. a clock perhaps.

any comment on my code? Is there another way to code POV?
it seems so.. laggy?
i read something about using interrupt, but i didn't exactly know how that works. I only have very basic C++/ arduino programming experience.

any advice would be appreciated!  :D

Quote
// 7 LED POV

// letter width
#define WIDTH 5

//library
const byte font [][WIDTH] =
{
 {0x7e, 0x09, 0x09, 0x09, 0x7e}, //A
 {0x7f, 0x49, 0x49, 0x49, 0x36}, //B
 {0x3e, 0x41, 0x41, 0x41, 0x22}, //C
 {0x7f, 0x41, 0x41, 0x22, 0x1c}, //D
 {0x7f, 0x49, 0x49, 0x49, 0x49}, //E
 {0x7f, 0x09, 0x09, 0x09, 0x09}, //F
 {0x7e, 0x41, 0x49, 0x49, 0x38}, //G
 {0x7f, 0x08, 0x08, 0x08, 0x7f}, //H
 {0x00, 0x41, 0x7f, 0x41, 0x00}, //I
 {0x30, 0x40, 0x41, 0x7f, 0x01}, //J
 {0x7f, 0x08, 0x14, 0x22, 0x41}, //K
 {0x7f, 0x40, 0x40, 0x40, 0x40}, //L
 {0x7f, 0x02, 0x04, 0x02, 0x7f}, //M
 {0x7f, 0x02, 0x0c, 0x10, 0x7f}, //N
 {0x3e, 0x41, 0x41, 0x41, 0x3e}, //O
 {0x1e, 0x21, 0x21, 0x21, 0x5e}, //Q
 {0x7f, 0x09, 0x19, 0x29, 0x46}, //R
 {0x26, 0x49, 0x49, 0x49, 0x32}, //S
 {0x01, 0x01, 0x7f, 0x01, 0x01}, //T
 {0x3f, 0x40, 0x40, 0x40, 0x3f}, //U
 {0x07, 0x38, 0x40, 0x38, 0x07}, //V
 {0x3f, 0x40, 0x3f, 0x40, 0x3f}, //W
 {0x63, 0x14, 0x08, 0x14, 0x63}, //X
 {0x07, 0x08, 0x70, 0x08, 0x07}, //Y
 {0x61, 0x51, 0x49, 0x45, 0x43} //Z  
};
 
void setup()
{  
 for (int k=0;k<=7;k++)
    pinMode(k,OUTPUT);
}


void display (char POVstring[])
{
 for (int i=(strlen(POVstring)-1); i>=0; i--)
   {  for (int j=(WIDTH-1); j>=0; j--)
       { PORTD = font[(int)POVstring-65][j]; delay(1); }
       PORTD = B00000000; delay(1);
   }
}

void loop()
{
if ( analogRead(5)==0 )
 { display("HELLO"); }
}


(http://sphotos.ak.fbcdn.net/hphotos-ak-ash2/hs066.ash2/36661_1296770829864_1548150120_30670870_2204062_n.jpg)
(http://sphotos.ak.fbcdn.net/hphotos-ak-ash2/hs066.ash2/36661_1296770789863_1548150120_30670869_3222711_n.jpg)
Title: Re: :) my first not-so-good persistence of vision
Post by: cr0sh on Jun 23, 2010, 07:54 am
First off, never be disappointed in something you have built or made, especially if you did the best job you could or know how. You should only be disappointed if you know you didn't try your best; and the only person who should worry about that is you. Be proud of your accomplishments, because they are for you and you only. Learn from your mistakes and progress, grow, and become better. What you have managed to do is beyond what 99% of the people on this planet can do, if only because they lack the experience, or more likely, the willingness to try (and potentially fail). You have tried and succeeded - REJOICE!

:)
Title: Re: :) my first not-so-good persistence of vision
Post by: alansmk on Jun 23, 2010, 12:45 pm
lol, not the kind of input i was looking for, but.. thanks!
Title: Re: :) my first not-so-good persistence of vision
Post by: drhex on Jun 23, 2010, 01:14 pm
delay() is rather imprecise around 1 millisecond, try using delayMicroseconds() instead.
What makes you think your POV is worse than others?
Title: Re: :) my first not-so-good persistence of vision
Post by: AWOL on Jun 23, 2010, 10:06 pm
Great work, and everything that cr0sh said.

My questions are,
1) what have you got on analogue pin 5?
2) what do you mean by "laggy"?
3) what is your rotational rate?

"analogRead" is much slower than "digitalRead"
Title: Re: :) my first not-so-good persistence of vision
Post by: Funky Diver on Jun 24, 2010, 12:09 am
That's coool  :D

Might have to have a bash at it myself!
Title: Re: :) my first not-so-good persistence of vision
Post by: raron on Jun 24, 2010, 05:51 am
I love it!
I especially like the simplicity of your sketch! Beautifully made, well done!:)

I'm also curious about the answers to AWOL's question.
Btw Is that a hall effect sensor I see bent down towards the center?

cr0sh: Wow. Well put! I might be using that as a quote some time :)
Title: Re: :) my first not-so-good persistence of vision
Post by: Tchnclfl on Jun 24, 2010, 06:05 am
Looks like it works fine to me, and the code truly is a beautiful work of art in its simplicity.

I love it.  I can't stop looking at it! :O
Title: Re: :) my first not-so-good persistence of vision
Post by: Jeremy1998 on Jun 24, 2010, 06:31 am
I better never hear you say this is bad again! This is way beyond anything I can do! This is genious by standards!  :)
Title: Re: :) my first not-so-good persistence of vision
Post by: raron on Jun 24, 2010, 06:37 am
In fact when I think about it, I can probably just about answer AWOL's question 3 from the look(s) of it:

"HELLO" seems to cover about 90 degrees of a circle, 5 letters 5 pixels wide + 4 one-pixel space between letters = 29 pixels, or 29 ms for 1/4 circle. Should be about 8.6 rotations/sec (or 517 RPM).

So display FPS is 8.6-ish Hz? I guess this is what you mean by "laggy"? IE Flicker. Probably, if you switch to micros() as suggested, and also decrease the time between pixel columns (and increase the speed, say at least 4-6 times as fast), you will get a more stable display.
Unless I'm mistaken.
Title: Re: :) my first not-so-good persistence of vision
Post by: alansmk on Jun 24, 2010, 02:44 pm
o, i didn't know there such a thing as Microsecond()
that changes a lot! awesome.

1.) yeah, analog 5 is a hall effect sensor. i didn't know digitalRead is faster.. i suppose i could try that  :D
2.)i guess laggy as in... it doesn't refresh very fast. hardly "persistence" of vision.
3.) i have no idea what the rotational rate is. i just strapped on a motor and let it spin. lol, i guess raron's guess on the speed is probably right on.

so i could get a more stable display (which was my problem) if i use Microsecond and increase the motor speed? okay, sounds like a easy fix!

wow, thanks for all the positivity / input, guys!
;D

Title: Re: :) my first not-so-good persistence of vision
Post by: lestofante on Jun 25, 2010, 10:57 pm
i think with some precomputed trigonometry you can also eliminate the letter deformation
Title: Re: :) my first not-so-good persistence of vision
Post by: mowcius on Jun 25, 2010, 11:33 pm
Quote
i think with some precomputed trigonometry you can also eliminate the letter deformation

Yes in theory but it would be much more difficult as at the moment, the line of LEDs is defined and lit accordingly. If they were all seperate then they would have to be individually controlled with different time scales etc.

The spaces would then be more stretched.

Personally I think it looks fine  ;)

It would look better with a larger disk so the letters are not so curved but it's not a massive issue  :)

Mowcius
Title: Re: :) my first not-so-good persistence of vision
Post by: 2MuchNFO on Jun 28, 2010, 01:14 pm
It is neat code like this that makes me realise I still have lots to learn.
I've been writing the same thing, from a completely different angle, with the letters defined as individual bits.  This is so much tidier.
I'll revisit my code and rewrite my excel font creation spreadsheet to output hex rather than binary.
Most of my issues with writing at the moment seem to relate back to knowing when you can and can't make use of different data types.

Many thanks for posting.
Title: Re: :) my first not-so-good persistence of vision
Post by: jfkreuter on Jun 28, 2010, 01:59 pm
Hey Alan,
I managed to get a somewhat bigger project done,  and the code for my project is longer...
But: I dont understand a bit of your (appearantly really nice) code! Can you maybe add some comments to the code so that other people can understand what its doing?
Greetings
                         Jan
Title: Re: :) my first not-so-good persistence of vision
Post by: alansmk on Jun 29, 2010, 02:33 pm
:D sure. i didn't realize people would like the codes so much; lol, i didn't think anything of it.

let me post some comment on the codes, hopefully it will be helpful to whoever want to try something similar  :)


Quote
// 7 LED POV

// letter width. since i have 7 LED, then each letter would look like a 7 x 5 matrix
#define WIDTH 5

//library, each letter stored in hex number instead of bit, five hex numbers make a letter; hence each hex number represent a column of a letter.

const byte font [][WIDTH] =
{
{0x7e, 0x09, 0x09, 0x09, 0x7e}, //A
{0x7f, 0x49, 0x49, 0x49, 0x36}, //B
{0x3e, 0x41, 0x41, 0x41, 0x22}, //C
{0x7f, 0x41, 0x41, 0x22, 0x1c}, //D
{0x7f, 0x49, 0x49, 0x49, 0x49}, //E
{0x7f, 0x09, 0x09, 0x09, 0x09}, //F
{0x7e, 0x41, 0x49, 0x49, 0x38}, //G
{0x7f, 0x08, 0x08, 0x08, 0x7f}, //H
{0x00, 0x41, 0x7f, 0x41, 0x00}, //I
{0x30, 0x40, 0x41, 0x7f, 0x01}, //J
{0x7f, 0x08, 0x14, 0x22, 0x41}, //K
{0x7f, 0x40, 0x40, 0x40, 0x40}, //L
{0x7f, 0x02, 0x04, 0x02, 0x7f}, //M
{0x7f, 0x02, 0x0c, 0x10, 0x7f}, //N
{0x3e, 0x41, 0x41, 0x41, 0x3e}, //O
{0x1e, 0x21, 0x21, 0x21, 0x5e}, //Q
{0x7f, 0x09, 0x19, 0x29, 0x46}, //R
{0x26, 0x49, 0x49, 0x49, 0x32}, //S
{0x01, 0x01, 0x7f, 0x01, 0x01}, //T
{0x3f, 0x40, 0x40, 0x40, 0x3f}, //U
{0x07, 0x38, 0x40, 0x38, 0x07}, //V
{0x3f, 0x40, 0x3f, 0x40, 0x3f}, //W
{0x63, 0x14, 0x08, 0x14, 0x63}, //X
{0x07, 0x08, 0x70, 0x08, 0x07}, //Y
{0x61, 0x51, 0x49, 0x45, 0x43} //Z  
};


//set up pin 0 - 7 as OUTPUT
void setup()
{  
for (int k=0;k<=7;k++)
   pinMode(k,OUTPUT);
}

//method of displaying the letters. displaying each column (one hex number) of the letter one by one through PORTD. then after a letter, it puts a space in between and move onto the next letter. until however long of the String you wish to display.
//each letter is first turned into ASCII integer, then minus 65. It would then be the row of the letter from the library above. (ex. A is 65 in ASCII, but row 0 in my library)
// furthermore, because of the way i made the hardware, it displays each letter starting from the back of the sentence, and each letter from the right most column.

void display (char POVstring[])
{
for (int i=(strlen(POVstring)-1); i>=0; i--)
  {  for (int j=(WIDTH-1); j>=0; j--)
      { PORTD = font[(int)POVstring-65][j]; delay(1); }
      PORTD = B00000000; delay(1);
  }
}

// you simply feed a string to display it. this code only allows capital letters. however, if you add characters or lowercases in the library above, it would also be able to display it. (but then it would minus a different number instead of 65 above)

void loop()
{
if ( analogRead(5)==0 )
{ display("HELLO"); }
}
Title: Re: :) my first not-so-good persistence of vision
Post by: pracas on Jun 29, 2010, 02:41 pm
impressive first project! well its not not-so-good. Its kick ass man! cheerup! love what you do(did) and do what you love!
Title: Re: :) my first not-so-good persistence of vision
Post by: AltairLabs on Dec 28, 2010, 02:38 am
Congrats Alan on your POV display, very nice indeed!

I am a newcomer to Arduino, a longtime occasional developer, and just now discovered your post.  Arduino and open source has got me dizzy with excitement and ideas, but I also carry a bit of guilt that I bought my first Arduino for a work-related project that cannot be openly shared.  

Your Arduino code for POV is so compact and wonderfully clean, with your permission I'd like to use your sketch to begin my next project for a color POV, not job related, and release the result as open source.  Is this ok with you?

Also did you ever try delayMicroseconds() and a faster motor speed?  Hope your excellent POV Display has brought you more feeling of satisfaction and accomplishment bkoz you sure do deserve it.
Title: Re: :) my first not-so-good persistence of vision
Post by: alansmk on Dec 28, 2010, 06:57 am
thanks! glad people are still coming across this.
you are welcome to use it anyway you like.

:) i made this first project long time ago, learned a lot more since then.

I can probably make this better if i ever re-do a simliar POV.
delayMicroseconds() is definitely needed, hm.
i also tried using TimerOne library and interrupts to keep counts in another POV. that worked out okay too.

and i also tried using just time counting using the example Blink Without Delay() and i personally don't like that too much.

have fun with arduino!
Title: Re: :) my first not-so-good persistence of vision
Post by: Simpson_Jr on Dec 28, 2010, 09:37 pm
Well, let me be the first to say it looks horrible  !
(ofcourse I'm lying, I just hate to have the same opinion as everyone else  ;) )

I've been thinking of making one too, maybe still will do one day.

Title: Re: :) my first not-so-good persistence of vision
Post by: retrolefty on Dec 28, 2010, 10:49 pm
Very nice.

By using PORTD commands associated with pins 0-6, you are limiting the sketch to 168/328 processors only as the 1280/2560 processors map different pins to different port letters. A simple comment at the top of the sketch will remind you (and other users) that they will have to change the wiring if used on  mega boards.

Lefty
Title: Re: :) my first not-so-good persistence of vision
Post by: liuzengqiang on Dec 29, 2010, 01:34 am
I have been having this question since I saw this post a while ago. How was power fed to the arduino and LEDs?
Title: Re: :) my first not-so-good persistence of vision
Post by: retrolefty on Dec 29, 2010, 01:40 am
Quote
I have been having this question since I saw this post a while ago. How was power fed to the arduino and LEDs?


What, you don't believe in spinning batteries?  ;D
Title: Re: :) my first not-so-good persistence of vision
Post by: jhonray on Jan 22, 2011, 04:31 pm
what a nice project. can you give a the schematic of this project?
Title: Re: :) my first not-so-good persistence of vision
Post by: jhonray on Jan 22, 2011, 04:39 pm
does this project have a sensors?