Controlling Multiple WS2811 LED's with IR Remote - Limited LEDs Work

Getting back into Arduino after years of a break. Attempting a rather ambitious project utilizing 462 WS2811 LED's. I have gotten the IR remote to control the LEDs with limited success. I have a few issues to tackle, however the first being something I suspect to be rather simple. I am able to use the remote up to 341 LEDs, anything over that amount the remote will not trigger the commands. I am able to utilize all 462 using example sketches, however not with the IR Remote sketch. There are 6 tabs, i included the define tab as thats the only thing i am changing. However i can post the rest if needed!

//Define Tab
#include <MyRGBcolors.h>            //  My RGB color library for WS2812b strip
//#include <MyGRBcolors.h>          //  My GRB color library for WS2811 strip

//#include "./Libraries/MyRGBcolors.h"//  My color library for RGB WS2812b strip
//#include "./libraries/MyGRBcolors.h"//  My color library for GRB WS2812b strip


#include <Adafruit_NeoPixel.h>      //  Library for WS2811/WS2812b Led strips
#include "IRremote.h"               //  Library for IR Remote

#define IR_Receiver           4    //  Pin 1 of IR receiver to Arduino digital Pin 11
#define LED_PIN               6    //  Data Pin of Led strip
#define LED_COUNT             341    //  Number of LEDs in your strip
//#define StatusLed_PIN       13    //  [OPTIONAL] Pin of the status Led
#define SPEED                 20    //  Speed of each Color Transition (in ms)
#define NOW                    0    //  Transition happen instantly
#define RAINBOW_SPEED         10    //  Rainbow Transition speed
#define RAINBOW_REPEAT         1    //  How many times the Rainbow Cycle is repeated
#define BRIGHTNESS            55    //  Initial Brightness
#define BRIGHTNESS_INCREMENT  50    //  Increase/Decrease Brightness by this value
#define MIN_BRIGHTNESS         5    //  Minimum Brightness
#define MAX_BRIGHTNESS       255    //  Maximum Brightness

int currentBrightness;              //  This will save the current Brightness
int buttonPushCounterA    =    0;   //  Counts how many times the button has been pushed
int buttonStateA          =    0;   //  Current state of the button
int lastButtonStateA      =    0;   //  Previous state of the button

//  Initialize Led Strip
Adafruit_NeoPixel strip = Adafruit_NeoPixel(LED_COUNT, LED_PIN, NEO_GRB + NEO_KHZ800);

//  Initialize IR Receiver
IRrecv irrecv(IR_Receiver);         //  create instance of 'irrecv'
decode_results results;             //  create instance of 'decode_results'

You didn't say what microcontroller you are using. You need 3 bytes for each LED. You might just be out of memory.

My apologies, it is an Arduino Uno. I assumed it would work since it runs perfectly on Example sketches provided. How maybe my logic is incorrect.

The examples work as is. Your program involves a lot more code and variables and you only have 2kB of SRAM (Arduino Uno with ATmega328).

How much dynamic memory does the IDE report after compiling. Seeing that you're using the Adafruit Neopixel library, add three bytes for every pixel (or subtract it from the free space).

A further problem can be that updating 462 pixels takes time; during that time interrupts are disabled and that might result in corrupt IR codes or no IR codes being received.

1 Like

You may be onto something here. I may play around with the code and cut some of the variables out.

Here are the results. Its 1386 bytes just for the LED controls. So adding that to the Global variables puts me at 2268. So am starting to think you are right about the interrupts. If my calculations are right, strictly from a memory stand point i should be able to control closer to 387 LEDs.

Sketch uses 12718 bytes (39%) of program storage space. Maximum is 32256 bytes.
Global variables use 882 bytes (43%) of dynamic memory, leaving 1166 bytes for local variables. Maximum is 2048 bytes.

It's not the interrupts (yet), it's your available RAM (dynamic memory).

You might be able to optimise your sketch to make more dynamic memory available but if you will be able to get it down to around 1600 bytes (safe area) is debatable.

Show your sketch if you want people to advise on that.

Sorry for the delay, life and work took over for a bit. In the mean while I rewrote the code to be super basic just to test things out. I eliminated all animations and have only 4 commands programmed. All of which work perfectly with limited LED's however when I up the amount the code stops responding.

#include <Adafruit_NeoPixel.h>
#include <IRLibAll.h>
#ifdef __AVR__
 #include <avr/power.h> // Required for 16 MHz Adafruit Trinket
#endif

#define LED_PIN    6
#define NUMPIXELS 200
IRrecv myReceiver(2);//receiver on pin 2
IRdecode myDecoder;//Decoder object

Adafruit_NeoPixel strip(NUMPIXELS, LED_PIN, NEO_GRB + NEO_KHZ800);

uint32_t red = strip.Color(255, 0, 0);
uint32_t green = strip.Color(0, 255, 0);
uint32_t blue = strip.Color(0, 0, 255);

void setup() {
  #if defined(__AVR_ATtiny85__) && (F_CPU == 16000000)
  clock_prescale_set(clock_div_1);
#endif
  strip.begin();
  strip.show(); // Initialize all pixels to 'off'
  strip.setBrightness(50);
  myReceiver.enableIRIn(); // Start the receiver
}

void loop() {
  if (myReceiver.getResults()) {
    myDecoder.decode();
    if (myDecoder.protocolNum == NEC) {
      switch(myDecoder.value) {
        case 0xF710EF:  //Volume Down
          strip.fill(red,0);//Red
          break;
        case 0xF730CF:  //Play/Pause
          strip.fill(green,0,NUMPIXELS);//Green
          break;
        case 0xF708F7:  //Volume Up
          strip.fill(blue,0,NUMPIXELS);//Blue
          break;
        case 0xF7807F: //Reset
          strip.clear();
          break;
      }
    strip.show();
    myReceiver.enableIRIn(); //Restart the receiver
    }
  }
}
Sketch uses 13360 bytes (41%) of program storage space. Maximum is 32256 bytes.
Global variables use 974 bytes (47%) of dynamic memory, leaving 1074 bytes for local variables. Maximum is 2048 bytes.

Add 200 neopixels and you're at approx. 1600 bytes which is kind-of a safe limit. Use 341 neopixels and you're close to the maximum which will not leave much space for function calls and ISRs to work properly; that is the cause of your problem.

Ok thank you for confirming! I will look into a new board!

Picked up the Mega 2560 and worked immediately. Solution marked.

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