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.
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
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 :
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.
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++; }
}
}