Using NeoPXL8 with interrupt reliant libraries on RP2040 SCORPIO

Please tell us which board you are using.
For CircuitPython issues, ask in the Adafruit CircuitPython forum.

Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.
Locked
User avatar
RandomCoder11
 
Posts: 2
Joined: Mon May 22, 2023 3:03 pm

Using NeoPXL8 with interrupt reliant libraries on RP2040 SCORPIO

Post by RandomCoder11 »

I am attempting to control neopixels using a 433mhz remote. I am using the rc-switch library to read the signals from my receiver module. Standalone it works perfectly fine and has very solid range. When the NeoPXL8 show() function is called it messes everything up for a short period, it reduces the range to a few inches and even serial library can't send data. The problem is that im trying to run animations on the neopixels eventually which means calling show() repeatedly trashing my range. I have already attempted separating controlling the neopixels and getting reciever signals from the remote on to separate cores using loop1(). There is no weird rf interference when its running because another 433mhz module next to it on a separate micro controller is not affected. Here is the entirety of my test code:

Code: Select all

#include <RCSwitch.h>
#include <Adafruit_NeoPXL8.h>

#define NUM_LEDS 30
#define COLOR_ORDER NEO_GRBW

int8_t pins[8] = { 16, 17, 18, 19, 20, 21, 22, 23 };

Adafruit_NeoPXL8 leds(NUM_LEDS, pins, COLOR_ORDER);
RCSwitch Remote = RCSwitch();

unsigned long LastPress = 0;
uint32_t Color = leds.Color(0, 0, 0, 255);
uint8_t Mode = 0;
uint8_t Bright = 255;
uint8_t Speed = 7;
bool On = false;

void setup1() {
  Serial.begin(9600);
  Remote.enableReceive(digitalPinToInterrupt(9));
}

void setup() {
  if (!leds.begin()) {
    pinMode(LED_BUILTIN, OUTPUT);
    for (;;) digitalWrite(LED_BUILTIN, (millis() / 500) & 1);
  }
  leds.setBrightness(Bright);
  leds.fill(leds.Color(0, 0, 0, 0), 0, NUM_LEDS*8);
  leds.show();
}

void loop() {
  leds.setBrightness(Bright);
  if (On == true) {
    leds.fill(leds.gamma32(Color), 0, NUM_LEDS*8);
  }
  else {
    leds.fill(leds.Color(0, 0, 0, 0), 0, NUM_LEDS*8);
  }
  leds.show();
}

void loop1() {
  if (Remote.available()) {
    long RemoteValue = Remote.getReceivedValue();
    unsigned long WaitTime = millis() - LastPress;
    if (RemoteValue >= 51969 && RemoteValue <= 51980 && WaitTime > 250) {
      if (RemoteValue == 51971) {
        Serial.println("On/Off button pressed");
        On = !On;
      }
      else if (RemoteValue == 51969) {
        Serial.println("White button pressed");
        Color = leds.Color(0, 0, 0, 255);
      }
      else if (RemoteValue == 51977) {
        Serial.println("Mode+ button pressed");
        if (Mode < 7) {
          Mode += 1;
        }
        else {
          Mode = 0;
        }
      }
      else if (RemoteValue == 51975) {
        Serial.println("Mode- button pressed");
        if (Mode > 0) {
          Mode -= 1;
        }
        else {
          Mode = 7;
        }
      }
      else if (RemoteValue == 51978) {
        Serial.println("Speed+ button pressed");
        if (Speed < 8) {
          Speed += 1;
        }
      }
      else if (RemoteValue == 51980) {
        Serial.println("Speed- button pressed");
        if (Speed > 1) {
          Speed -= 1;
        }
      }
      if (RemoteValue != 51979 && RemoteValue != 51973){
        LastPress = millis();
      }
    }
    if (RemoteValue >= 51981 && RemoteValue <= 52223) {
      Serial.print("Color Value: ");
      Serial.println(RemoteValue - 51981);
      uint16_t hue = (RemoteValue - 51981) * 270 - 21000;
      Color = leds.ColorHSV(hue);
    }
    if (RemoteValue == 51979) {
      Serial.println("Bright+ button pressed");
      if (Bright < 255) {
        Bright += 15;
      }
    }
    if (RemoteValue == 51973) {
      Serial.println("Bright- button pressed");
      if (Bright > 15) {
        Bright -= 15;
      }
    }
    Remote.resetAvailable();
  }
}
Does anyone have suggestions on how I can continuously refresh my neopixels without impacting the functionality of the other components in my code?

User avatar
mikeysklar
 
Posts: 13936
Joined: Mon Aug 01, 2016 8:10 pm

Re: Using NeoPXL8 with interrupt reliant libraries on RP2040 SCORPIO

Post by mikeysklar »

Running on both cores sure looked like a good solution to this problem. If that is still causing resource contention enough to mess up the NeoPixel display then maybe the remote stuff need to be done with an additional controller? Add a Qt Py RP2040 with serial UART <--> Scorpio UART?

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

Return to “Feather - Adafruit's lightweight platform”