Sunday, October 31, 2010
Encoder DRO Madness
I bought 4 digit, 7 segment LED displays from sparkfun, along with two shiny new Ardunio Unos.
What you're seeing here is one of each, all wired up and ready to play with.
It took a little while to get the display working properly, because there are so many pins to control, and so few to control them with.
All of the segments are run in parallel (for example, the top horizontal segment on each of the four digits is connected together, like wise for the upper-right/vertical segments for each of the four digits, and so on). But each digit has it's own power pin, so essentially what you have to do is write your letter/number, turn the first digit on, turn the first digit off, write the second letter/number, turn the second digit on, turn the second digit off, etc... and do it very fast.
This worked great, except it was too fast :P all of my digits blurred on all of the segments. So I added a 100 ms delay after each on, but before the off. This was a bit too slow, the digits were now displayed properly, but flashing serially. I trimmed the delay to 10 ms and everything was honkey dorey.
Well, displaying a static number was kinda neat and all, but relatively useless. So, I pulled out my ol'e encoder and dusted it off. Either through coincidence or through destiny there were exactly two pins open on the digital side of the Arduino, the exact amount needed to make the encoder work (per a previous post).
(towards the top of my working surface you're also seeing a flex sensor I got from spark fun too... however that's for another lame post - it seems that it needs an op-amp to work properly, and that's now on it's way in the mail).
It was a matter of merging the encoder and the 4 segment display codes, and like magicks, it worked (sorta).
The code is highly highly highly bloated, but it works... better than the Serial.Println() encoder version... which proves to me that the serial out was what was dragging the original encoder code down. There's a lot more work to do to get this thing in useable condition - right now it only displays positive counts (playing with the math should fix that), I'm not using a decimal currently (it seems it might actually get a little complicated compared to straight digits), and my encoder count is off (again, I think it's just in the math).
With some simple eye-ball testing, it seems to not be skipping any counts at roughly 60 rpm (1 turn in one sec). But it's noticeably off when I really twirl it fast. Not sure if it's due to the bloated code (about 375 lines in the Arduino!) or if it's the delay()'s. I'll keep playing and trim down the code greatly before I take out the delays (because I'm not sure how to separate the digits without them!).
But that's for another time, I've got to play Fable 3 now.
Labels:
CNC
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment