Saturday, May 09, 2020

Marlin, ESP32, RGB LEDs, and case light

Previously, I tested NEOPixel RGB LEDs on the MRR ESPA. This time, I tested the options for controlling the LEDs via an LCD controller. For that, I needed to use the MRR ESPE since the MRR ESPA cannot support the traditional LCD12864 controller.

The setup:
- One NEOPixel light strip with 10 addressable RGB LEDs, connected to 5V, GND, and GPIO2
- One 120mm RGB fan, connected to 12V, GND, and pins 153, 154, and 155 for R, G, and B respectively via a custom MOSFET board
(Note: Non-addressable RGB LEDs can be controlled via the I2S output pins since they are basically on/off only. For NEOPixels, the I2S output pins cannot be used for the data pin; the data pin needs to be connected to a native ESP32 pin like GPIO2.)


First, the changes in configuration files needed.
Configuration.h
#define RGB_LED

#if EITHER(RGB_LED, RGBW_LED)
  #define RGB_LED_R_PIN 153
  #define RGB_LED_G_PIN 154
  #define RGB_LED_B_PIN 155
  //#define RGB_LED_W_PIN -1
#endif

 
#define NEOPIXEL_LED
#if ENABLED(NEOPIXEL_LED)
  #define NEOPIXEL_TYPE   NEO_GRB 

  #define NEOPIXEL_PIN     2
  #define NEOPIXEL_PIXELS 10
  #define NEOPIXEL_IS_SEQUENTIAL
  #define NEOPIXEL_BRIGHTNESS 127
  #define NEOPIXEL_STARTUP_TEST
#endif

 
Configuration_adv.h
#define CASE_LIGHT_ENABLE
#if ENABLED(CASE_LIGHT_ENABLE)
  #define CASE_LIGHT_PIN 2
  #define INVERT_CASE_LIGHT false
  #define CASE_LIGHT_DEFAULT_ON true
  #define CASE_LIGHT_DEFAULT_BRIGHTNESS 105
  //#define CASE_LIGHT_MAX_PWM 128
  #define CASE_LIGHT_MENU
  //#define CASE_LIGHT_NO_BRIGHTNESS
  #define CASE_LIGHT_USE_NEOPIXEL
  #if ENABLED(CASE_LIGHT_USE_NEOPIXEL)
    #define CASE_LIGHT_NEOPIXEL_COLOR { 255, 255, 255, 255 }
  #endif
#endif
 

  #define LED_CONTROL_MENU
  #if ENABLED(LED_CONTROL_MENU)
    #define LED_COLOR_PRESETS
    #if ENABLED(LED_COLOR_PRESETS)
      #define LED_USER_PRESET_RED        255
      #define LED_USER_PRESET_GREEN      128
      #define LED_USER_PRESET_BLUE         0
      #define LED_USER_PRESET_WHITE      255
      #define LED_USER_PRESET_BRIGHTNESS 255
      //#define LED_USER_PRESET_STARTUP
    #endif
  #endif



The results are not really stunning. But it works.

On boot, the NEOPixels will cycle through red, green, and blue, then turn white since the light strip is configured as a case light which is always on after boot. Somehow, setting the color of the NEOPixels also end up setting the colors for the RGB fan.

I then used the LCD controller to turn on and off the case light. The menu item is actually under Configuration -> Case light. This has options for on/off and brightness. Even when NEOPixels are used, there is no option to change colors from the LCD controller.

Next, I used the LCD controller to change LED colors. This is under the LED option of the main menu. Changing LED colors will affect both the RGB fan as well as the NEOPixel light strip. Somehow, they are linked inside the firmware. I don't know if this is a feature or a bug.

This is the custom MOSFET board. It can be used to drive a RGB CPU fan. It is basically two sets of dual-channel MOSFETs to give a total of four channels. Three channels are used for RGB control, the remaining channel for fan control.






The glitch when using the Adafruit_Neopixel library with ESP32 still exists. One way to try and resolve the glitch is to select the same option on the LCD controller again. Basically, run the command twice. This helps most of the time. Another option involves editing neopixel.h itself to change the show() function.
  static inline void show() {
    adaneo1.show();
    adaneo1.show();
    #if PIN_EXISTS(NEOPIXEL2)
      #if MULTIPLE_NEOPIXEL_TYPES
        adaneo2.show();
        adaneo2.show();
      #else
        adaneo1.setPin(NEOPIXEL2_PIN);
        adaneo1.show();
        adaneo1.show();
        adaneo1.setPin(NEOPIXEL_PIN);
      #endif
    #endif
  }

Basically, call show() twice.

Conclusion: The LCD controller can be used to control LEDs (of course) and it works with ESP32-based boards. Both MRR ESPA and MRR ESPE have been tested to work with RGB LEDs: the MRR ESPA can work with NEOPixels, while the MRR ESPE has enough pins to use for NEOPixels as well as non-addressable RGB LEDs.

Get the MRR ESPA board here.

MRR ESPA and MRR ESPE related social media:
Facebook page
Facebook group for users


No comments: