Colored Light Widget with WS2812B LEDs

Does anyone know if it is possible to use WS2812B LEDs with the Colored light widget?

I have been trying but it seems it only wants to work with the RGB leds on my IoT carrier but I cannot get them to work with the WS2812B strip.
I would like to try and have the colored light widget control the colors of my WS2812B LED strip.

Can anyone help me with the coding if this is possible?
Would like to include FastLED but I also for Adafruit NeoPixel to work.

What is this?
Can you post a link to it please.

From this page:

The colored light widget is designed to set the color of a lamp and turn it ON or OFF.
Can be linked with a Colored Light variable.
An example of how it is used in a sketch:

uint8_t r, g, b;
rgbVariable.getValue().getRGB(r, g, b);

I do not know how the "widget" pushes the RGB values to the Arduino, but the code in the Arduino would change the RGB lights, and WS2812B use the same range of RGB; 0 to 255. It seems possible.

This is where I am at with the code,
I am a bit of a beginner with programming and trying to learn what I can.

I used the base Cloud code, added a standard fastLED setup, and added the description in the widget database in the end statement.

uint8_t r, g, b;2rgbVariable.getValue().getRGB(r, g, b);

/*
Sketch generated by the Arduino IoT Cloud Thing "Untitled"
https://create.arduino.cc/cloud/things/390eae0f-abc1-4600-8a04-3dc4b0c1274e

Arduino IoT Cloud Variables description

The following variables are automatically generated and updated when changes are made to the Thing

CloudColoredLight lEDstrip;

Variables which are marked as READ/WRITE in the Cloud Thing will also have functions
which are called when their values are changed from the Dashboard.
These functions are generated with the Thing and added at the end of this sketch.
*/

#include "thingProperties.h"
// FastLED NeoPixel - Version: Latest
#include <FastLED.h>

#define NUM_LEDS 5
#define LED_PIN 6 // Replace 6 with your actual pin number

CRGB leds[NUM_LEDS];

void setup() {
// Initialize serial and wait for port to open:
Serial.begin(9600);
// This delay gives the chance to wait for a Serial Monitor without blocking if none is found
delay(1500);

FastLED.addLeds<WS2812B, LED_PIN, GRB>(leds, NUM_LEDS);

// Defined in thingProperties.h
initProperties();

// Connect to Arduino IoT Cloud
ArduinoCloud.begin(ArduinoIoTPreferredConnection);

/*
The following function allows you to obtain more information
related to the state of network and IoT Cloud connection and errors
the higher number the more granular information you’ll get.
The default is 0 (only errors).
Maximum is 4
*/
setDebugMessageLevel(2);
ArduinoCloud.printDebugInfo();
}

void loop() {
ArduinoCloud.update();
// Your code here

}

/*
Since LEDstrip is READ_WRITE variable, onLEDstripChange() is
executed every time a new value is received from IoT Cloud.
*/
void onLEDstripChange() {
// Add your code here to act upon LEDstrip change

uint8_t r, g, b;
lEDstrip.getValue().getRGB(r, g, b);
}

I finally got it figured out, it was an issue in the final argument.

#include "thingProperties.h"
#include <FastLED.h>

#define NUM_LEDS 300
#define LED_PIN 6 // Replace 6 with your actual pin number

CRGB leds[NUM_LEDS];

void setup() {
// Initialize serial and wait for port to open:
Serial.begin(9600);
// This delay gives the chance to wait for a Serial Monitor without blocking if none is found
delay(1500);

FastLED.addLeds<WS2812B, LED_PIN, GRB>(leds, NUM_LEDS);

// Defined in thingProperties.h
initProperties();

// Connect to Arduino IoT Cloud
ArduinoCloud.begin(ArduinoIoTPreferredConnection);

/*
The following function allows you to obtain more information
related to the state of the network and IoT Cloud connection and errors.
The higher the number, the more granular information you’ll get.
The default is 0 (only errors).
Maximum is 4.
*/
setDebugMessageLevel(2);
ArduinoCloud.printDebugInfo();
}

void loop() {
ArduinoCloud.update();
// Your code here
}

/*
Since LEDstrip is READ_WRITE variable, onLEDstripChange() is
executed every time a new value is received from IoT Cloud.
*/
void onLEDstripChange() {
// Add your code here to act upon lEDstrip change
uint8_t r, g, b;
lEDstrip.getValue().getRGB(r, g, b);

// Use the RGB values to control your FastLED NeoPixel strip
for (int i = 0; i < NUM_LEDS; i++) {
leds[i] = CRGB(r, g, b);
}
FastLED.show();
}

1 Like

! yeay !

This trips up everyone. Me, too.

The color of the LEDs is a bit dim and I am having issues getting the deep, full, rich color. It always comes out like a light shade no matter what I try to do.

Can anyone help with this issue?

Look up "ws2812 power injection" and your WS2812B will be bright from beginning to end.

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.