Neopixel strip in a non-regular grid

EL Wire/Tape/Panels, LEDs, pixels and strips, LCDs and TFTs, etc products from Adafruit

Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.
User avatar
jayconverse
 
Posts: 15
Joined: Tue Jul 02, 2013 7:49 pm

Neopixel strip in a non-regular grid

Post by jayconverse »

I've searched all around, I think this is something new..

I'm building a thing with neopixel strips in a grid, but the grid isn't a regular X by Y square matrix. The pixels will fill a circle. There are 9 strip segments, and from top to bottom the number of pixels on the strips are 8, 14, 16, 18, 18, 18, 16, 14, 8. Technically it's an 18X18 matrix, but the corners are "dead" pixels.

It's looking really good when I hand code the numbers from an Excel spreadsheet. I can do moving rows, columns, and diagonals, but it's really tedious to code. I'd love to use the Adafruit_NeoMatrix library, but it expects a square matrix.

I'm looking over the CPP and H files, but I don't see anything to adjust for this.

Any ideas?

User avatar
Disciple
 
Posts: 852
Joined: Tue Jan 06, 2015 8:13 pm

Re: Neopixel strip in a non-regular grid

Post by Disciple »

Hello. I'm a customer in a similar story using Pro Trinkets and Arduino Unos.
Good news. the Adafruit_NeoMatrix library has a tool for the job. It's the setRemapFunction(), and I've used it to manage some really non-rectangular layouts. I can point you to a somewhat unsophisticated example I shared in another thread. A more compact function using a bit of math should suit your disk shape well. (A picture of one of my irregular layouts appears here.) Best of success.

Hallelujah!
Disciple

User avatar
jayconverse
 
Posts: 15
Joined: Tue Jul 02, 2013 7:49 pm

Re: Neopixel strip in a non-regular grid

Post by jayconverse »

Thanks a million! That function did the trick, I've got "HELLO WORLD" scrolling now. My grid is wired differently than a standard grid where the columns always go in the same direction, but that only makes the remap function messier. And the letters are upside down for some reason, but I'll figure it out

Thanks again!

User avatar
jayconverse
 
Posts: 15
Joined: Tue Jul 02, 2013 7:49 pm

Re: Neopixel strip in a non-regular grid

Post by jayconverse »

I'm finally running. I have learned that when you have a setRemapFunction defined, some of the parameters to Adafruit_NeoMatrix are ignored.

For example, NEO_MATRIX_BOTTOM/TOP, NEO_MATRIX_LEFT/RIGHT, and even NEO_MATRIX_ZIGZAG/PROGRESSIVE are all ignored.

My circular grid starts on the bottom left, and zigzags to the top right. To make it work, I defined a simple array:

Code: Select all

const int16_t TubaGrid[] = {
-1,-1,-1,-1,-1,218,219,220,221,222,223,-1,-1,-1,-1,-1,
-1,-1,-1,217,216,215,214,213,212,211,210,209,208,-1,-1,-1,
-1,-1,196,197,198,199,200,201,202,203,204,205,206,207,-1,-1,
-1,195,194,193,192,191,190,189,188,187,186,185,184,183,182,-1,
-1,168,169,170,171,172,173,174,175,176,177,178,179,180,181,-1,
167,166,165,164,163,162,161,160,159,158,157,156,155,154,153,152,
136,137,138,139,140,141,142,143,144,145,146,147,148,149,150,151,
135,134,133,132,131,130,129,128,127,126,125,124,123,122,121,120,
104,105,106,107,108,109,110,111,112,113,114,115,116,117,118,119,
103,102,101,100,99,98,97,96,95,94,93,92,91,90,89,88,
72,73,74,75,76,77,78,79,80,81,82,83,84,85,86,87,
71,70,69,68,67,66,65,64,63,62,61,60,59,58,57,56,
-1,42,43,44,45,46,47,48,49,50,51,52,53,54,55,-1,
-1,41,40,39,38,37,36,35,34,33,32,31,30,29,28,-1,
-1,-1,16,17,18,19,20,21,22,23,24,25,26,27,-1,-1,
-1,-1,-1,15,14,13,12,11,10,9,8,7,6,-1,-1,-1,
-1,-1,-1,-1,-1,0,1,2,3,4,5,-1,-1,-1,-1,-1
};
Then my function is merely:

Code: Select all

uint16_t circleGrid(uint16_t x, uint16_t y) {

  y = y * 16 + x;  // Compute index number based on 16x17 matrix

return TubaGrid[y];
}
Here's the bench test: https://www.youtube.com/watch?v=WrsMPWDRSAk.

I can't wait to take my sousaphone out for tonight's walk!

User avatar
adafruit_support_bill
 
Posts: 88037
Joined: Sat Feb 07, 2009 10:11 am

Re: Neopixel strip in a non-regular grid

Post by adafruit_support_bill »

That's an awesome Sousaphone! I'm sure John Phillip would approve. ;)

Thanks for posting.

User avatar
jayconverse
 
Posts: 15
Joined: Tue Jul 02, 2013 7:49 pm

Re: Neopixel strip in a non-regular grid

Post by jayconverse »

Here's another test. I'm going to have so much fun after dark tonight!

https://www.youtube.com/watch?v=4Q4gZjiXNio

User avatar
3DPiper
 
Posts: 44
Joined: Thu Jan 07, 2016 11:43 pm

Re: Neopixel strip in a non-regular grid

Post by 3DPiper »

Jayconverse,

I have a similar project I would like to build: a neopixel strip in a round display to go inside our marching bass drum.
I would rather have it display an image/animation each time the bass drum is hit. Kind of like a playlist of images/gifs.
Your youtube videos are impressive, I'd love to see your sketch and maybe get some help getting my project going.

User avatar
jayconverse
 
Posts: 15
Joined: Tue Jul 02, 2013 7:49 pm

Re: Neopixel strip in a non-regular grid

Post by jayconverse »

This is a work in progress. It says "I {heart} USA". It's only one heart now, but I'm going to make it beat. The colors are off on the heart, too, I'll figure it out sooner or later.

Code: Select all

#include <Adafruit_NeoPixel.h>
#include <Adafruit_GFX.h>
#include <Adafruit_NeoMatrix.h>
#include <Fonts/FreeSansBold9pt7b.h>

#define PIN 6

Adafruit_NeoMatrix matrix = Adafruit_NeoMatrix(16, 17, PIN,0, NEO_GRB + NEO_KHZ800);

const uint32_t colors[] = { matrix.Color(255, 0, 0), matrix.Color(0, 255, 0), matrix.Color(0, 0, 255), matrix.Color(255, 255, 255) };

const uint32_t iRed = matrix.Color(255, 0, 0);
const uint32_t iGreen = matrix.Color(0, 255, 0);
const uint32_t iBlue = matrix.Color(0, 0, 255);
const uint32_t iWhite = matrix.Color(255, 255, 255);
const uint32_t iGold = matrix.Color(255, 215, 0);
const uint32_t iOrange = matrix.Color(255, 165, 0);
const uint32_t iOff = matrix.Color(0, 0, 0);

const uint16_t iHeart4[] = {35,47,48,49,66,65,64,63,62,76,77,78,79,80,81,82,99,98,97
,96,95,94,93,107,108,109,110,111,112,113,114,115
,132,131,130,129,128,127,126,125,124,139,140,141,142
,143,144,145,146,147,164,163,162,161,160,159,158
,157,156,171,172,173,175,176,177};

const uint16_t iHeart5[] = {21,36,35,34,46,47,48,49,50,67,66,65,64,63,62,61
,75,76,77,78,79,80,81,82,83,101,100,99,98,97,96,95,94,93,92,91,106,107,108,109
,110,111,112,113,114,115,116,133,132,131,130,129,128,127,126,125,124,123,138,139
,140,141,142,143,144,145,146,147,148,165,164,163,162,161,160,159,158,157,156
,155,170,171,172,173,174,175,176,177,178,192,191,190,188,187,186};

const uint16_t iHeart6[] = {11,20,21,22,37,36,35,34,33,45,46,47,48,49,50,51,68,67,66
 ,65,64,63,62,61,60,74,75,76,77,78,79,80,81,82,83,84,101,100,99,98,97,96,95,94,93,92
 ,91,105,106,107,108,109,110,111,112,113,114,115,116,117,134,133,132,131,130,129,128
,127,126,125,124,123,122,137,138,139,140,141,142,143,144,145,146,147,148,149,166,165
,164,163,162,161,160,159,158,157,156,155,154,168,169,170,171,172,173,174,175,176,177
,178,179,180,194,193,192,191,190,188,187,186,185,184,197,198,199,203,204,205};


const int16_t TubaGrid[] = {
-1,-1,-1,-1,-1,218,219,220,221,222,223,-1,-1,-1,-1,-1,
-1,-1,-1,217,216,215,214,213,212,211,210,209,208,-1,-1,-1,
-1,-1,196,197,198,199,200,201,202,203,204,205,206,207,-1,-1,
-1,195,194,193,192,191,190,189,188,187,186,185,184,183,182,-1,
-1,168,169,170,171,172,173,174,175,176,177,178,179,180,181,-1,
167,166,165,164,163,162,161,160,159,158,157,156,155,154,153,152,
136,137,138,139,140,141,142,143,144,145,146,147,148,149,150,151,
135,134,133,132,131,130,129,128,127,126,125,124,123,122,121,120,
104,105,106,107,108,109,110,111,112,113,114,115,116,117,118,119,
103,102,101,100,99,98,97,96,95,94,93,92,91,90,89,88,
72,73,74,75,76,77,78,79,80,81,82,83,84,85,86,87,
71,70,69,68,67,66,65,64,63,62,61,60,59,58,57,56,
-1,42,43,44,45,46,47,48,49,50,51,52,53,54,55,-1,
-1,41,40,39,38,37,36,35,34,33,32,31,30,29,28,-1,
-1,-1,16,17,18,19,20,21,22,23,24,25,26,27,-1,-1,
-1,-1,-1,15,14,13,12,11,10,9,8,7,6,-1,-1,-1,
-1,-1,-1,-1,-1,0,1,2,3,4,5,-1,-1,-1,-1,-1
};

void setup() {
  
  matrix.setFont(&FreeSansBold9pt7b);
  
  matrix.begin();
  matrix.setTextWrap(false);
  matrix.setBrightness(255);
  matrix.setTextColor(colors[0]);
  matrix.setRemapFunction(circleGrid);
}

void loop() {
 
  for(int pass = 0; pass<4; pass++)
  {
    DoLetter(colors[pass],750, "I",5);
    delay(250);
    DoHeart(colors[pass],750);
    delay(250);
    DoLetter(colors[pass],375, "U",2);
    delay(125);
    DoLetter(colors[pass],375, "S",2);
    delay(125);
    DoLetter(colors[pass],375, "A",2);
    delay(125);
    delay(500);
  }
}

void DoHeart(uint16_t iColor, int iDelay)
{
  matrix.fillScreen(0);
  matrix.show();
  for(int i=0;i<65;i++)
  {
      matrix.setPixelColor(iHeart4[i],iColor);
  }
  matrix.show();
  delay(iDelay);
  matrix.fillScreen(0);
  matrix.show();
  return;
}

void DoLetter(uint16_t iColor, int iDelay, String sLetter, int iCursor)
{
  matrix.setFont(&FreeSansBold9pt7b);
  matrix.fillScreen(0);
  matrix.setCursor(iCursor, 14);
  matrix.setTextColor(iColor);
  matrix.print(sLetter);
  matrix.show();
  delay(iDelay);
  matrix.fillScreen(0);
  matrix.show();
  return;
}


void DoText(uint16_t iColor, int iDelay)
{
  matrix.setFont(&FreeSansBold9pt7b);
  for(int x=0;x > -90;x--)
  {
    matrix.fillScreen(0);
    matrix.setCursor(x, 14);
    matrix.print(F("  Fairfax!"));
    matrix.setTextColor(iColor);
    matrix.show();
    delay(iDelay);
  }
  matrix.fillScreen(0);
  matrix.show();
  return;
}

void DoCircles(uint16_t iColor, int iRepeat, int iDelay1, int iDelay2)
{
  matrix.fillScreen(0);
  for(int j=0;j<iRepeat;j++)
  {
    for(int i=1;i<12;i++)
    {
      matrix.fillScreen(0);
      matrix.drawCircle(8,8,i,iColor);
      matrix.drawCircle(8,8,i-1,iColor);
      matrix.show();
      delay(iDelay1);
    }
    //delay(iDelay2);
    for(int i=9;i>=0;i--)
    {
      matrix.fillScreen(0);
      matrix.drawCircle(8,8,i,iColor);
      matrix.drawCircle(8,8,i+1,iColor);
      matrix.show();
      delay(iDelay1);
    }
    matrix.fillScreen(0);
    matrix.show();
    delay(iDelay2);
  }
  
  return;
}

// Brute force address conversion, XY to live pixels
uint16_t circleGrid(uint16_t x, uint16_t y) {

  y = y * 16 + x;  // Compute index number based on 16x17 matrix

return TubaGrid[y];

}

User avatar
jayconverse
 
Posts: 15
Joined: Tue Jul 02, 2013 7:49 pm

Re: Neopixel strip in a non-regular grid

Post by jayconverse »


User avatar
Disciple
 
Posts: 852
Joined: Tue Jan 06, 2015 8:13 pm

Re: Neopixel strip in a non-regular grid

Post by Disciple »

Fun! (c:

Now I'm imagining several marching in a row, with synchronized displays triggered by the RF key fob.
How about using dental floss or something to tie your strips together in a support web, to keep them straight and even? Just a thought.

Hallelujah!
Disciple

User avatar
jayconverse
 
Posts: 15
Joined: Tue Jul 02, 2013 7:49 pm

Re: Neopixel strip in a non-regular grid

Post by jayconverse »

Good ideas! FWIW, this was a bench test. When I attach the outer ring to the bell, there's a black wooden dowel that runs underneath the center line. The dowel is bowed up under tension, which keeps the rows straight and tight

User avatar
jayconverse
 
Posts: 15
Joined: Tue Jul 02, 2013 7:49 pm

Re: Neopixel strip in a non-regular grid

Post by jayconverse »


User avatar
adafruit_support_bill
 
Posts: 88037
Joined: Sat Feb 07, 2009 10:11 am

Re: Neopixel strip in a non-regular grid

Post by adafruit_support_bill »

That's awesome! Thanks for the video. :)

User avatar
jayconverse
 
Posts: 15
Joined: Tue Jul 02, 2013 7:49 pm

Re: Neopixel strip in a non-regular grid

Post by jayconverse »

Even better is last night on my walk, I realized that with 3 other matrices that are rotations of the first, I can make my animations go left, right, up, or down with the same code, just by swapping between them.

User avatar
jayconverse
 
Posts: 15
Joined: Tue Jul 02, 2013 7:49 pm

Re: Neopixel strip in a non-regular grid

Post by jayconverse »


Locked
Please be positive and constructive with your questions and comments.

Return to “Glowy things (LCD, LED, TFT, EL) purchased at Adafruit”