🤖Have you ever tried Chat.M5Stack.com before asking??😎
    M5Stack Community
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Register
    • Login

    Unexpected behavior on M5stack fire LEDs

    M5Stack Fire
    4
    5
    8.9k
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • B
      bob1996w
      last edited by

      Hello, I have just got my M5stack fire and is making a simple LED modifying program with M5ez. I use the same library as samples in arduino IDE, Adafuit_NeoPixel. The program compiles with no errors, but when I start to use, the LEDs behave wierd.

      Here are the revalent code.

      #define M5_NEO_NUM 10
      #define M5_NEO_PIN 15
      
      Adafruit_NeoPixel pixels = Adafruit_NeoPixel(M5_NEO_NUM, M5_NEO_PIN);
      
      void setup() {
        #include <themes/default.h>
        #include <themes/dark.h>
        ezt::setDebug(INFO);
        pixels.begin();
        pixels.setBrightness(255);
        pixels.show();
        ez.begin();
      }
      

      Selecing which LED to control...

      void mainmenu_leds() {
        ezMenu submenu("Set LED colors");
        submenu.txtSmall();
        submenu.buttons("up # Back # Select # # down #");
        for(int i = 0; i < 10; ++ i) {
          submenu.addItem("LED#" + (String)i);
        }
        submenu.upOnFirst("last|up");
        submenu.downOnLast("first|down");
        while (submenu.runOnce()) {
          int pickedItem = (int)submenu.pick() - 1;
          if (pickedItem >= 0 && pickedItem < 10) {
            menu_setLED(pickedItem);
          }
        }
      }
      

      Each LED gets individual control options here. (0 <= led_no <= 9)

      void menu_setLED(int led_no) {
        /*
        ez.msgBox("Set LED#" + (String)led_no, 
          "You have picked LED#" + (String)led_no);
        */
        ezMenu submenu("Set LED#" + (String)led_no);
        submenu.txtSmall();
        submenu.buttons("up # Back # Select # # down #");
        //submenu.addItem("R | R\t0");
        //submenu.addItem("G | G\t0");
        //submenu.addItem("B | B\t0");
        submenu.addItem("black | Turn off");
        submenu.addItem("white | Turn bright");
        while(submenu.runOnce()) {
          if (submenu.pickName() == "black") {
            pixels.setPixelColor(led_no, pixels.Color(0, 0, 0));
            pixels.show();
            delay(20);
          }
          else if (submenu.pickName() == "white") {
            pixels.setPixelColor(led_no, pixels.Color(255, 255, 255));
            pixels.show();
            delay(20);
          }
        }
      }
      

      Expected behavior:
      When "black" is picked, the corresponding LED should be turned off (pixels.Color(0,0,0))
      When "white" is picked, the LED should turn white (pixels.Color(255,255,255))

      What really happens:
      Usually the corresponding LED behaves normally, but the other LED may also light up random color due to unknown reasons.
      Also, when set LED#0 to black, it displays green. That means LED#0 cannot be turned off now.

      I really don't know what is happening here, please help. Thanks in advance.

      m5-docsM ajb2k3A 2 Replies Last reply Reply Quote 0
      • m5-docsM
        m5-docs @bob1996w
        last edited by

        @bob1996w
        Please use FastLED Library for controlling RGB Led instead of Adafuit_NeoPixel Library.

        https://github.com/FastLED/FastLED

        Because controlling RGB Led with Adafuit_NeoPixel Library will cause some unexpected bug, like some leds will turn into unexpected status(on or blink).

        M5Stack documentation URL

        https://docs.m5stack.com

        1 Reply Last reply Reply Quote 0
        • ajb2k3A
          ajb2k3 @bob1996w
          last edited by

          @bob1996w said in Unexpected behavior on M5stack fire LEDs:

          Hello, I have just got my M5stack fire and is making a simple LED modifying program with M5ez. I use the same library as samples in arduino IDE, Adafuit_NeoPixel. The program compiles with no errors, but when I start to use, the LEDs behave wierd.

          Here are the revalent code.

          #define M5_NEO_NUM 10
          #define M5_NEO_PIN 15
          
          Adafruit_NeoPixel pixels = Adafruit_NeoPixel(M5_NEO_NUM, M5_NEO_PIN);
          
          void setup() {
            #include <themes/default.h>
            #include <themes/dark.h>
            ezt::setDebug(INFO);
            pixels.begin();
            pixels.setBrightness(255);
            pixels.show();
            ez.begin();
          }
          

          Selecing which LED to control...

          void mainmenu_leds() {
            ezMenu submenu("Set LED colors");
            submenu.txtSmall();
            submenu.buttons("up # Back # Select # # down #");
            for(int i = 0; i < 10; ++ i) {
              submenu.addItem("LED#" + (String)i);
            }
            submenu.upOnFirst("last|up");
            submenu.downOnLast("first|down");
            while (submenu.runOnce()) {
              int pickedItem = (int)submenu.pick() - 1;
              if (pickedItem >= 0 && pickedItem < 10) {
                menu_setLED(pickedItem);
              }
            }
          }
          

          Each LED gets individual control options here. (0 <= led_no <= 9)

          void menu_setLED(int led_no) {
            /*
            ez.msgBox("Set LED#" + (String)led_no, 
              "You have picked LED#" + (String)led_no);
            */
            ezMenu submenu("Set LED#" + (String)led_no);
            submenu.txtSmall();
            submenu.buttons("up # Back # Select # # down #");
            //submenu.addItem("R | R\t0");
            //submenu.addItem("G | G\t0");
            //submenu.addItem("B | B\t0");
            submenu.addItem("black | Turn off");
            submenu.addItem("white | Turn bright");
            while(submenu.runOnce()) {
              if (submenu.pickName() == "black") {
                pixels.setPixelColor(led_no, pixels.Color(0, 0, 0));
                pixels.show();
                delay(20);
              }
              else if (submenu.pickName() == "white") {
                pixels.setPixelColor(led_no, pixels.Color(255, 255, 255));
                pixels.show();
                delay(20);
              }
            }
          }
          

          Expected behavior:
          When "black" is picked, the corresponding LED should be turned off (pixels.Color(0,0,0))
          When "white" is picked, the LED should turn white (pixels.Color(255,255,255))

          What really happens:
          Usually the corresponding LED behaves normally, but the other LED may also light up random color due to unknown reasons.
          Also, when set LED#0 to black, it displays green. That means LED#0 cannot be turned off now.

          I really don't know what is happening here, please help. Thanks in advance.

          The Neopixel code uses WS2812 leds where as the Go based used on the fire uses SK6812 leds which operate differently.

          UIFlow, so easy an adult can learn it!
          If I don't know it, be patient!
          I've ether not learned it or am too drunk to remember it!
          Author of the WIP UIFlow Handbook!
          M5Black, Go, Stick, Core2, and so much more it cant be fit in here!

          1 Reply Last reply Reply Quote 0
          • B
            bob1996w
            last edited by

            Thanks for the replies! The FastLED works with no "ghost LEDs", but I still have some questions:
            When changing leds[some_led_index].r, it actually changes the green value of the led. leds[some_led_index].g changes red. blue works normally. Is there anyone having same problems? Thanks.

            This is the current settings I'm using:

            #define M5_NEO_NUM 10
            #define M5_NEO_PIN 15
            CRGB leds[M5_NEO_NUM];
            void setup()
              FastLED.addLeds<SK6812, M5_NEO_PIN>(leds, M5_NEO_NUM);
              // other setups...
            }
            

            Compiler complains that No hardware SPI pins defined. All SPI access will default to bitbanged output, so I also tried WS2811, but the same problem continues.

            The revelant code:

            
            void setLedSingleChannelValue(int led_no, String channel, int val) {
              Serial.println("led_no " + (String)led_no + ", channel " + channel + ", val " + (String)val);
              if (channel == "R") {
                if (led_no < 10) {
                  leds[led_no].red = val;
                }
                else {
                  if (led_no == 10 || led_no == 11) {
                    for (int i = 0; i < 5; ++ i) {
                      leds[i].red = val;
                    }
                  }
                  if (led_no == 10 || led_no == 12) {
                    for (int i = 5; i < 10; ++ i){
                      leds[i].red = val;
                    }
                  }
                }
              }
              else if (channel == "G") {
                if (led_no < 10) {
                  leds[led_no].g = val;
                }
                else {
                  if (led_no == 10 || led_no == 11) {
                    for (int i = 0; i < 5; ++ i) {
                      leds[i].g = val;
                    }
                  }
                  if (led_no == 10 || led_no == 12) {
                    for (int i = 5; i < 10; ++ i){
                      leds[i].g = val;
                    }
                  }
                }
              }
              else if (channel == "B") {
                if (led_no < 10) {
                  leds[led_no].b = val;
                }
                else {
                  if (led_no == 10 || led_no == 11) {
                    for (int i = 0; i < 5; ++ i) {
                      leds[i].b = val;
                    }
                  }
                  if (led_no == 10 || led_no == 12) {
                    for (int i = 5; i < 10; ++ i){
                      leds[i].b = val;
                    }
                  }
                }
              }
              FastLED.show();
              delay(5);
            }
            
            void checkAndSetLedSingleChannel(int led_no, String channel, int delta) {
              int check_led_no = (led_no < 10) ? led_no : (led_no == 12) ? 9 : 0;
              int currentValue = getLedSingleChannelValue(check_led_no, channel);
              int afterValue = currentValue + delta;
              afterValue = (afterValue < 0) ? 0 : (afterValue > 255) ? 255 : afterValue;
              setLedSingleChannelValue(led_no, channel, afterValue);
            }
            
            void menu_setLedSingleChannel(int led_no, String channel) {
              ezMenu submenu(getLedHeaderText(led_no, "Set"));
              submenu.txtSmall();
              submenu.buttons("-1 # -10 # Back | OK # # +1 # +10 # -50 # +50 # ");
              submenu.addItem(channel + " | " + channel + "\t" + (String)getLedSingleChannelValue(led_no, channel));
              while(submenu.runOnce()) {
                String pickButton = submenu.pickButton();
                if (pickButton == "-1") {
                  checkAndSetLedSingleChannel(led_no, channel, -1);
                }
                else if (pickButton == "+1") {
                  checkAndSetLedSingleChannel(led_no, channel, 1);
                }
                else if (pickButton == "-10") {
                  checkAndSetLedSingleChannel(led_no, channel, -10);
                }
                else if (pickButton == "+10") {
                  checkAndSetLedSingleChannel(led_no, channel, 10);
                }
                else if (pickButton == "-50") {
                  checkAndSetLedSingleChannel(led_no, channel, -50);
                }
                else if (pickButton == "+50") {
                  checkAndSetLedSingleChannel(led_no, channel, 50);
                }
                submenu.setCaption(channel, channel + "\t" + (String)getLedSingleChannelValue(led_no, channel));
                delay(20);
              }
            }
            
            // The program enters from this function.
            void menu_setLed(int led_no) {
              /*
              ez.msgBox("Set LED#" + (String)led_no, 
                "You have picked LED#" + (String)led_no);
              */
              ezMenu submenu(getLedHeaderText(led_no, "Set"));
              submenu.txtSmall();
              submenu.buttons("up # Back # Select # # down #");
              submenu.addItem("R | R\t" + (String)getLedSingleChannelValue(led_no, "R"));
              submenu.addItem("G | G\t" + (String)getLedSingleChannelValue(led_no, "G"));
              submenu.addItem("B | B\t" + (String)getLedSingleChannelValue(led_no, "B"));
              while(submenu.runOnce()) {
                String picked = submenu.pickName();
                if (picked == "black") {
                if (picked == "R" | picked == "G" || picked == "B") {
                  menu_setLedSingleChannel(led_no, picked);
                }
                delay(20);
              }
            }
            
            1 Reply Last reply Reply Quote 0
            • H
              horsley
              last edited by

              @bob1996w I meet the same problem, I think I can answer your last question about RGB. I found code on M5Stack_NeoPixelTest.ino

              #define M5STACK_FIRE_NEO_NUM_LEDS 10
              #define M5STACK_FIRE_NEO_DATA_PIN 15
              
              Adafruit_NeoPixel pixels = Adafruit_NeoPixel(M5STACK_FIRE_NEO_NUM_LEDS, M5STACK_FIRE_NEO_DATA_PIN, NEO_GRB + NEO_KHZ800);
              

              NEO_GRB was the data stream order flag according to the comment. GRB & RGB orders different!

              There were similar flags for FastLED, working code shows below

              FastLED.addLeds<WS2812B, M5STACK_FIRE_NEO_DATA_PIN, GRB>
              
              
              1 Reply Last reply Reply Quote 0
              • First post
                Last post