RainbowBit – Smart RGB LED

RainbowBit – Smart RGB LED

It has been an exciting year back in 2013. Besides launching rero on indiegogo.com, we have been busy with the development for Robot Head To Toe, not to forget the improvement and ongoing development needed for rero. One of our new products is smart LED. Have you ever wanted to add LED to your project but think twice when you see all the wires needed? Well, now you should think again.

 

 

With WS2812B LED, only 1 pin is needed to control as many RGB LEDs as you want. This is SMD (Surface Mount Device) LED that integrates a driver controller alongside RGB (Red Green Blue) into a tiny 5050 package controlled through a single wire; even better, it can be daisy-chained and individually controllable. In simple words, you can control this RGB LED, a single unit, or chain it up to as many as you want, and you are still able to control each and every LED individually. All this can be done with 1 digital output pin from your microcontroller. Isn’t that amazing!!

 

If you look closely at the picture above, you can actually see the bonding of wires to different segments (Red, Green, Blue) from the driver chip. All this is on a single 5050 SMD package LED. For the time being, we only offer the breakout board that is mounted with a single WS2812B LED :). We are developing more of RainbowBit products, keep a close look at our front page. The flexible LED strip (RainbowStrip) is here, we are excited too.

Nature of RainbowBit (WS2812B) LED:

  • Not all RGB LEDs are RainbowBit (WS2812B). We named this RGB LED because it is like a rainbow. Anyway, the library and interface can be applied to WS2811 and WS2812 LED.
  • Beware! RainbowBit will require some sort of controller (such as Arduino) to operate/light up. It will not light up by itself even the power is connected, not like a normal LED. However, fear not! We do provide guidance and example code to use it, and you should create your own lighting magic! You will love it.
  • Do understand this, controller push bit by bit to 1st RainbowBit and further to 2nd, and so on and so forth. This requires time, therefore, you are not able to get a fast refreshing rate if there are too many RainbowBit. But do not get me wrong, there are still plenty of projects that you can do with RainbowBit.
  • Not every controller can handle the timing requirement of the serial protocol needed for RainbowBit (WS2812B). Some controllers such as Netduino and Raspberry Pi might have a hard time reliably achieving this requirement. Even Arduino or PIC running the RainbowBit function cannot be distracted by an interrupt which might affect the timing.

Features and Specifications of RainbowBit:

  • Ready with WS2812B LED and decoupling cap
  • Every RainbowBit is tested before being shipped
  • Operating voltage, VDD or VCC: +3.5V to +5.5V
  • Built-in signal reshaping circuit
  • 256 levels of brightness (PWM) for each color (RGB), offering a 16777216 color display
  • RainbowBit is designed to be cascaded side by side
  • Input signal voltage: -0.5V to VDD+0.5V
  • Each RainbowBit can draw up to 60mA at maximum brightness white(RGB all at full brightness)
  • Each color segment at full brightness will draw around 20mA

1st thing 1st, the Hardware (RainbowBit) 

Yes, is time to hook this colorful LED and get some rainbow out of it! All you need is a +5VDC supply and a digital output pin which you could program to output the timing required. As the example sketch provided is using BBFuino, we will follow it. The library for RainbowBit was developed by Adafruit (credit goes to them). We modified the example and created another example, RainbowBit_Example. The sketch is compatible with Arduino UNOArduino PRO MiniArduino MegaArduino Nano, and more Arduino main board series. RainbowBit_Example uses four RainbowBit modules, but you can always use one to start if you wanted to try it. Let’s hook up!

BBFuino+RainbowBit

RainbowBit connected to BBFuino

If you refer to the diagram carefully, the RainbowBit is being connected in daisy chain format. Only the 1st Rainbowbit is connected to BBFuino. While the output (-, +, and O) of 1st RainbowBit is connected to the input of 2nd RainbowBit. Please do check the arrow direction on RainbowBit, it indicates the direction of control flow from BBFuino or your controller.

The “In” of 1st RainbowBit should be connected to pin D2 of BBFuino. If you are using another type of Arduino board, simply make the same connection as shown:

  • GND from Arduino to “-” of 1st RainbowBit
  • 5V from Arduino to “+” of 1st RainbowBit
  • D2 from Arduino to “In” of 1st RainbowBit

Note: Is a good practice to connect the GND (-) pin before anything else.

Not to forget, you will need to solder the header pin of your choice to RainbowBit. Try to get a 1×40 straight header pin, or 1×40 right angle header pin, or any connector that you like.

With the assumption you have been using Arduino IDE, I will proceed with library installation. If you are new, please do visit the getting started guide with BBFuino here. Download the library and example sketch here. Unzip it and move the folder to Documents\Arduino\libraries. Open Arduino IDE, and go to File -> Examples -> Adafruit_NeoPixel -> RainbowBit_Example. Compile and load it into BBFuino.

This is what the example code does:

  • RainbowBit will illuminate in Red light from the 1st to 4th module
  • Change the 4th to 1st RainbowBit module into Green
  • Change 1st to 4th RainbowBit into Blue
  • Change 4th to 1st RainbowBit into White
  • Blank all from 1st to 4th RainbowBit and
  • Lastly, a rainbow sequence through all 4 RainbowBit

Hope you have fun with the result, if you cannot get the expected result, please check:

  • Polarity, center pin of RainbowBit is +5V, not 3.3V or Vin of Arduino.
  • D2 of Arduino should be connected to “In” of RainbowBit, not “O”.
  • Make sure the 5V is stable. Try putting a 100uF E cap between 5V and GND.
  • Connections on the breadboard, is it lose?

RainbowBit Layout

The center white color chip is the WS2812B RGB LED chip and the brown color chip on the top is the decoupling cap (0.1uF).

RainbowBit is designed to be cascaded side by side. If you wanted to build your own LED strip, you will only need 3 wires from the controller board to 1stRainbowBit, and another 3 wires from the output of 1st RainbowBit to the input of 2nd RainbowBit, and so on and so forth until you are out of wires or RainbowBit. You can even solder it directly as shown.

Top View: RainbowBit

Bottom View: RainbowBit

Make sure the data direction arrow is pointing in the same direction.

Power requirement

RainbowBit should be powered with +5VDC. Lower voltages are always safe, but not necessarily acceptable. Even though it might function, the light from LED will be slightly dimmer. The minimum voltage is +3.5V, we have yet to test it with a 3.3V system, but if the voltage drops below a certain level, RainbowBit will start to display the wrong color. Besides, power voltage will drops across the wire due to resistance. Although the resistance is small in wires, it makes difference if it is long. This means the power voltage near the end of the wire will be lower than the beginning of the wire. To overcome the power voltage drop at the end of the RainbowBit string (if it is very long), you can actually connect another power source at the end or middle of the wire, making sure the voltage level is the same. RainbowBit does not care which direction they receive power from, though the data only flow in one direction (follow the arrow). You can simply measure the voltage at beginning of the string and at end of the string by using a multimeter. Just compare the result. We did a RainbowBit string in our office with a length of 5.5 meters. The voltage drops around 0.4V at the end of the string.

How about the current draw? What is the current spec of the power supply you should use? This is easier to calculate  Assuming a RainbowBit requires 60mA in the full brightness of the white color (All RGB at full brightness), just multiply it by the number of RainbowBit in the system. As an example, with 30 RainbowBit in a chain, the maximum current draw will be:

30 x 60mA = 1.8A.

You should get a power supply of at least 2A considering the current draw by the microcontroller and other components. Nonetheless, you can always power the RainbowBit chain with a lower current power source if you manage to control the brightness (PWM) of the LED. Not all RainbowBit emits white color all the time 

Which power supply/source should I use?

  • Switching Power supply, with an output of 5V, for example this power supply. It provides high current and stable voltage output. But always connect a 470uF >10V Electrolytic Cap parallel with the output. This prevents potential inrush current which might damage the 1st RainbowBit.

  • AC to DC adapter, 5V 1A:

  • Use the power from the microcontroller 5V regulator. Most microcontroller board including BBFuino, Arduino UNO, and SK40C comes with a 5V voltage regulator. It can always be used for RainbowBit. Do bear in mind; generally, this type of voltage regulator (linear regulator) is rated under 1A or even under 500mA. So if the brightness of RainbowBit is being controlled, you can still power up to 20 of it in the chain.
  • Use single cell 18650 Li-ion or Li-po rechargeable battery. A single-cell Li-ion or Li-po battery is rated at 3.7V (fully charged at 4.2V), this is just nice to power up most of the low power microcontroller,s and RainbowBit. 5 to 8 RainbowBit will work fine.

  • Benchtop adjustable power supply. CAUTION!! Most benchtop power supplies will produce high voltage spikes when initially switch ON, so if you plan to use this, do not connect the RainbowBit directly. Please switch the power supply ON and let the voltage stabilize, only connect the RainbotBit, always the GND first.

  • Desktop ATX Power supply with proper hacking. The ATX power supply is being used in desktop computers and offers +3.3V, +5V, and +12V with very stable voltage output and high current. With proper hacking, this is a very low-cost yet stable option to power up a long string of RainbowBit. We have been using this power supply with BB-ATXRA in our laboratory for several projects. Check out our tutorial on how to use it.

How does it work? The Protocol!

We reach the magic area of RainbowBit. You can ignore this section if you are a beginner and using the library. We will be talking about the protocol of RainbowBit, what makes it to be addressable individually and able to be chained up. If you wanted to write your own code, come in!

I extract the data from the WS2812B datasheet, in case I made mistake, please go back to the datasheet.

RainbowBit/s is/are controlled by a simple, yet timing-critical wire protocol on the input signal line. Each RainbowBit has 3 bytes (24-bit) of data to control the PWM/brightness of Red, Green, and Blue LED (8-bit each). As you might know, color LED is a combination of Red, Green, Blue LED integrated together closely. The color of the LED is determined by the brightness of these 3 LEDs. These values (brightness of three LEDs) should be sent into RainbowBit in GRB (Green, Red, Blue) sequence, NOT RED, GREEN, BLUE!!


The first 24-bit color brightness transmitted out applies to the first RainbowBit LED which is the closest to the microcontroller, with the MSB (Most Significant Bit) going first. While the second 24-bit color brightness transmitted applies to the next LED or 2nd LED in the string, and so on.

The sequence of 24-bit for RainbowBit.

As the diagram illustrates, 1st byte sent out from the microcontroller should be brightness for Green LED, and MSB (bit-7) goes first, followed by 8-bit of brightness for the Red LED and further Blue LED. Not to forget, this 24-bit data is for one RainbowBit, if you have more RainbowBit in chained, you need to continue sending data. To update all the RainbowBits in the string, all the color data should be sent out at once (24-bit + 24-bit + 24-bit……) with no pauses. If less data is being sent out than the number of RainbowBit in the string, some RainbowBit near the end of the string will not be updated. For example, if you have 20 RainbowBit in your string and you want to update all of the RainbowBit (most of the time you want to do that), you should send 480 bits (24-bit x 20 RainbowBit) of data out as pulses and then hold the line low for at least 50us (microseconds) or more.

Now let’s look at the lower layer of communication. Since there is only 1 wire, there must be a special way to transmit logic 1 and 0. During an idle state (no data), the signal line should be low. To transmit color brightness, a series of high pulses are needed to be sent out. Each high pulse encodes a bit: A short pulse (0.35µs) represents a zero (logic 0), while a long pulse (0.9µs) represents a one (logic 1). The time between adjacent rising edges should be 1.25µs. After bits for all RainbowBit are sent, the signal line should be held low for at least 50µs to send a reset command, which makes the new color data take effect. From experiments, the pulse widths do not have to be precise, however, the high pulse period plays an important factor to determine the logic.

Logic pulses

 

Logic timing requirement

 

Note that there’s around 20% to 25% of the “grey area” to play around with the timing table. ±150ns for high and low stages, giving us a total of ±300ns for tolerance. So if your code cannot output a bit at the recommended timing, it might be still working :). Although there is tolerance, most of the library is written using Assembly language to ensure the correct timing. Besides, to ensure the timing is met, interrupt is disabled during the data is being sent out. Therefore, the Servo library in Arduino does not work well with RainbowBit functions. If you have to use interrupt, you may modify the code to enable interrupt during a low state of the signal which might work, but we do not sure about that.

Alternative libraries

Yes, we like to use RainbowBit with other types of microcontrollers too. For the time being, we have tested the NeoPixels library from Adafruit Industries, working fine! Kudos to them. However, since the library is written with a mix of Assembly languages due to the requirement of timing, it might not work on Netduino, ChipKit, or other “Arduino-like” development boards. Yet, it does work with common Arduino boards such as UNOLeonardoMegaDUE, Micro, Pro-MiniNano, and BBFuino.

How about other types of microcontrollers or boards? We have yet to explore other libraries, but here are some links that might be worth a look:

WS2811 vs WS2812 vs WS2812B

You might have seen WS2811, WS2812/S, and WS2812B in the market and are not sure can the library works with this chip. WS2812B is the latest RGB LED with an integrated chip which is revised from WS2812. WS2812 is 6 pins while WS2812B is 4 pins. Both WS2812 and WS2812B are build base on WS2811. WS2811 is an external LED driver chip.  

Why did we choose WS2812B? According to the manufacturer, WS2812B is better in terms of:

  • Better mechanical package design – WS2812B only has 4 pins vs 6 pins in WS2812/S. This simpler design prevents shorts and offers improved voltage drop and thermal dissipation by allowing for larger power and ground planes on the PCB.
  • Higher Brightness – The WS2812B is able to produce a much higher brightness than the WS2812/S.
  • Safety performance comparison – WS2812B comes with reverse polarity protection at the power line. It will survive the reverse connection of power.
  • Internal structure improved – WS2812B has a better structure than WS2812. The control circuit and the RGB LED have been separated, it has a better heat dissipation performance. The control and LEDs work independently, one does not relate to the other, line distance is shorter and making the work more stable.

Well, that is from us. We will try to update more libraries and the RainbowBit product lines.

BUY