Maker.io main logo

How to Fire NeoPixels on the micro:bit

2018-08-23 | By Maker.io Staff

micro:bit

The micro:bit has a simple 5 x 5 red LED matrix that can be used to display a wide range of different things including text, symbols, and animations. However, this display is limited to one color and does have its limitations. In this how-to article we will learn how to connect Adafruit NeoPixels to the micro:bit.

Things You Will Need

Schematic

How to Fire NeoPixels on the micro:bit

DigiKey's Scheme-it Wire Diagram

Get NeoPixels On MakeCode

MakeCode is one of the two official ways of programming the micro:bit and it is a fully online IDE. As seen in previous articles, MakeCode offers a very simple way to create programs by using jigsaw-like pieces. However, despite this simple programming method, MakeCode offers a lot more functionality in the form of adding libraries!

NeoPixels work using a single wire timing protocol. Normally, this can be very hard to code from scratch using MakeCode blocks. Thanks to some very clever people, we can instead import a NeoPixel library that contains all the pieces we need to use them! To get this library, click “Advanced” in the sidebar and then click “Add Package”.

How to Fire NeoPixels on the micro:bit

In the window that appears type “NeoPixel” into the search bar. The first result should be NeoPixel. Click this and the package should be downloaded and then included.

How to Fire NeoPixels on the micro:bit

You should see a “NeoPixel” option on the menu on the left, confirming the package has been included.

How to Fire NeoPixels on the micro:bit

NeoPixel Blocks: The Basics

The blocks in the NeoPixel menu are the basic blocks that can be used to make the display work. For those who want to do more advanced tasks (such as setting individual lights), there is an advanced set of blocks under ”…more”. We will use an advanced block to choose a specific pixel in our test program.

When using NeoPixels, first to create a NeoPixel object. This is done by assigning a variable to the value of the block shown below. From this point, the item will reference the NeoPixel in question and must be included in NeoPixel-related functions. Also, you may notice that there is a pin option, a number option, and a color option. The pin option allows us to choose which pin on the micro:bit will be used to communicate with the NeoPixel display (by default this is P0). The number option is used to tell the micro:bit how many LEDs our display has (the FeatherWing has 32 LEDs for example). The last option is the color format. This may vary depending on your NeoPixel, but the FeatherWing uses the GRB format.

How to Fire NeoPixels on the micro:bit

How to Fire NeoPixels on the micro:bit

The next setting to configure is the brightness. For those who may not realize, NeoPixels are incredibly bright: the brightest value being 255 and the dimmest being 0. These LEDs were so bright I had to set the brightness to 5!

How to Fire NeoPixels on the micro:bit

The last two important instructions for the NeoPixel are “show” and “clear”. When NeoPixels are set and adjusted, the display will not update itself until the instruction “show” has been called. If you want to clear the display, use the instruction “clear”.

How to Fire NeoPixels on the micro:bit

NeoPixels: Display Blocks

Now that we know how to get the NeoPixel initialized, it's time to learn a few display routines! The first two basic blocks are “show color” and “show rainbow”. These two instructions use the entire display with the first instruction turning all the pixels on the display to the same color while the second will show a rainbow of colors between two defined LEDs.

How to Fire NeoPixels on the micro:bit

However, for our example, we will configure individual LEDs which is more useful! First, click “…more”. The first block in this list is “set pixel color”, used to set the color of a specific pixel. If you want to turn this pixel off, set the color to black.

How to Fire NeoPixels on the micro:bit

Our Simple Example

Our program starts by creating a NeoPixel object and configuring that object to use pin 0. We also configure the object to use 32 LEDs, which is the number of LEDs on the FeatherWing. Then, the next block sets the blinding brightness of the NeoPixel to 5.

The main “forever” loop is the next section to be executed and the first task in this loop is to sequentially turn on the LEDs one by one using “a” for loop. Once this is done, the next for loop clears each LED sequentially to create a pattern of appearing and disappearing LEDs.

How to Fire NeoPixels on the micro:bit

FeatherWing Pinout

How to Fire NeoPixels on the micro:bit

制造商零件编号 MBIT0003
MICRO:BIT (MICRO:BIT ESSENTIALS
Pimoroni Ltd
制造商零件编号 2945
NEOPIXEL FEATHERWING
Adafruit Industries LLC
Add all DigiKey Parts to Cart
TechForum

Have questions or comments? Continue the conversation on TechForum, DigiKey's online community and technical resource.

Visit TechForum