Neopixel Ws2812 Rainbow LED Glow With M5stick-C | Running Rainbow on Neopixel Ws2812 Using M5stack M5stick C Using Arduino IDE

Hi guys in this instructables we will learn how to use neopixel ws2812 LEDs or led strip or led matrix or led ring with m5stack m5stick-C development board with Arduino IDE and we will make a rainbow pattern with it.

Teacher Notes

Teachers! Did you use this instructable in your classroom?
Add a Teacher Note to share how you incorporated it into your lesson.

Step 1: Things You Need

For this instructables we need following things :

m5stack m5stick-C development board
Type C usb cable

Ws2812 neopixel led strip/led matrix/led ring/few leds

Step 2: Install ESP32 Boards Un Your Arduino IDE

Make sure you installed ESP32 boards in your Arduino IDE and if it is not the case then make please follow the following instructables to do that :

ESP32 BOARDS INSTALL :

Step 3: Circuit

The current part is very simple :
The Din pin on Neopixel will go to pin G26 on m5stick-C.
And the Vcc/Vin of neopixel will need 5v so get 5v from some power supply
And the Gnd pin of neopixel will go to Gnd of that 5v power
And the Gnd pin of neopixel will also be connected to gnd pin of m5stick-C to provide common ground.

The other way is also there for circuit ( say if your m5stick-C battery is discharged ) :
In that scenario you can connect 5v power supply 5v/Vcc pin to Vcc/Vin pin of neopixel & 5v pin of m5stick-C as well
Gnd pin of that power supply will be connected to gnd of neopixel as well as gnd of m5stick-C board.

And Din pin of neopixel will go to G26 of m5stick-C development board.

Please refer wired connection images for your reference if you face isssue.

And for powering 5v DC to the circuit i am using Arduino's Vin pin & Gnd pin because arduino is getting power from usb cable which is connected to a power bank.
Note : if you are using arduino and powering it with more than 5V do not use Vin pin , use Vin pin only if arduino is getting power from some 5v source otherwise use Vcc pin instead of Vin pin.

Step 4: Uploading Code

Before uploading the code make sure you installed FastLED library in your Arduino IDE if not please do that first.

Please copy the following the code & upload it to your m5stick-c development board using Arduino IDE. :

Before Uploading the code nake sure you have entered the number of LEDs your neopixel has in code as i entered 64 LEDs because i have 64 led in my neopixel matrix.

/*
Please install FastLED library first.
In arduino library manage search FastLED
*/
#include "M5Stack.h"
#include "FastLED.h"

#define Neopixel_PIN 26 //enter no. of LEDs your neopixel has
#define NUM_LEDS 64

CRGB leds[NUM_LEDS];
uint8_t gHue = 0;
static TaskHandle_t FastLEDshowTaskHandle = 0;
static TaskHandle_t userTaskHandle = 0;

void setup() {
Serial.begin(115200);
M5.begin();
M5.Lcd.clear(BLACK);
M5.Lcd.setTextColor(YELLOW); M5.Lcd.setTextSize(2); M5.Lcd.setCursor(40, 0);
M5.Lcd.println("Neopixel Example");
M5.Lcd.setTextColor(WHITE);
M5.Lcd.setCursor(0, 25);
M5.Lcd.println("Display rainbow effect");

// Neopixel initialization
FastLED.addLeds(leds, NUM_LEDS).setCorrection(TypicalLEDStrip);
FastLED.setBrightness(10);
xTaskCreatePinnedToCore(FastLEDshowTask, "FastLEDshowTask", 2048, NULL, 2, NULL, 1);
}

void loop()
{

}

void FastLEDshowESP32()
{
if (userTaskHandle == 0) {
userTaskHandle = xTaskGetCurrentTaskHandle();
xTaskNotifyGive(FastLEDshowTaskHandle);
const TickType_t xMaxBlockTime = pdMS_TO_TICKS( 200 );
ulTaskNotifyTake(pdTRUE, xMaxBlockTime);
userTaskHandle = 0;
}
}

void FastLEDshowTask(void *pvParameters)
{
for(;;) {
fill_rainbow(leds, NUM_LEDS, gHue, 7);// rainbow effect
FastLED.show();// must be executed for neopixel becoming effective
EVERY_N_MILLISECONDS( 20 ) { gHue++; }
}
}

Step 5: Rainbow on Neopixel LED

So after uploading the code, you can see the rainbow pattern is displaying on my neopixel LED matrix and it will appear sake for you neopixel led strip/matrix/ring.
Please refer video to see it working in motion.

Indoor Lighting Contest

Participated in the
Indoor Lighting Contest

Be the First to Share

    Recommendations

    • Made with Math Contest

      Made with Math Contest
    • Multi-Discipline Contest

      Multi-Discipline Contest
    • Robotics Contest

      Robotics Contest

    Discussions