Connecting an RGB LED strip to Carambola

Measuring SPI signals with the scope

Interfacing RGB LED strips to an Arduino is easy: it’s been done many times so often it’s a matter of downloading the correct code library and you are ready to go. These plug-and-play code libraries do not exist for Carambola, but for Stripe I need one. Today, I will show you how I hooked up the hardware and created the software for an LPD8806 RGB LED strip connected directly to the Carambola.

Why not just use an Arduino?

If you are following along in my Stripe series, you might recognize the following schematic:

Laptop - arduino - led strip

This was the setup I used in the Arduino-based Stripe prototype. But Stripe is meant to be stand-alone, so the laptop is replaced by Carambola:

Carambola, Arduino and the LED strip

Not bad! This gives us a stand-alone Wi-Fi platform and full control over the colors on the LED strip. But still, an Arduino is quite large and expensive if its only purpose is to translate serial commands in digital signals on two pins. The Carambola has several GPIO pins, so getting rid of the Arduino should be possible:

Carambola to LED strip without Arduino

Hardware-wise this is a piece of cake. The Carambola runs on 3.3V and the chips on the LED strip work fine with 3.3V signals. Now it’s just a matter of finding the right GPIO pins to use and write the software.

Finding free GPIOs

Finding free GPIO on Carambola

Not every pin on Carambola can be used as a digital input or output. Some are already in use by the status LEDs, serial ports or the I2C bus. After probing around with the brand-new oscilloscope and having a good read on the Carambola Wiki I found that the pins of the second serial port could be used for driving the LED strip.

Twiddling bits: an open source mash-up

In the Arduino prototype, I used Adafruit’s LPD8806 library to communicate with the LED strip. The library is written in C/C++ and the nice thing about C/C++ is: it’s universal! It can run on any kind of hardware as long as you compile it for the right platform. The LPD8806 library is open source, so I was free to use it as the basis for having Carambola talk to the LED strips.

What I just said about C/C++ being universal is not completely true. Some parts, like switching digital pins, are hardware-specific. In the LPD8806 Arduino library, writing to the LED strip is done with the trusty digitalWrite command:

void LPD8806::writezeros(uint16_t n) {
    digitalWrite(datapin, LOW); // Data low

    uint16_t i;

    for(i = 8 * n; i>0; i--) {
      digitalWrite(clockpin, HIGH);
      digitalWrite(clockpin, LOW);

For Carambola, I found the equivalent to digitalWrite is using ioctl. This was found by browsing through the (open) source code of a program that toggles GPIO pins on Carambola. The function writezeros for Arduino then turns into:

void writezeros(int n) {
    ioctl(fd, GPIO_CLEAR, data_pin); // Data low

    int i;    

    for(i = 8 * n; i>0; i--) {
      ioctl(fd, GPIO_SET, clock_pin);
      ioctl(fd, GPIO_CLEAR, clock_pin);

Even if you don’t understand the code above, you can still see that porting the Arduino library to Carambola is mostly a matter of replacing some Arduino-specific commands by instructions suited to the Carambola.

Wrapping it up and testing

To test if it works, I wrapped the library in a small C program that sets RGB colors from the command line. Here is what the oscilloscope shows when I send some colors to the LED strip.

RGB LED strip commands on the scope

The yellow line is the clock line, the red line the data. The frequency measurement at the bottom left shows that data is transferred at 270kHz, which should be enough to change all 32 LEDs in the strip 11 thousand times per second. Plenty fast!

On this blog, I am documenting the design of an internet-enabled linear LED clock: Stripe. Want to know more? Have a look at all posts about Stripe, subscribe to the RSS feed or follow me on Twitter

One Response to “Connecting an RGB LED strip to Carambola”

  1. eas

    Thanks for sharing what you are learning about the Carambola.

    I found out about the platform looking for an inexpensive way to allow WiFi control my own LED project, so these examples are of particular interest.

    I’m new to hardware hacking, so the arduino ecosystem is attractive, but the WiFi solutions are generally expensive, and it offends my sense of elegance to have all the power of the WiFi SOC go to waste.

    I hope the Carambola community blossoms!

Leave a Reply