RF433 and FastLed, problems with condition

Hi,

I am a bit new in the Arduino programming world and it's my first time asking for help. I'm probably missing something very simple.

The project:
By using the RadioHead library and the FastLed library, I try to make an led lantern that change every time it received a string via RF433hz.
A RF433hz transmitter is sending a 6 character string like "ZONE A" and then on the receiver (the led lantern) I'm reiceiving it and then send a chase to the LEDs on the "ZONE A" condition ( or anything the string can be ).

So far everything works great in a range of 20' without antenna. Exactly what I wanted to prevent overlap.

The problem :
I want it to keep chasing the last received cue over and over again until a different string is received. So when the lantern goes in a dead zone it's not black.

My diagnosis:
As I use bool for cues, I don't get why it's stopping from chasing. Even if any conditions is unfulfilled the last "true" bool should stay right ?
In my code after each chase the RF ask fonction is resend, so I suspect that; because the string is empty on a dead zone, nothing happen and the bool are all false...

I know that I am near the solution I just might miss something very simple.

Thank you.

The code ( using Arduino Nano v3 ) :

//RF 433 Rx Libs
#include <RH_ASK.h>
#include <SPI.h>
//data pin to D11

RH_ASK rf_driver;

String str_out;

//FastLed Libs
#include <FastLED.h>
#define LED_PIN     5
#define NUM_LEDS    100
CRGB leds[NUM_LEDS];

//cue variable

bool cueA = false;
bool cueB = false;
bool cueC = false;

void setup() {

  //RF 433 setup
  rf_driver.init();
  Serial.begin(115200);


  //FastLed setup
  FastLED.addLeds<WS2812B, LED_PIN, GRB>(leds, NUM_LEDS);
}


void loop() {


  //RF 433 loop

  //Size of string message

  uint8_t buf[6];
  uint8_t buflen = sizeof(buf);
  if (rf_driver.recv(buf, &buflen)) {
    str_out = String((char*)buf);
    str_out.remove(6, 10);
    Serial.println(str_out);

    //CUE A
    if (str_out == "ZONE A") {
      cueA = true;
      cueB = false;
      cueC = false;

      //FastLed CUE A

      if (cueA == true) {

        for (int i = 0; i <= 99; i++) {
          leds[i] = CRGB ( 255, 0, 0);
          FastLED.show();
          delay(20);
        }

        for (int i = 0; i <= 99; i++) {
          leds[i] = CRGB ( 0, 0, 0);
          FastLED.show();
          delay(20);
        }

        for (int i = 0; i <= 99; i++) {
          leds[i] = CRGB ( 255, 15, 0);
          FastLED.show();
          delay(20);
        }

        for (int i = 0; i <= 99; i++) {
          leds[i] = CRGB ( 0, 0, 0);
          FastLED.show();
          delay(20);
        }
      }
    }


    //CUE B
    if (str_out == "ZONE B") {
      cueA = false;
      cueB = true;
      cueC = false;


      //FastLed CUE B

      if (cueB == true) {

        for (int i = 0; i <= 99; i++) {
          leds[i] = CRGB ( 0, 0, 25);
          FastLED.show();
          delay(20);
        }

        for (int i = 99; i >= 0; i--) {
          leds[i] = CRGB ( 255, 0, 80);
          FastLED.show();
          delay(20);
        }
      }
    }


    //CUE C
    if (str_out == "ZONE C") {
      cueA = false;
      cueB = false;
      cueC = true;


      //FastLed CUE C

      if (cueC == true) {

        for (int i = 0; i <= 99; i++) {
          leds[i] = CRGB ( 0, 0, 25);
          FastLED.show();
          delay(20);
        }
      }
    }
  }
}

Hello, do yourself a favour and please read How to get the best out of this forum and modify your post accordingly (including code tags and necessary documentation of your ask).

please edit your post, select the code part and press the </> icon in the tool bar to mark it as code. It's barely readable as it stands. (also make sure you indented the code in the IDE before copying, that's done by pressing ctrlT on a PC or cmdT on a Mac)

Hi,

thank you for the forum tips and resources. The post now looks better indeed.

indeed, doesn't it ?

all your code is in this if : if (rf_driver.recv(buf, &buflen)) {
so if you did not receive anything, you don't do anything.

Note there is limited interest in doing this:

    if (str_out == "ZONE A") {
      cueA = true;
      cueB = false;
      cueC = false;
      //FastLed CUE A
      if (cueA == true) { // <-- YOU JUST SET it to true.... 
....

➜ set your cues when you receive something. then outside the global if, use the cues to decide what to do

This totally make sens, I will be able to try it tomorrow at the office. Thank you for the quick reply.

The RadioHead in ASK mode takes over the Arduino Nano, because it has to run the interrupt routine a lot. The RadioHead library also uses a lot of SRAM memory, some of that memory is not even used. The previous VirtualWire does not use all that extra memory.

The FastLED (and also the NeoPixel) library take over the Arduino Nano. With 100 leds, nothing else works reliable anymore. Even millis() is no longer reliable. It also requires SRAM memory for all the leds.

Can you make two test-sketches ? A sketch for the RadioHead/VirtualWire using the Serial Monitor to output the result and an other sketch for the FastLED. Then you know that your code is good.

However, I'm afraid they will not work together on a single Arduino Nano.

Good to know but I'm 90% sure that it's not a memory issue as everything run smoothly.

Hi again, I've edited my code so everything is not inside the "if (rf_driver.recv(buf, &buflen)) " condition.

But now I am stuck in the cues loop. I just want to recheck the rf string after each loop and rewrite str_out.

I don't know what I am doing wrong.

Here is my code update:

//RF 433 Rx Libs
#include <RH_ASK.h>
#include <SPI.h>
//data pin to D11

RH_ASK rf_driver;

String str_out;

//FastLed Libs
#include <FastLED.h>
#define LED_PIN     5
#define NUM_LEDS    100
CRGB leds[NUM_LEDS];

//cue variable

bool cueA = false;
bool cueB = false;
bool cueC = false;

void setup() {

  //RF 433 setup
  rf_driver.init();
  Serial.begin(115200);


  //FastLed setup
  FastLED.addLeds<WS2812B, LED_PIN, GRB>(leds, NUM_LEDS);
}


void loop() {

  // Get String
  uint8_t buf[6];
  uint8_t buflen = sizeof(buf);
  if (rf_driver.recv(buf, &buflen)) {
    str_out = String((char*)buf);
    str_out.remove(6, 10);
    Serial.println(str_out);
  }

  //FastLed CUE A

  if (str_out == "ZONE A") {

    for (int i = 0; i <= 99; i++) {
      leds[i] = CRGB ( 255, 0, 0);
      FastLED.show();
      delay(20);
    }

    for (int i = 0; i <= 99; i++) {
      leds[i] = CRGB ( 0, 0, 0);
      FastLED.show();
      delay(20);
    }

    for (int i = 0; i <= 99; i++) {
      leds[i] = CRGB ( 255, 15, 0);
      FastLED.show();
      delay(20);
    }

    for (int i = 0; i <= 99; i++) {
      leds[i] = CRGB ( 0, 0, 0);
      FastLED.show();
      delay(20);
    }

    if (rf_driver.recv(buf, &buflen)) {
      str_out = String((char*)buf);
      str_out.remove(6, 10);
      Serial.println(str_out);
    }

  }


  //FastLed CUE B

  if (str_out == "ZONE B") {

    for (int i = 0; i <= 99; i++) {
      leds[i] = CRGB ( 0, 0, 255);
      FastLED.show();
      delay(20);
    }

    for (int i = 99; i >= 0; i--) {
      leds[i] = CRGB ( 255, 0, 80);
      FastLED.show();
      delay(20);
    }

    if (rf_driver.recv(buf, &buflen)) {
      str_out = String((char*)buf);
      str_out.remove(6, 10);
      Serial.println(str_out);
    }

  }


  //FastLed CUE C

  if (cueC == true) {

    for (int i = 0; i <= 99; i++) {
      leds[i] = CRGB ( 0, 0, 25);
      FastLED.show();
      delay(20);
    }
  }
}

You don’t need this multiple times. Just listen once during each loop

I tryed this whitout succes. I even tryed to send a Serial.print to see if I where going out of the loop, and I did but I didn't received another rf message after that. Weird.

I however solved my problem. I only send HIGH and LOW values on D2 and D3 pins wired on another arduino D2 and D3 pins. And I start my Fastled cues on those condition.
Works like a charm. I'll be building some proto lantern tommorow and present the project to my boss. Ask me if you want a video.

Thank you for your times and helps.

You probably were having just too much to deal with for one arduino.
Great to hear you solved it.