This is Part 1 of a Mini Series. Manya has challenged herself to use the Adafruit NeoPixels (WS2812B RBG LEDs) with the Freescale FRDM-K64F board and the Kinetis SDK (see “Let’s play with Freescale FRDM-K64F“). I did a while back that with the FRDM-KL25Z board (see “NeoShield: WS2812 RGB LED Shield with DMA and nRF24L01+“). I used Processor Expert in my project (without the Kinetis SDK), and with this setup it is very easy. However, Manya wanted to do this with the Kinetis SDK and without Processor Expert. No surprise to me, she has found out that this setup with the Kinetis SDK and without the usage of Processor Expert is much more challenging (see “Not done yet!!“). I promised to Manya to give her a helping hand, so here we go! 🙂
Mini Series Tutorial List
- Tutorial: Adafruit WS2812B NeoPixels with the Freescale FRDM-K64F Board – Part 1: Hardware
- Tutorial: Adafruit WS2812B NeoPixels with the Freescale FRDM-K64F Board – Part 2: Software Tools
- Tutorial: Adafruit WS2812B NeoPixels with the Freescale FRDM-K64F Board – Part 3: Concepts
- Tutorial: Adafruit WS2812B NeoPixels with the Freescale FRDM-K64F Board – Part 4: Timer
- Tutorial: Adafruit WS2812B NeoPixels with the Freescale FRDM-K64F Board – Part 5: DMA
I’m starting here a mini series of articles how to use the FRDM-K64F board from Freescale with the Adafruit WS2812B LEDs ((Adafruit named them ‘NeoPixels‘). I’m using the Freescale Kinetis Design Studio V3.0.0 (Eclipse based IDE with GNU ARM Embedded (launchpad)) with the Freescale Kinetis SDK. This first part covers how to set up the hardware.
The WS2812B LEDs are RGB LEDs which have a built in-current driver with a shift register: I can chain the LEDs to long stripes and shift data to them.
There are several challenge with the WS2812B, both electrically and because of the special protocol needed by the WS2812:
- The NeoPixels need a 5V power supply. Each LED requires up to 60 mAin fulll (white) brightness (20 mA for each color (red, green and blue). Driving many LEDswill require a *lot* of current. For my larger projects I’m using multiple 5V 40A (!!!!!!) power supplies for my larger projects :-).
- There needs to be large capacitor (1000 µF, 6.3V or higher) across the + and – terminals of the pixels. This prevents the initial onrush of current from damaging the pixels. That capacitor is not needed for a few (say 1-3) pixels, but definitely recommended for anything beyond, otherwise you risk to damage the pixels!
- The WS2812B logic level is 5V. As the FRDM-K64F board is using 3.3V, I need a very precise and fast (!) logic level shifter which translates the 3.3V to 5.0V, such as the 74AHCT125 or 74HCT245.
- The LEDs need a very precise timing. For each LED I need to shift 24 bits: first 8 bits for Green, then 8 bits for Red and finally 8 bits for Blue. A ‘1’ is encoded as 0.8 µs high, 0.45 µs low. A ‘0’ is 0.85 µs high, then 0.85 µs low. It is not (!!!) possible from normal C code to toggle a pin to reach that precision and timing, unless you are using well tuned assembly code.
To make it easier to connect WS2812 stripes, at the university we have developed a shield for FRDM or Arduino boards. The schematics and CAD files are open source and can be found on https://github.com/ErichStyger/mcuoneclipse/tree/master/Altium/NeoPixel%20Shield. As you very likely do not have that board :-(, I’ll describe how to do a similar thing with a bread board instead :-).
On another note: Using a high-speed logic analyzer or oscilloscope is *critical* for these kind of projects. If you do not have one, now it would be time to get one. Seriously! Doing such projects or finding problems without the right tools will be very, very frustrating, and every engineer or hobbyist should have the right tools on his bench :-).
💡 I’m using the Logic16 (not available any more) and Logic Pro8) from Saleae (http://www.saleae.com). They are affordable and saved me countless hours of desperate debugging. The Logic4 is priced around $100 and would be good engough for this project. BTW: the Salea Logic16 was my Christmas present a couple of years ago (which I bought for myself) :-).
You need the following hardware:
- A Freescale Freedom board. I use the FRDM-K64F in this article. You can use any other board, but then you need to use potentially a different pin to talk to the LEDs.
- Any number of WS2812B/NeoPixels from Adafruit (http://www.adafruit.com/category/168).
- A good 5V power supply, depending on the amount of pixels/WS28122 you are using. E.g. the 5V 10A from Adafruit (http://www.adafruit.com/products/658). Consider as well a power jack to screw terminal adapter (http://www.adafruit.com/products/368)
- A good 3.3V to 5.0V level shifter. I recommend 74AHCT125 or 74HCT245 which are available in bread board friendly packages.
- A 300-500 Ohm resistor which is put into the DIN line to the LEDs
- A 1000 µF capacitor, rated at least 6.3V to be put between the 5V and GND.
- A bread board, necessary bread board wires and USB cables.
The image shows the wiring between the FRDM board , the level shifter and the NeoPixel LED’s.
💡 Make sure you use the correct polarity of the capacitor!
In the picture I use a USB breakout board (http://www.adafruit.com/products/1833) connector as power supply: that way I can power a few LEDs from my laptop USB port (up to 500 mA) without the need for an external power supply, or using a wall USB power supply (I have one powering up to 2 A :-)).
💡 Additionally, you might consider to use the 5V from the FRDM board. But do this *only* for very limited number of LED’s, as that 5V is very limited (check the schematics of your board!). I do *not* recommend that 5V, unless you are sure you are not damaging your board.
Every Adafruit NeoPixel Board uses GND, 5V and DIN (Data IN). Connect these lines to the circuit described above. Solder wires or use headers where applicable. The picture shows a 8×8 NeoPixel Matrix on the left and a 8 pixel board stripe on the right:
I can chain multiple modules/strips with connecting the DOUT (Data OUT) to the DIN (Data IN) of the next module.
This completes the hardware setup and wiring. It is important to use a good level shifter, a capacitor to limit the current rush plus a resistor on the input to the LEDs. Make sure you have a good power supply which is able to drive up to 60 mA per LED/Pixel. Multiple stripes and boards can be combined.
With this, the next article will describe how to get the software tools ready. So stay tuned…
Happy Hardwareing 🙂
- Adafruit Guide on NeoPixels: https://learn.adafruit.com/adafruit-neopixel-uberguide/overview
- Using FRDM-KL25Z with NeoPixels: https://mcuoneclipse.com/2014/07/13/first-adafruit-neopixel-blinks-with-the-frdm-board/
- Bread-Board project with level shifter: https://mcuoneclipse.com/2014/07/18/adafruit-neopixel-clock-with-60-leds/
- Application with NeoPixels and FRDM-KL25Z: https://mcuoneclipse.com/2014/07/27/led-clock-with-kitchen-hot-pan-protector/
- Custom level shifter shield for NeoPixels: https://mcuoneclipse.com/2014/11/10/neoshield-ws2812-rgb-led-shield-with-dma-and-nrf24l01/
- Manya’s Diary: https://mcuoneclipse.com/category/manyas-diary/
- Freescale Freedom FRDM-K64F Board: http://www.freescale.com/webapp/sps/site/prod_summary.jsp?code=FRDM-K64F
- Freescale Kinetis Design Studio: http://www.freescale.com/kds
- Freescale Kinetis SDK: http://www.freescale.com/kds
- WS2812B Shield Schematics: https://github.com/ErichStyger/mcuoneclipse/tree/master/Altium/NeoPixel%20Shield