Introduction: Micro:bit Neopixel Introduction

This instructable will teach some basic about Neopixels and show how to use the Neopixel library. Neopixels are a great way to bring light to your projects, since they are cheap, easy to use and the micro:bit can control many of them at the same time.

Supplies

1 x Micro:bit

3 x Alligator-Alligator jumpwires

A strip of Neopixels (WS2812B).

Some wire

Solder

Soldering iron

Step 1: The Neopixel

Neopixels are individual addressable LED. Each have three inputs. Power, ground and data input. On the picture that is 5v, gnd and Din. It also have three outputs. Power, ground and data out. Which again is 5v, gnd and Do on the picture. Since each neopixel can send the data, power and ground to the next neopixel you can daisy chain a large amount of neopixels together and control them all with a single pin out and power them from a single power supply.

While the neopixel does say 5 volt, you can run it on 3.3 volt, but they require a certain amount of power, so you shouldn't try to power to many directly from your micro:bit. So if you want to run many neopixels you should only use the micro:bit to input data, while you get power from another source. Here we will only use 3 neopixels, so powering it from the micro:bit is not a problem.

Step 2: Preparing the Neopixels

First we are going to cut the neopixel strip so that we only have three neopixels. Neopixel strip can be cut betwen the pixels. If you look at the first picture, then the strip can be clip appart at the white stripe. Just use a wirecutter.

I have seen some people put alligator clips directly on to neopixel LED strips, but since I am properly going to use this short strip a few times I am going to solder wires to it. Three wires. A green wire on Din, black wire on gnd and red on 5 v.

Step 3: Connecting the Neopixel Strip and Micro:bit

We use the alligator wires to connect the neopixel to the micro:bit.

Neopixel ->Micro:bit

Gnd -> Gnd

Din -> Pin 0

5 v -> 3.3 v

Step 4: Getting the Extension

First you go to the Makecode editor and start a new project. You then go to "Advanced" and select "Extensions". Be aware that since I am danish, these buttons have slightly different names in the pictures. In extensions you search for "neopixel" and select the top left result.

Step 5: First Program

I am still danish, so my Makecode is in danish, but you can properly still see what the blocks compare to in the english version.

The first block in "On start" (Ved start) tells the micro:bit were to find the neopixel strip and how many neopixels are connected to it. Here we are connecting 3 neopixel to pin 0.

Next block set brightness from 0 to 255. We set it to 30 that is still very bright.

In the forever loop (For altid) we use three different ways to set the LED colours.

The first block sets the first LED to be red. This is the easiest way to set colours, but there is only 10 different colours to choose from. This block doesn't actuelly show the colour on the LED strip. We need to use the show block for that.

The second block set the colour of the second LED based on hue (Kind of the base colour), saturation (How strong the colour is) and luminosity (How bright or dark the colour is). This is going to be a bright turkish blue.

The third block set the colour of the third LED based on how much green, blue and red there is in it. This colour is made by 80 green and 40 red, which give us a dark green colour.

The last block in the forever loop is the show block. The colour changes we have made will first take effect when we run the show block.

Since there isn't anything changing in this program we could actuelly have put the entire program into "On start".

Here is the program.

Step 6: Second Program

In the second program we have put the entire first program into "On Start"

On button A pressed (Når der trykkes på knappen A) we use the shift pixel command. This will move all the colour on step up. So the third LED get the colour of the second LED, the second LED gets the colour of the first LED and with the shift command the first LED will become blank. We also use the show block, because without the show block the LED would actuelly not change colour.

On button B pressed (Når der trykkes på knappen B) we use the rotate pixel command. This works very much like the shift command pixel command, but instead of the first LED becoming blank it will take the colour of the last LED. So the third LED get the colour of the second LED, the second LED gets the colour of the first LED and with the rotate command the first LED will get the colour of the third LED. We also use the show block, because without the show block the LED would actuelly not change colour.

On button A+B pressed (Når der trykkes på knappen A+B). The first block prints the estimated power use of the Neopixels on the mico:bit. The second block give us 2 second to read the estimate. The third block then clears the screen.

Here is the second program.