Shifting Levels

Welcome to The...how do you say?...Ah yes....NeoPixels

Sometimes, meaning can get lost in translation. It can happen to regular people like you and me, it can happen to actor Antonio Banderas, and it can even happen between microcontrollers and NeoPixels!

There are lots of great microcontrollers that speak the language of 3v3 (3.3 volts) which can make it difficult for them to communicate with NeoPixel LEDs, which speak 5V. Thankfully, along comes a bi-lingual translator, the logic level converter -- or level shifter -- to save the day.

First, The Problem

Let's start with the three inputs on a NeoPixel: GND, DIN, and +5V. (For greater detail, check out the excellent NeoPixel Überguide.) 

Two of those -- GND and +5V -- connections to the power supply used to light up the strip. GND needs to be tied in to the microcontroller and the power source, +5V should be the connection to a dedicated power source in most cases (unless you're using a small strip or ring of NeoPixels which can be run directly from a 5V source on the microcontroller).

The third connection -- DIN -- is the data line, which also runs at a 5V logic level on the NeoPixel drivers. And this is where the confusion lies.

Some microcontrollers, such as the Arduino Uno and Adafruit Metro 32u4, run at 5V logic levels, and so their data pins can speak directly with the NeoPixel. Other microcontrollers, such as the Adafruit Feather boards, Arduino M0 Pro, Teensy 3, and others, run at 3.3V logic levels. This means there can be a communications mismatch when one of their data pins tries to talk to the NeoPixel's DIN input.

When the 3.3V board tries to talk to the 5V NeoPixel, a variety of strange behaviors can be exibited, including incorrect colors, flickering, dimness, and seemingly "dead" pixels. 

This is particularly a problem on long wiring runs or driving large numbers of NeoPixels -- you can often get away with the logic level mismatch on smaller numbers of pixels near the board. You can also run small numbers of NeoPixels at both 3.3V for power and data, such as directly off of a Gemma or Trinket.

Next, The Solution

The logic level converter is the perfect solution to this problem. It has one job, which it does flawlessly: it listens to our 3.3V microcontroller data, translates it to a 5V-compatible message, and passes that along to our 5V NeoPixel. 

This is the 74AHCT125, a quad level shifter that can connect 3.3V and 5V devices of up to four channels. 

I've got a project that will use a 3.3V microcontroller, and six channels of NeoPixel strips running at full brightness from a large 5V power brick, so I decided to go with the 8-channel LXB0108 logic shifter seen here. 

This chip can send messages in both directions, and works with pretty much any microcontroller and sensor pairing that need translation, however this guide just focuses on one possible pairing to NeoPixels.

Connections

When connecting the level shifter, you can think of it as having two halves. On the left side you'll make connections your microcontroller, on the right side to your NeoPixels.

On each side you'll make a connection between the device's operating voltage and the relative VCC pin on the level shifter. This acts as a reference voltage to tell the level shifter what to expect from the data pins on that side.

So, for the Feather M0 Basic Proto, for example, the microcontroller's 3.3V pin connects to VCCA on the level shifter's left side. The NeoPixel's +5V power source connects to the VCCB pin on the level shifter's right side.

Ground on all devices must be tied together, including a connection to GND on the level shifter.

Now, you can use any of the eight level shifting channels to do your translations. Connect, say, digital output pin 6 of the Feather to pin A1 of the level shifter's left side. Then connect the corresponding pin B1 of the level shifter to the DIN pin of the NeoPixels. The data flowing out of the Arduino at 3.3V logic levels will be translated by the level shifter to 5V logic levels and then passed along via the B1 pin to the NeoPixel. 

Permanence

Once you're happy with your circuit on a breadboard, you can move it over to a more permanent home, a PermaProto board!

The PermaProto board has the same layout as the breadboard, so you can move the circuit directly from one to another. But on the PermaProto board you can solder the wires and pins of your components, so it's much more secure than the breadboard.

Last updated on 2017-02-17 at 12.40.38 PM Published on 2017-02-16 at 11.35.40 PM