The basics of the Yocto-Color-V2

The basics of the Yocto-Color-V2

We recently noticed that our libraries didn't include an example using the Yocto-Color-V2. On top of adding this missing example in all of our libraries, we decided to write a post illustrating the new function which was added to the Yocto-Color-V2.





The first version of the Yocto-Color could drive only two RGB leds. To drive them, the module had two functions, colorled1 and colorled2, which enabled you to respectively drive led 1 and led 2.

However, the Yocto-Color-V2 can drive up to 150 leds and the module CPU cannot manage 150 functions for the leds. It wouldn't have been very practical in any case.

So we added a new function, colorLedCluster, which allows you to drive all the leds. This colorLedCluster function is more complex because it enables you to drive and to configure all the leds connected to the Yocto-Color-V2.

Note on backward compatibility


In order to maintain compatibility, the Yocto-Color-V2 still has the two colorled1 and colorled2 functions driving the first two leds. This enables applications developed for the Yocto-Color to go on working with the Yocto-Color-V2. However, for new developments, we recommend that you use the new colorLedCluster function.

The YColorLedCluster class


If you have never used Yoctopuce modules before, we strongly recommend that you start by reading our post series for the beginners. We assume that you already know how our libraries work and that you can use our programming library in your language of preference.

To drive the leds, you must use the YColorLedCluster class. Depending on the programming language that you use, you may need to include the yocto_colorcluster file which defines this class.

from yocto_colorledcluster.py import *



Then, like with any of our functions, you must use the FindColorLedCluster or FirstColorLedCluster to obtain the object allowing you to drive this feature.
For example, the following Python code initializes the ledCluster variable with the YColorLedCluster object of the Yocto-Color-V2 with the YRGBLED2-1234 serial number.

ledCluster = YColorLedCluster.FindColorLedCluster('YRGBLED2-1234.colorLedCluster')



Configuration

Before trying to drive the leds, you must configure the number of leds which are connected to the Yocto-Color-V2 as well as their type. To do so, use the set_activeLedCount and set_ledType methods.

Since firmware 30526, you can use RGBW leds with the Yocto-Color-V2. It is therefore important to configure the type of leds that you are using at the same time as you specify the number of connected leds. If when using the Yocto-Color-V2 you obtain strange color patterns, there is a high probability that you haven't set the correct led type or that you have mixed the two types of leds.

Finally, as with all other parameters, you must save these parameters in the flash memory with the module saveToFlash() method.

The following code configures the Yocto-Color-V2 to work with 60 RGB leds.

ledCluster.set_activeLedCount(60)
ledCluster.set_ledType(YColorLedCluster.LEDTYPE_RGB)
ledCluster.get_module().saveToFlash()



Assigning a color to a led

The set_rgbColor() method enables you to assign an RGB color to one or several adjacent leds. The first parameter is the starting offset, the second parameter is the number of leds impacted, and finally the last parameter is the color that must be assigned.

# assigns the red color to the first led
ledCluster.set_rgbColor(0, 1, 0xff0000)
# assigns the blue color to leds 11 to 60
ledCluster.set_rgbColor(10, 50, 0x00ff00)



You can also assign the values of the leds by block, with the set_rgbColorArray() method. The first parameter is the starting offset, and the second is the array of the values to be assigned.

# assigns the red color to led 10
# assigns the green color to led 11
# assigns the blue color to led 12
values = []
values.append(0xff0000)
values.append(0x00ff00)
values.append(0x0000ff)
ledCluster.set_rgbColorArray(10, values)



You can also read the color with the get_rgbColorArray() method. this function takes as parameter the starting offset and the number of leds, and returns an array with the colors.

# reads the value of leds 11 to 60
rgbValues = ledCluster.get_rgbColorArray(10, 50)



Transitions

You can perform a transition towards a color with the rgb_move() method. This method has an additional argument to the set_rgbColor() method, which is the length of the transition.

# transitions toward the blue color over one second for leds 11 to 60
ledCluster.rgbMove(10, 50, 0x00ff00, 1000)



Note, this function returns control immediately, and the transition is performed internally by the Yocto-Color-V2 CPU. Therefore, if two transitions are performed one after the other without delay, only the second one is actually run.

In the following code, the firs transition doesn't have time to run.

# Coding error! Only the second transition is visible.
ledCluster.set_rgbColor(10, 50, 0xff0000, 1000)
ledCluster.set_rgbColor(10, 50, 0x00ff00, 1000)



For the previous code to work, you must add a waiting delay of one second so that the transition to red has time to end.

# transitions toward the red color over one second for leds 11 to 60
ledCluster.set_rgbColor(10, 50, 0xff0000, 1000)
# waits for 1 second that the transition is over
time.sleep(1)
# transitions toward the blue color in one second for leds 11 to 60
ledCluster.set_rgbColor(10, 50, 0x00ff00, 1000)



Colors displayed at power on


All the functions that we have seen change the current state of the leds, but you can also modify the led default color. To do so, you must use the set_rgbColorAtPowerOn() method which works like the set_rgbColor method, but instead of applying the color to the implicated leds, it changes the led default value. This default value is the color which is displayed as soon as the module is powered on.

Note, you must imperatively save these modifications with the saveLedsConfigAtPowerOn() method, otherwise the changes are lost.

ledCluster.set_rgbColorAtPowerOn(0, 1, 0xff0000);
ledCluster.set_rgbColorAtPowerOn(10, 50, 0x00ff00);
ledCluster.saveLedsConfigAtPowerOn();



The HSL color space


All the functions that we have just showed you work in the RGB color space, but you can also work in the HSL color space.

For each function that we just detailed, there is an HSL equivalent:

RGB color spaceHSL color space
set_rgbColorset_hslColor
set_rgbColorArrayset_hslColorArray
get_rgbColorArrayget_hslColorArray
rgb_movehsl_move
set_rgbColorAtPowerOnset_hslColorAtPowerOn



These methods work in the same way as their RGB version, but the color value is represented by 3 bytes which correspond to the color Hue, Saturation, and Luminosity (HSL) instead of the Red, Green, Blue components.

Sequences


In this post, we discussed only "simple" ways to program the leds. But the Yocto-Color-V2 can also play pre-programmed animations. You can consult our post on the topic for more details.

Programming examples

For all the libraries, we added a Doc-GettingStarted-Yocto-Color example which uses what we just saw. You now have everything you need to start using your own Yocto-Color-V2.




1 - fwa Sunday,june 11,2023 0H30

A nice application would be a project where you create counter light. A drone could have a camera facing up that takes pictures of the sky and led’s on the underside, the idea being that the light emitted by the led’s should make the drone stealthy.

Yoctopuce, get your stuff connected.