Jump to content
43oh

Free* 16x32 LED Matrix - Help me adapt Arduino library


Recommended Posts

Well, not exactly free, I need your help.  But I am willing to buy a 16X32 LED matrix from SparkFun https://www.sparkfun.com/products/12583 or AdaFruit https://www.adafruit.com/products/420 [shipping included] for someone who can help me adapt the Arduino library to my Tiva C Connected Launchpad with the 120 MHz TM4C1294NCPDT processor, and make a couple of enhancements.  It's already been adapted to the BeagleBone, Teensy, and Raspberry Pi.

 

I'm not a noob, but I'm not advanced either, somewhere in between.  I have already studied the library and identified the issues.

  1) It writes directly to the ports.  I'm not sure if I can get away with simply changing the names.  Lines 45-79.

  2) It is pretty timing critical, and the Launchpad is sooooo much faster than the Arduino.  On an Arduino it eats most of the clock cycles just to keep a decent refresh rate.  I want to keep the refresh rate about the same, maybe a little faster, and keep most of the Tiva processor cycles free for other things.

  3) It uses a timer, and I don't understand them quite well enough to adapt it.  Lines 179-184.

  4) It uses a tiny amount of inline assembler code for the AVR processor in a speed-critical section.  Looks really simple, just some OUTs.  Lines 534-543.

 

Enhancements I wanna make:

  1) Multiple panels can be daisy-chained.  I want to use just 2 of the 32x32 (Total display 64X32, 14" x 7").  Just need to clock out more bits serially before toggling the latch pin.  I could probably figure this one out myself.  With the Tiva's speed and memory, someone else might conceivably want to daisy-chain more than 2.

  2) It already supports double-buffering, but I would like to have 2 (or more) sets of buffers (pages) with different things drawn on them, and be able to switch between them.  Yes, I realize this will use a lot of memory.  This will probably require changes to the Adafruit_GFX library.  Ultimately, I would like a fade function between 2 pages instead of just a hard switch.

 

I suspect a good coder could knock this out fairly quickly.  Any takers?  You can find the library on GitHub here: https://github.com/adafruit/RGB-matrix-Panel

 

FYI, ultimately this will end up on my Astrolabe/Clock/Calendar project.

 

 

Link to post
Share on other sites

Oooh, blinkenlights.

 

Looks pretty straightforward.  I would be willing to give it a go.

To start with I would do the assembly language part in C, only drop to assembly if not fast enough.

(I have done assembly language programming on various processors, but "premature optimization is the root of all evil")

 

Doesn't look like timer is anything fancy, just gives consistent refresh rate.  (I have messed with timers a bit doing the eLua port).

 

On the fade function - do you want to just do a linear interpolation through rgb space, or do you want to get fancy and allow possibility of doing it in various color spaces (e.g. hsv)?

Link to post
Share on other sites

To start with I would do the assembly language part in C, only drop to assembly if not fast enough.

(I have done assembly language programming on various processors, but "premature optimization is the root of all evil")

The assembly, as I mentioned, is just a bunch of OUTs.  Apparently from the memory buffer to the port, if I am reading it correctly.

Doesn't look like timer is anything fancy, just gives consistent refresh rate.  (I have messed with timers a bit doing the eLua port).

Yup!  precisely.

On the fade function - do you want to just do a linear interpolation through rgb space, or do you want to get fancy and allow possibility of doing it in various color spaces (e.g. hsv)?

Just a basic fade from Page A to Page B.  I'm thinking kinda like a PWM, where first it displays page A for 9 milliseconds and page B for 1, then 8 and 2, 7 and 3, 6 and 4... etc. until page B is being shown 100% of the time.  Once the fade is complete, I can redraw the [non-displayed] page A in memory.  It keeps displaying the page B until I invoke a command to fade it back to the page A.  Displays that until I tell it to go back to page B.  Etc.  Fade speed should be configurable.

Primarily, I want to do cross-fading of the digits for the clock, like this: https://www.youtube.com/watch?v=O-VBEMgtUMw but also, when switching between pages of other information, so it's not so jarring on the eyes and brain.  I've already implemented the crossfade on an Arduino clock with a LED 7-segment numeric display and it looks really slick!  In fact, I wrote a nifty little algorithm so instead of being like a straight pwm, it more evenly distributes the 2 pages.  Its makes a visible difference for slow refresh rates but it needs some optimizing for a microcontroller though, the math eats too many clock cycles on an Arduino  (and thus causing a slow refresh rate.  Catch-22).  The TM4C1294 has floating point support built into hardware, so it should run much better on it, I haven't tried it there yet.

static bool crossFade(float pct, uint16_t tick)
{

  bool state = false;

  if (pct <= 0)
  {
    state = false;
  }
  else if (pct >= 1)
  {
    state = true;
  }
  else
  {
    float howManyTrue = maxTicks * pct;                 // How many of the ticks should be true
    float spacing = (float)maxTicks / howManyTrue;                      // Percentage of the total each tick is
    float steps = (float)tick / (float)howManyTrue;               // Approx amount of ticks for each true
    float x1 = (float)tick / spacing;
    float x2 = x1 - (uint8_t)x1;
    float dv = 1 / spacing;
    if (x2 < dv)
    {
      state = true;   // display 2nd item
    }
    else
    {
      state = false;  // display 1st item
    }
  }
  return state;
}

So anyway, download the RGB-matrix library if you haven't already and look at it, and the issues, and if you are still interested in tackling it, send me a private message and we will take this conversation offline for now.  That goes for anyone else interested as well.  And of course, we will post the updated library here and share it for anyone who wants to use one of these panels in the future.

Link to post
Share on other sites
  • 2 months later...

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...