SK6812 RGBW + IR + Nanopixel = problems !Solved!

Hi im new here ! :slight_smile:

i have some problems with my code.

i have googled it up that it is common with problems when using Adafruit_NeoPixel.h and IRremote.h

i want to controll a 25 pixel SK6812 RGBW led strip with a ir controller using Arduino Mini Pro.

the problem is that the arduino is only receiving the first signal and i heard that it has something to do with interrupts.

i post it here in hope for help and a possible solution.

sorry for messy code and some comments may be in swedish in the code. (Not full code maximum allowed length)

so again my question is. is there a possible solution to the Adafruit_NeoPixel.h and IRremote.h interrupts problem ?

the code works perfectly with FastLed but the problem is that fastled dont support RGBW

#include <boarddefs.h>
#include <IRremote.h>
#include <IRremoteInt.h>
#include <ir_Lego_PF_BitStreamEncoder.h>

// Initialize leds
#define NUM_LEDS 25
#define DATA_PIN 10

#include <Adafruit_NeoPixel.h>
Adafruit_NeoPixel strip = Adafruit_NeoPixel(NUM_LEDS, DATA_PIN, LED_TYPE + NEO_KHZ800);
  #include "FastLED.h"

int RECV_PIN = 1;        //Connect the receiver to pin
IRrecv irrecv(RECV_PIN);
decode_results results;  //decode

byte brightness = 175; //Styrka
int bStep = 8;

int loopMode =  0;

//#define MODE_OFF 0
#define MODE_SWYPE 2
#define MODE_RAINBOW 3

unsigned long lastShow = 0;
double vinkelHast = 1.0;
byte vinkel = 0;
int redColor = 0;
boolean swypeUp = false;
// Namn på olika färger (hex värdet är 0xWWRRGGBB)
// (strip.Color converterar från (r,g,b,w)till hex)
uint32_t magenta = 0xFF00FF;
uint32_t greenishwhite = strip.Color(0, 64, 0, 64);
uint32_t orange =  0xFF7F00;
uint32_t white = 0xFF000000;
uint32_t purple = 0xFF00FF;
uint32_t yellow = 0xFFB600;
uint32_t turkos = 0xFFFF00;

uint32_t currentColor = orange;

//random function variables
long randNumber1;
long randNumber2;
long randNumber3;

//brightness state
float brightnessState = 0;

void setup() {
  // put your setup code here, to run once:

  //FastLED.addLeds<WS2811, 10, GRB>(leds, NUM_LEDS).setCorrection( TypicalLEDStrip );
  //FastLED.addLeds<WS2811, 11, GRB>(leds, NUM_LEDS).setCorrection( TypicalLEDStrip );
  //FastLED.addLeds<TM1812, DATA_PIN>(leds, NUM_LEDS);

  strip.begin();; // Initialize all pixels to 'off'

  /*FastLED.addLeds<NEOPIXEL, 10>(leds, 0, NUM_LEDS_PER_STRIP);
    FastLED.addLeds<NEOPIXEL, 11, GRB>(leds, 0, NUM_LEDS_PER_STRIP);
    FastLED.addLeds<NEOPIXEL, 12>(leds, 0, NUM_LEDS_PER_STRIP);
    FastLED.addLeds<NEOPIXEL, 13>(leds, 0, NUM_LEDS_PER_STRIP);
  Serial.begin(9600);   // debuging
  irrecv.enableIRIn(); // Starting the receiver
  off();               // set all pixels off

void loop() {

  // Switch case, ir kontrol    case 0xFFXXXX XXXX = ir kod
  if (irrecv.decode(&results)) {
    switch (results.value)  { //när den får en signal från fjärren

      case 0xFF3AC5:  // brightness+
        if (brightness <= (255 - bStep)) //undvik overflow
          brightness += bStep;
          brightness = 255;

      case 0xFFBA45:  // brightness-
        if (brightness >= bStep)
          brightness -= bStep;

      case 0xFF827D:

      case 0xFF02FD:
        Serial.println("OFF"); //off
        loopMode = 0;

      case 0xFF1AE5:
        swypeUp = true;
        currentColor = 0xFF0000;
        loopMode = MODE_STATICCOLOR;

      case 0xFF9A65:
        swypeUp = true;
        currentColor = 0x00FF00;
        loopMode = MODE_STATICCOLOR;

      case 0xFFA25D:
        swypeUp = true;
        loopMode = MODE_STATICCOLOR;
        currentColor = 0x0000FF;

      case 0xFF22DD:
        swypeUp = true;//swype animation on color change
        loopMode = MODE_STATICCOLOR;
        currentColor = 0xFF000000;

    irrecv.resume(); // Receive the next value

As I understand it, the Neopixel routine has to disable interrupts to output the LED data (otherwise the strict timing of the pulses out to the LEDs is messed up).

The IR routine needs to use an interrupt to pick up the input signal.

This should only be a problem if you are continually outputting to the LEDs (which continually disables interrupts), but it seems you are simply waiting for some IR signal then updating the LEDs, then returning to just wait for another IR signal.

So... I think there is something else wrong.

Try commenting out the switch( results.value ){ ... } and just Serial.print( results.value )

I'm not familiar with the IR library you are using, so it may be worth checking some simple example code which uses it.

I'm guessing that irrecv.decode(&results) might be continually returning true after the first receive, so the LEDs are continually being written.

You could try simply setting results.value= 0; before irrecv.resume();

Yours, TonyWilk

Hi Tony thanks for your answer

i tried to comment out the switch( results.value ) and replace it with Serial.print( results.value ) and that didnt work to compile because the switch case function disables ?

And i also tried to write results.value= 0; before irrecv.resume(); it didnt do any different it

still just taking the first signal from the ir controller. for exaple when i click W for White on controller it

turns white but wont take a new signal it just stays there so i guess that there is still a interrupts problem.


it now works ! :)

the problem was that (ShowStrip); paused the interrupts so removed them from the for loops and now it works :) (couldnt post that part of code)

Ante93: ...the problem was that (ShowStrip); paused the interrupts...

Ahhhhh... now you tell us there was more to it :o

Happy you got it going!

Yours, TonyWilk

yes sorry i was so assured that the problem was somewhere in the switch case function but when i tried to add all the code it was more than the maximum limit to write here :)

my code is 560 lines long but only 200 was posted whoops :o

will think of that next time i need to ask here in the forum ! :)