NerdKits - electronics education for a digital generation

You are not logged in. [log in]

NEW: Learning electronics? Ask your questions on the new Electronics Questions & Answers site hosted by CircuitLab.

Microcontroller Programming » Ideas for coding LED array streaming?

December 04, 2009
by Haprog
Haprog's Avatar

Any ideas for good ways to implement receiving streaming animation on the NerdKits LED array?

I thought I could start by modifying the do_scrolling_display() function for receiving individual LED on/off data.

Anyone done this?

December 04, 2009
by Rick_S
Rick_S's Avatar

I've made quite a few different effects with text on the array. Most of which is posted in the forum here. The ledarray_set function you'll find in your ledarray.c program sets individual led's.

If you come up with more interesting ways to use the display, please update us. New code helps us all learn.

Rick

December 04, 2009
by mcai8sh4
mcai8sh4's Avatar

Haprog : Sorry to repeat, but it's always better to post ideas here so everyone gets them.

For those who may be confused - Haprog and I have just had a quick chat on the IRC channel about this, so here's a plan.

A (potentially) simple idea would be to send 24 integers (between 0 - 5) and store them in the array la_data, then display, the get the next 'frame'.....

So using the basic idea of sending text - send a char, wait for 'send next char' thingy, send next char.... we just do the same, but with numbers. Those numbers are then stored in the array and it should work.

I have a hell of a schedule at present, but I'm going to do some simple tests when I get a bit of spare time to test this theory.

Rick : from reading (and really enjoying) you posts detailing your progression with the display - I think you'll know instantly if I'm going down the right path or not :)

Just my initial thought on the subject.

-Steve

December 04, 2009
by Rick_S
Rick_S's Avatar

I haven't tried messing with the main array directly. Right now my display is dedicated for the holiday. A direct manipulation of the array data was in my mind when I was thinking of shifting text on the display from the top down or bottom up as a whole word. Also some of the other suggestions I had for curtain wipes to display text or clear the screen would probably benefit from this type of updating.

I probably won't mess around with it much until after the holidays. I'm also going to look into the use of shift registers to control the column data. If this works, it could open the display to be much larger with less pins used on the controller.

New more interesting stuff will be coming (hopefully at least) if I can get it all going. I have bought some more LED's so who knows, maybe I'll get ambitious and build another display. :D

Rick

December 05, 2009
by Haprog
Haprog's Avatar

Rick: Sounds great. It would be awesome to be able to control more LEDs with less pins. Keep me updated about that. I would definitely want build a bigger LED display at some point or maybe use a few pins for something else on the same breadboard.

We should start a new thread on this if something comes up.

Actually I even figured out one way to increase the number of LEDs myself. Instead of using the 17 pins for 12 column and 5 row wires (12x5x2 = 120 LEDs) we could wire the LEDs as a grid of 9 column and 8 row wires to get an 18x8 display of 144 LEDs using the same 17 pins on the MCU. That's 24 LEDs more. We could then physically align the LEDs as a grid of 36x4, 24x6, 18x8, 16x9 or 12x12. Or if you don't mind wasting a few potential LEDs you can get a 28x5, 20x7, 14x10 or 13x11 grid. Though the physical wiring will require some planning as the row and column wires won't be going straight unless you do the 16x8 grid. And ofcourse this would also require a special addressing method in code to map the physical LED positions to the wired 9 column 8 row grid depending on how you wired the LEDs. This might be a bit too much trouble to go through for only 24 LEDs though.

December 05, 2009
by Rick_S
Rick_S's Avatar

Wow, it seems our minds are on similar tracks. I had thought of converting 2 column wires to rows creating a 7 x 10 or 140 led's. My main thought was making better looking fonts with the added pixel height. I hadn't really thought of trying to address them other than 7x10 though. To try to use some of the row pixels as column pixels seems a bit overwhelming to me. Keep in mind... While I'm a 44yr old electronics/computer nut who has played with electronics and computers since the early 80's, my main exposure to C has been just over the past couple of months since I purchased my NerdKit.

Sure, I dabbled a bit in C but never really got any farther than "Wow this is different". I'm just now starting to get my head around it to where it's starting to click.

It took me a good week of studying the code for the ledarray to understand it well enough to make the mods and add the functions I did. So believe me when I say this is a learning experience for me as well.

I know the NerdKits guys are looking into expansion of the array as well... so who knows what the future will bring...

December 05, 2009
by Haprog
Haprog's Avatar

I also thought I could at some point consider making a way bigger LED array controlled by more than one MCUs (or MCU + some other devices?). I don't actually know much about electronics yet though I'm trying to learn with my new NerdKit.

I might as well tell something about myself also. I'm a 22 year old computer science student at the University of Turku, Finland. I had my first personal HTML website around 1998 when I was about 11. About a year later I started programming as a hobby. First I programmed with Delphi (Object Pascal) for many years. I also started playing around with PHP+MySQL for the web around 2001 and have been doing those since then. I've tried simple things in many other languages. Lately I've also tried some Python and studied Java. I've also been working as a Software Designer making database applications for the web for some years now.

December 05, 2009
by Rick_S
Rick_S's Avatar

My main experiences in programming was with BASIC of the 80's (GW-Basic, Quick-Basic, Visual Basic for DOS). I looked at Pascal, and C But hadn't touched any of them until about a year ago when I discovered micro-controllers. I also discovered they could be programmed with my old friend (BASIC) through the BASCOM (basic compiler) for micro-controllers. I've messed around with that as well as various projects until I decided it's time to try a more advanced language again. Thus my interest in the NerdKit.

My hope was that through it I could finally begin to grasp C. Much to the dismay of my wife (due to the many hours I've spent), It's begun to click. I still have a VERY long way to go but I'm at least on the path.

One thing I can't seem to get my head around is how much I could seemingly program with the 4K limited demo of bascom vs C. I have several different micro-controllers. ATTiny2313's, ATMega8's, ATmega128, ATMega168's, and ATMega328p's. I have difficulty fitting what I think should be a simple program into a mega8. For instance the temperature program. I know I could program that in bascom and fit it whithin the 4K limitation of the demo. I can't seem to get C to compile it small enough to fit in the 8K the chip has??

Oh well, as I said, I have a LOT to learn.

As for you, it sounds like you are well on your way to a good and enjoyable career. Just remember, NEVER stop learning. It will keep you ahead of all competition!!

December 05, 2009
by Haprog
Haprog's Avatar

Just remember, NEVER stop learning. It will keep you ahead of all competition!!

Ofcourse. There are so many things one needs to know to become truely successful in this career. Different languages (markup, programming, modeling) and tools, version control systems (centralized and distributed), object oriented and agile methods, design principles and patterns, SQL and "NoSQL" databases, cloud platforms etc. And all relevant technologies and methods evolve continuously at a rapid pace. I'm trying to keep up with web development techniques by being subscribed to dozens of related RSS/Atom feeds (websites, blogs, YouTube channels) and following certain people and entities on Twitter. :)

December 05, 2009
by Haprog
Haprog's Avatar

I came up with a big idea. I started defining a new protocol for defining and streaming LED array animations (with minimalistic footprint bit-wise). (Or more generally binary array/matrix animations.)

The basic idea is that you can define command sequences that can be either streamed from PC or they can be stored on the MCU so you can have custom animation when the NerdKit isn't connected to a PC. The stored animations (command sequences) can be written (and read) through serial connection without reprogramming the MCU.

This is my plan so far:

There are three main modes:
- paused: don't edit la_data array (just shows whatever was on the LED array when mode was changed to paused)
- play command stream: receive commands from PC and execute them
- play stored animation: execute a stored command sequence and repeat until mode is changed
    (a mode change can be executed from a stored animation)

Current mode and stored animations are to be saved to PROGMEM (flash) or EEPROM for resuming operation on next bootup.

Each command is represented by an unsigned 8bit integer (one byte). This is the same as the command index on the list below.
The command parameters are divided to even bytes by curly brackets {}.
The number of bits used by a specific parameter is defined in square brackets [].

These commands define my Timed Binary Array Control Protocol (TBACP) :P

bit state commands:
-0 all_off()
    set all bits 0
-1 all_on()
    set all bits 1
-2 frame_invert()
    invert all bits (1->0, 0->1)
-3 frame_shift( {direction[2], default_state[1], amount[5]} )
    shift all bits in the matrix, discarding bits that are shifted out
    direction: 0=right, 1=up, 2=left, 3=down
    default_state: defines what bits are shifted in from the opposite direction
-4 frame_roll( {direction[2], amount[5]} )
    shift all bits in the matrix, rolling out-shifted bits back in from the opposite side
    direction: 0=right, 1=up, 2=left, 3=down
-5 toggle_one( {index[7]} )
    toggel the state of one bit (1->0, 0->1)
    index: bit index 0-119
-6 toggle_many( {amount[7]}, {index[7]}... )
    toggel the state of many bits (1->0, 0->1)
    amount: the number of bits to toggle
    index: bit index 0-119
-7 set_one( {index[7], on_off[1]} )
    set one bit to 1 or 0 depending on on_off
    index: bit index 0-119
    on_off: 1 or 0
-8 set_many( {amount[7], on_off[1]}, {index[7]}... )
    set a specified amount of bits to 1 or 0 depending on on_off
    amount: the number of bits to set (the number of index parameters)
    on_off: 1 or 0
    index: bit index 0-119
-9 set_all( {state[1]*8}*15 )
    set the state of all bits
    state: 15 bytes = 120 bits
        first byte defines the state of the first 8 bits of the first row.
        3 bytes per row.

control commands:
-10 set_interval( {interval[8]} )
    set frame interval for all subsequent updates
    interval[0-255]: 1-256 cs = 10-2560 ms
-11 sleep( {interval[8]} )
    set frame interval for next update only
    interval[0-255]: 1-256 cs = 10-2560 ms
-12 set_mode( {mode[8]} )
    modes:
        0: paused
        1: play command stream
        2: play stored animation 1
        3: play stored animation 2
        4: play stored animation 3
        ...
-13 hold_update( {command_count[8]} )
    by default, frame interval is applied after every bit state command.
    use hold_update() to execute multiple commands before updating the frame.
    command_count: how many following commands to execute before updating frame data.
-14 save_animation_begin( {index[8]} )
    index: which animation index to save to
-15 save_animation_end()
-16 load_animation( {index[8]} )
    request stored animation from MCU
    index: which animation index to load

I think this could be awesome but there's a lot of coding to do.

Any comments or ideas?
:)

Post a Reply

Please log in to post a reply.

Did you know that you can control multiple LEDs from one microcontroller output? Learn more...