Category Archives: Circuit

LED light strip LPD6803 code

Wow, it’s been a crazy few months. I am taking some courses for my masters, started a few contracting gigs and went to China with DangerousPrototypes Hacker Camp. There is so much to write about and I’ve been dropping the ball on Protological. Time to change that. Time for some cool LED stuff!

While in China I picked up a 5 meter “5050” 12V LED strip with 30 LEDs per meter for 90RMB which is $14.50 USD. I didn’t buy the controller because I wanted to control it with a microcontroller of course! The controller chip is a knockoff LPD6803 LED driver chip that listens for clocked data. The only datasheet I could find was from Adafruit here and the english is really, really bad. I didn’t know ‘grey’ == ‘color’?! After some playing around I figured out the protocol for how the data is sent. The commands are 16-bit and shifted out MSB first, the clock is idle low and the data is latched in on the high transition of the clock. The MSB is always 1 to indicate that the value is data and the 3 colors are 5 bits each; allowing for 31 steps in brightness.

1000 0000 0000 0000

One would think that the colors are Red, Green and Blue, however some testing showed they are Green, Red and Blue.

1000 0000 0000 0000
D|Grn ||Red ||Blue|

So if you want to turn on an LED with 1 step of RGB the byte value is 1 00001 00001 00001 = 1000 0100 0010 0001 = 0x8421;

These strips can be chained together, so to ‘reset’ the strip pixel ID and have it listen for a new set of colors you send 32 0’s which is 8 bytes of 0x00. Once I got the protocol figured out it was really easy to hook up a micro and control the strip.

I used an LPC1768 Mbed microcontroller (because it’s super easy) and made a demo program with some simple animations. The strip is 30 LEDs per meter, 5 meters long. Each LED ‘pixel’ is a group of 3 RGB LEDs and they all show the same color. So there are 50 groups of 3 in my 5 meter strip. The way I drive the LEDs is I make a uint16_t array in RAM for the 50 pixels, then create a timer to run through the array and send it out to the strip using the SPI hardware. With 8 bytes of reset, 100 bytes of data, at 500KHz I was able to address the whole strip in about 4ms. I set my timer to update the strip at 10ms, giving me a 100Hz refresh rate.

The rest of the application just writes the data array in memory and lets the timer clock it out to the strip. I included the code here with 4 demos. This will build in the Mbed compiler and uses the P5 & P6 SPI pins on the LPC1768 for data and clock. It should be pretty straight forward to port to an Arduino or other microcontroller, just setup a timer and update the SPI config and write functions.

Here is a video of the demos in action:

And the source file: ledstrip_mbed_demo.cpp

Enjoy, Drew

Debounce Calculator Online App

I finally got tired of punching numbers into my calculator for debounce circuits so I came up with a small javscript app to determine capacitance, resistance or time for a simple RC circuit. The script is already setup with values for input to a schmitt trigger inverter. This application is based on a single capacitor and resistor circuit as per this image.

ESP8266 boards are in, time for a project

Oooh yeah I got 3 ESP8266 WiFi boards in the mail today from SeeedStudios.  Now lets make a project!  For those that don’t know the ESP8266 is a WiFi to serial board that is only $5-$6 USD.  Apparently the board does all the WiFi and ethernet stuff, so all your project has to do is some basic setup and then RX and TX.  I’ll be reporting on how easy this is here and posting any projects as well as code for microcontrollers.

Got my esp8266 boards today

Debounce switches with simple components

Lets start off with a post that dives into one of the uglier sides of electronics, switch bounce.  Every time a switch closes, mechanical contacts  (which are just pieces of metal) touch each other and complete the circuit. For a short period of time the contacts chatter and open and close the circuit, this is a real nightmare if you are looking for a clean on and off signal.  I ran into this issue with a set of limit switches for a CNC machine.  I decided to put one of the switches on a scope and see what the bounce time was.  Take a look at the scope trace below, as you can see there is about 1.5ms of bounce on these switches for both rise and fall.  It’s been a while since I debounced a switch outside of firmware, so I went off looking for some info, what I found was Jack Ganssle’s site with two pretty good articles on debouncing.  (While you’re there, check out his newsletter).  I dug through my parts bin and found a few 74HC14 schmitt inverters which can be used for debounce since they have a hysteresis between the high and low voltage levels.  Running through the equations on jacks page with a 5v supply, 0.1uF capacitor and a 2.37v high signal for the 74HC14 I came out with almost exactly 31K for the resistance.

I had a 33K resistor and a 0.1uF resistor so I hooked them up as per this schematic and left off the input resistor from Jack’s page and the rise time was just about 2ms. There are some other pages that discuss leaving off the input resistor so I decided to see if the response was acceptable.   You can see the schmitt inverter flips with a nice clean edge, switch debounced!

bouncing_scope_trace scope_rise_debounce scope_switch_debounce_output scope_proto_74HC14_debounce