SK6812 LED strips with a total of 1118 LEDS using STM32F103C8

My project is a light table where I use SK6812 strips in a S pattern of 43 LEDs and 26 rows.

Trying to split the table up into 6 individual controlled groups.

My code works but it seems to lag a little. Takes about 20 seconds or so to light up each group.

Any ideas to speed it up.

#include "FastLED.h"
#include "FastLED_RGBW.h"

/* FastLED RGBW Example Sketch

Example sketch using FastLED for RGBW strips (SK6812). Includes
color wipes and rainbow pattern.

Written by David Madison
http://partsnotincluded.com

// Set Standard FastLED Color
leds[0] = CRGB::Red;

// Set Individual Colors
leds[0].r = 255;
leds[0].g = 128;
leds[0].b = 64;
leds[0].w = 32; // Specific to RGBW

leds[0] = CRGB(255, 128, 64);
leds[0] = CRGBW(255, 128, 64, 32);

// Set HSV Color
leds[0] = CHSV(hue, sat, val);
*/

#define NUM_LEDS 1118
#define NUM_LEDS_Groups 6
#define DATA_PIN PA8

CRGBW leds[NUM_LEDS];
CRGB *ledsRGB = (CRGB *) &leds[0];

int buttonPin1 = PA9;
int buttonPin2 = PA10;
int buttonPin3 = PB3;
volatile int buttonFlag;
int buttonDebounce = 50;
int previousPress = 0;

int NUM_LEDS_PerGrp[6][1] = {{182},{182},{195},{182},{182},{195}};

int grp[6][195] ={{0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13,
85, 84, 83, 82, 81, 80, 79, 78, 77, 76, 75, 74, 73, 72,
86, 87, 88, 89, 90, 91, 92, 93, 94, 95, 96, 97, 98, 99,
171,170,169,168,167,166,165,164,163,162,161,160,159,158,
172,173,174,175,176,177,178,179,180,181,182,183,184,185,
257,256,255,254,253,252,251,250,249,248,247,246,245,244,
258,259,260,261,262,263,264,265,266,267,268,269,270,271,
343,342,341,340,339,338,337,336,335,334,333,332,331,330,
344,345,346,347,348,349,350,351,352,353,354,355,356,357,
429,428,427,426,425,424,423,422,421,420,419,418,417,416,
430,431,432,433,434,435,436,437,438,439,440,441,442,443,
515,514,513,512,511,510,509,508,507,506,505,504,503,502,
516,517,518,519,520,521,522,523,524,525,526,527,528,529},//Group1
{14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27,
71, 70, 69, 68, 67, 66, 65, 64, 63, 62, 61, 60, 59, 58,
100,101,102,103,104,105,106,107,108,109,110,111,112,113,
157,156,155,154,153,152,151,150,149,148,147,146,145,144,
186,187,188,189,190,191,192,193,194,195,196,197,198,199,
243,242,241,240,239,238,237,236,235,234,233,232,231,230,
272,273,274,275,276,277,278,279,280,281,282,283,284,285,
329,328,327,326,325,324,323,322,321,320,319,318,317,316,
358,359,360,361,362,363,364,365,366,367,368,369,370,371,
415,414,413,412,411,410,409,408,407,406,405,404,403,402,
444,445,446,447,448,449,450,451,452,453,454,455,456,457,
501,500,499,498,497,496,495,494,493,492,491,490,489,488,
530,531,532,533,534,535,536,537,538,539,540,541,542,543},//Group2
{28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42,
57, 56, 55, 54, 53, 52, 51, 50, 49, 48, 47, 46, 45, 44, 43,
114,115,116,117,118,119,120,121,122,123,124,125,126,127,128,
143,142,141,140,139,138,137,136,135,134,133,132,131,130,129,
200,201,202,203,204,205,206,207,208,209,210,211,212,213,214,
229,228,227,226,225,224,223,222,221,220,219,218,217,216,215,
286,287,288,289,290,291,292,293,294,295,296,297,298,299,300,
315,314,313,312,311,310,309,308,307,306,305,304,303,302,301,
372,373,374,375,376,377,378,379,380,381,382,383,384,385,386,
401,400,399,398,397,396,395,394,393,392,391,390,389,388,387,
458,459,460,461,462,463,464,465,466,467,468,469,470,471,472,
487,486,485,484,483,482,481,480,479,478,477,476,475,474,473,
544,545,546,547,548,549,550,551,552,553,554,555,556,557,558},//Group3
{601, 600, 599, 598, 597, 596, 595, 594, 593, 592, 591, 590, 589, 588,
602, 603, 604, 605, 606, 607, 608, 609, 610, 611, 612, 613, 614, 615,
687, 686, 685, 684, 683, 682, 681, 680, 679, 678, 677, 676, 675, 674,
688, 689, 690, 691, 692, 693, 694, 695, 696, 697, 698, 699, 700, 701,
773, 772, 771, 770, 769, 768, 767, 766, 765, 764, 763, 762, 761, 760,
774, 775, 776, 777, 778, 779, 780, 781, 782, 783, 784, 785, 786, 787,
859, 858, 857, 856, 855, 854, 853, 852, 851, 850, 849, 848, 847, 846,
860, 861, 862, 863, 864, 865, 866, 867, 868, 869, 870, 871, 872, 873,
945, 944, 943, 942, 941, 940, 939, 938, 937, 936, 935, 934, 933, 932,
946, 947, 948, 949, 950, 951, 952, 953, 954, 955, 956, 957, 958, 959,
1031,1030,1029,1028,1027,1026,1025,1024,1023,1022,1021,1020,1019,1018,
1032,1033,1034,1035,1036,1037,1038,1039,1040,1041,1042,1043,1044,1045,
1117,1116,1115,1114,1113,1112,1111,1110,1109,1108,1107,1106,1105,1104},//Group4
{587, 586, 585, 584, 583, 582, 581, 580, 579, 578, 577, 576, 575, 574,
616, 617, 618, 619, 620, 621, 622, 623, 624, 625, 626, 627, 628, 629,
673, 672, 671, 670, 669, 668, 667, 666, 665, 664, 663, 662, 661, 660,
702, 703, 704, 705, 706, 707, 708, 709, 710, 711, 712, 713, 714, 715,
759, 758, 757, 756, 755, 754, 753, 752, 751, 750, 749, 748, 747, 746,
788, 789, 790, 791, 792, 793, 794, 795, 796, 797, 798, 799, 800, 801,
845, 844, 843, 842, 841, 840, 839, 838, 837, 836, 835, 834, 833, 832,
874, 875, 876, 877, 878, 879, 880, 881, 882, 883, 884, 885, 886, 887,
931, 930, 929, 928, 927, 926, 925, 924, 923, 922, 921, 920, 919, 918,
960, 961, 962, 963, 964, 965, 966, 967, 968, 969, 970, 971, 972, 973,
1017,1016,1015,1014,1013,1012,1011,1010,1009,1008,1007,1006,1005,1004,
1046,1047,1048,1049,1050,1051,1052,1053,1054,1055,1056,1057,1058,1059,
1103,1102,1101,1100,1099,1098,1097,1096,1095,1094,1093,1092,1091,1090},//Group5
{573, 572, 571, 570, 569, 568, 567, 566, 565, 564, 563, 562, 561, 560, 559,
630, 631, 632, 633, 634, 635, 636, 637, 638, 639, 640, 641, 642, 643, 644,
659, 658, 657, 656, 655, 654, 653, 652, 651, 650, 649, 648, 647, 646, 645,
716, 717, 718, 719, 720, 721, 722, 723, 724, 725, 726, 727, 728, 729, 730,
745, 744, 743, 742, 741, 740, 739, 738, 737, 736, 735, 734, 733, 732, 731,
802, 803, 804, 805, 806, 807, 808, 809, 810, 811, 812, 813, 814, 815, 816,
831, 830, 829, 828, 827, 826, 825, 824, 823, 822, 821, 820, 819, 818, 817,
888, 889, 890, 891, 892, 893, 894, 895, 896, 897, 898, 899, 900, 901, 902,
917, 916, 915, 914, 913, 912, 911, 910, 909, 908, 907, 906, 905, 904, 903,
974, 975, 976, 977, 978, 979, 980, 981, 982, 983, 984, 985, 986, 987, 988,
1003,1002,1001,1000,999, 998, 997, 996, 995, 994, 993, 992, 991, 990, 989,
1060,1061,1062,1063,1064,1065,1066,1067,1068,1069,1070,1071,1072,1073,1074,
1089,1088,1087,1086,1085,1084,1083,1082,1081,1080,1079,1078,1077,1076,1075}};//Group6

int currentGrpCondition[6][3] = {}; // Group row, Colour mode, Brightness Selector, Brightness Value
int groupSelector = 0;
int modeSelector = 0;
int brightnessSel = 0;
int StringBrightness = 0;
int brightness = 255;

void setup() {
FastLED.addLeds<SK6812, DATA_PIN, RGB>(ledsRGB, getRGBWsize(NUM_LEDS)).setCorrection(TypicalLEDStrip);
FastLED.setBrightness(brightness);
FastLED.show();
pinMode(buttonPin1, INPUT);
pinMode(buttonPin2, INPUT);
pinMode(buttonPin3, INPUT);
attachInterrupt(digitalPinToInterrupt(buttonPin1), button1_ISR, CHANGE);
attachInterrupt(digitalPinToInterrupt(buttonPin2), button2_ISR, CHANGE);
attachInterrupt(digitalPinToInterrupt(buttonPin3), button3_ISR, CHANGE);
delay(300);
}

void loop() {
//But1 Group Selector, But2 Colour Selector, But3 Brightness Selector
if (buttonFlag == 1){
if((millis() - previousPress) > buttonDebounce){
previousPress = millis();
groupSelector++;
if (groupSelector == NUM_LEDS_Groups) {groupSelector = 0;}
flashOnce();
}
buttonFlag = 0;
}

if (buttonFlag == 2) {
if((millis() - previousPress) > buttonDebounce){
previousPress = millis();
modeSelector = currentGrpCondition[groupSelector][0];
modeSelector++;
if (modeSelector == 6) {modeSelector = 0;}
currentGrpCondition[groupSelector][0] = modeSelector;
ColourModeSwitch ();
}
buttonFlag = 0;
}

if (buttonFlag == 3) {
if((millis() - previousPress) > buttonDebounce && buttonFlag){
previousPress = millis();
brightnessSel = currentGrpCondition[groupSelector][1];
brightnessSel++;
if (brightnessSel == 6) {brightnessSel = 0;}
BrightnessSwitch ();
}
buttonFlag = 0;
}
}

void button1_ISR(){
buttonFlag = 1;
}

void button2_ISR(){
buttonFlag = 2;
}

void button3_ISR(){
buttonFlag = 3;
}

void flashOnce() {
for (int i = 0; i < NUM_LEDS_PerGrp[groupSelector][0]; i++) {
leds[grp[groupSelector][i]] = CHSV(224, 255, 255);
FastLED.show();
}
delay(150);
modeSelector = currentGrpCondition[groupSelector][0];
ColourModeSwitch ();
}

void colorFill(int h, int s, int bright) {
for (int i = 0; i < NUM_LEDS_PerGrp[groupSelector][0]; i++) {
leds[grp[groupSelector][i]] = CHSV(h, s, bright);
FastLED.show();
}
}

void fillWhite() {
for (int i = 0; i < NUM_LEDS_PerGrp[groupSelector][0]; i++) {
leds[grp[groupSelector][i]] = CRGBW(0, 0, 0, currentGrpCondition[groupSelector][2]);
FastLED.show();
}
}

void rainbow() {
static uint8_t hue;

for (int i = 0; i < NUM_LEDS_PerGrp[groupSelector][0]; i++) {
leds[grp[groupSelector][i]] = CHSV((i * 256 / NUM_LEDS) + hue, 255, 255);
}
FastLED.show();
hue++;
}

void rainbowLoop() {
long millisIn = millis();
long loopTime = 5000; // 5 seconds

while (millis() < millisIn + loopTime) {
rainbow();
delay(5);
}
}

void BrightnessSwitch () {
switch (brightnessSel) {
case 0:
StringBrightness = 0;
break;
case 1:
StringBrightness = 32;
break;
case 2:
StringBrightness = 80;
break;
case 3:
StringBrightness = 120;
break;
case 4:
StringBrightness = 180;
break;
case 5:
StringBrightness = 255;
break;
}
currentGrpCondition[groupSelector][1] = brightnessSel;
currentGrpCondition[groupSelector][2] = StringBrightness;
modeSelector = currentGrpCondition[groupSelector][0];
ColourModeSwitch ();
}

void ColourModeSwitch () {
switch (modeSelector) {
case 0:
fillWhite(); //White
break;
case 1:
colorFill(0, 255, currentGrpCondition[groupSelector][2]); //Red
break;
case 2:
colorFill(96, 255, currentGrpCondition[groupSelector][2]); //Green
break;
case 3:
colorFill(160, 255, currentGrpCondition[groupSelector][2]); //Blue
break;
case 4:
colorFill(192, 255, currentGrpCondition[groupSelector][2]); //PartyMode
break;
case 5:
rainbowLoop();
break;
}
}

This thread should draw lots of comments.
That many LEDs is tough, but doable.
Check out:
NeoPixels Revealed: How to (not need to) generate precisely timed signals | josh.com;

and:
How many leds can a arduino uno control? - Using Arduino / Project Guidance - Arduino Forum

I'm not sure how much faster the stm32 is at bit-banging out the sequences either. Other will better make that comparison.

As far as I can see, for every LED you set, you do a call of FastLED.show(). This updates the complete display. Maybe you can reduce these call by moving it after the loop.

e.g.:

void flashOnce() {
for (int i = 0; i < NUM_LEDS_PerGrp[groupSelector][0]; i++) {
leds[grp[groupSelector][i]] = CHSV(224, 255, 255);
}
FastLED.show();
delay(150);
modeSelector = currentGrpCondition[groupSelector][0];
ColourModeSwitch ();
}
1 Like

You cannot bitbang it faster, you have to follow the preceise timing that the WS2812 requires. Faster CPU means faster busy-waiting.

You can split the matrix into separate segments and connect these to different pins. Now you dont have to update everything when you change only one LED which saves time.

I was making the point that there isn't a lot of gain by using a faster processor.

but even though we're saying something similar, I don't quite agree with you.
You have more flexibility with the timing than is spec'd. There are more than a couple people exploring it.

Please read the link I posted earlier. Especially since it actually solves OPs issue.

This is another great option.
GitHub - sonyhome/FAB_LED: Fast Arduino Bitbang LED library supports programmable LEDs (WS2812B, APA102...), color palettes for Arduino AVR

That worked perfectly, now its to fast. I'll be adding more debounce time and some delays. Thanks.

This topic was automatically closed 120 days after the last reply. New replies are no longer allowed.