Need help choosing Socket Type

I want to control individual LEDs on this LED strip:
https://www.sparkfun.com/products/11272

There is some sample code in C for how this should be used:
http://www.sparkfun.com/datasheets/Components/LED/LED_Strip_Example.pde

I have a FEZ Spider I want to use for this. I’m thinking I can use these breakout extension modules:
http://www.ghielectronics.com/catalog/product/405

So the question is, what type of socket should I be using? The example code on sparkfun states " These
are controlled over a simple data and clock setup", but I’m not sure what exactly that means. It also displays a key like this:

Blue = 5V
Red = SDI
Green = CKI
Black = GND

However the acronyms “SDI” and “CKI” are not used anywhere on the Gadgeteer socket documentation:
http://gadgeteer.codeplex.com/wikipage?title=.NET%20Gadgeteer%20Socket%20Types

So I’m guessing I can probably use the I socket type (I2C interface), assuming the “SDI” and “CKI” ports map to what Gadgeteer calls “data (SDA) and clock (SCL) lines”. I wanted to sanity check that assumption with the community first.

I noticed another guy did something similar:

however, he used the SPI socket type. I’d prefer to use the I socket, since I have more of these. Do I need to use S or I, or can I use either?

It’s an SPI-like protocol, so an SPI socket will be easiest. But if the timing constraints aren’t too bad you could even bit-bang it or use software SPI and use any socket with GPIOs.

@ Brett - thanks for the ideas. What exactly does “bit bang” mean? I’ve seen that term in other places, but don’t actually understand what that means, can you explain a little further please?

I’m guessing that SDI means “Serial Data In” and CKI means “ClocK In”. The interface, at a hardware level, uses the data and the clock lines together to input data. Each time the clock “ticks” (by either going high or low, depending, you’d need to read the datasheet to be sure), the LED strip looks at the data line and reads either a 1 or a 0 depending on whether it’s high or low.

If you were using the SPI port, the hardware would take care of setting the data and clock pins to the correct states. If you’re “bit-banging” that means you’ll need to do that yourself. This means two OutputPort instances, one each for the two pins, and for each byte you want to send, changing the clock line high and then low for each bit, and the data line to the appropriate state for the byte you’re sending.

@ Paul F. - As Brett mentioned you can use software SPI for a few leds but then more use the worst the results will be.
Best idea is to use a “S” socket and use an extender and wire up the Red SDI to Pin 7 MOSI, Green CKI to pin 9 SCK and Black GND to pin 10
You will need to use external +5v supply for the LEDS as the spider cannot supply enough current.
Word of caution - dont give the strip more than +5v…

Each LED needs 3 Bytes of data for red green and blue, but will probably be in the order of blue red green at a guess.

So sending 255,0,0 will make LED 1 Blue.
Sending 255,0,0,0,255,0 will make LED1 Blue and LED2 Red

So basically you send an array of bytes 3 x number LEDS so for 1m strip an array of 96 bytes

This should get you going


using System.Threading;
using GT = Gadgeteer;
using GTM = Gadgeteer.Modules;
using GTI = Gadgeteer.Interfaces;

namespace ConcentratedTech
{
    public partial class Program
    {
     
        private byte[] _data;
        private static GTI.SPI _spi;

        void ProgramStarted()
        {
            GT.Socket socket = GT.Socket.GetSocket(6, true, null, null);
            GTI.SPI.Configuration config = new GTI.SPI.Configuration(false, 0, 0, false, true, 2000);
            _spi = new GTI.SPI(socket, config, GTI.SPI.Sharing.Exclusive, socket, GT.Socket.Pin.Five, null);
            _data = new byte[32 * 3];

           SetAllColour(255, 0, 0);
           Thread.Sleep(1000);
           SetAllColour(0, 0, 0);
        }
        private void SetAllColour(int red, int green, int blue)
        {
            if (red > 255) red = 255;
            if (green > 255) green = 255;
            if (blue > 255) blue = 255;

            ClearData();
            for (int i = 0; i < _data.Length; i += 3)
            {
                _data[i + 2] = (byte)red;
                _data[i + 1] = (byte)green;
                _data[i] = (byte)blue;
            }
            _spi.Write(_data);
        }
        
        private void AnimateLeftToRight(int red, int green, int blue, int numPix, int time)
        {
            if (red > 255) red = 255;
            if (green > 255) green = 255;
            if (blue > 255) blue = 255;

            ClearData();
            int pause = time / 160*10;

            int x = 0, y = 0;
            int length = _data.Length - (numPix * 3);

            while (x < length)
            {
                y = 0;
                while (y < numPix * 3)
                {
                    _data[(x + 2) + y] = (byte)red;
                    _data[(x + 1) + y] = (byte)green;
                    _data[x + y] = (byte)blue;
                    y += 3;
                }
                _spi.Write(_data);
                x += 3;
                _data[(x + 2) - 3] = 0x00;
                _data[(x + 1) - 3] = 0x00;
                _data[x - 3] = 0x00;
                 Thread.Sleep(pause);
            }
        }
        private void ClearData()
        {
            for (int i = 0; i < _data.Length; i++)
            {
                _data[i] = 0x00;
            }

        }
    }
}


@ ransomhall has actually written some code here: http://www.tinyclr.com/codeshare/entry/259

Have fun :slight_smile: