
Guide for using WS2812B LED Strips with MXChip
6 - 7 minutes
Introduction
This guide will walk you through how to connect and control a WS2812B individually addressable RGB LED strip to the MXChip.
Materials
Breakout Board
Apart from the LED strip you will also need a breakout board for the MXChip so we can access all of the boards pins. The MXChip's 'connecting finger' is the same as that on the BBC micro:bit which allows any breakout boards designed for the micro:bit compatible with the MXChip. In this guide i will be using the Kitronik edge connector breakout board but other boards should be very similar, if not the same.
Jumper Wires
In order to connect the LED strip to the breakout board we need wires. Breadboard jumper wires are inexpensive and come in Male-Male, Male-Female and Female-Female, perfect for connecting everything up. I got 120 wires for £6 on Amazon.
Wiring
Now that we have all the materials needed its time to wire the LED strip up to the breakout board. The LED strip's connector should have three wires; Live, Ground and Data. On my LED strip the ground wire is coloured white and is on the left, this is followed by a green data wire in the middle which leaves a red wire on the right. Wire the Red live wire up the 3V output, the white wire to ground (0V) and the data wire to any of the data pins.

Pin Mapping
As the breakout board we are using was designed for the micro:bit the pin numbers on the board and in software do not match up. In the bellow tables you can see the mapping from the Kitronik breakout board to the numbers that the MXChip will understand.
MXChip | Breakout Board | Code number |
---|---|---|
Reset | 3 | N/A |
Pin | 0 | 16 |
Pin | 4 | 5 |
A Button | 5 | 4 |
Red LED | 6 | 20 |
Green LED | 7 | 19 |
Pin | 1 | 22 |
User LED | 8 | 45 |
IR LED | 9 | 26 |
Blue LED | 10 | 39 |
B Button | 11 | 10 |
MXChip | Breakout Board | Code number |
---|---|---|
WiFi LED | 12 | 18 |
Pin | 2 | 23 |
Pin | 13 | 29 |
Pin | 14 | 30 |
Pin | 15 | 31 |
Pin | 15 | 31 |
Pin | 16 | 38 |
3.V | 3V | N/A |
I2C | 19 | 24 |
I2C | 20 | 25 |
GND | 0V | N/A |
The Code
The first thing you will need is the header and cpp files to drive the LED strip. These were written by microsoft and provide some nice helper functions and some test routines to light up the LEDs. These files can be downloaded at the bottom of this guide in the Files section.
Once those files have been downloaded and extracted into your workspace we can finally light the LED strip up!. The code provided below will run the strip through three different programmes, be sure the change NUMBER_OF_LED and LED_PIN to the correct values for your setup.
#include "neopixel.h"#define NUMBER_OF_LED 72 // This is the number of LEDs in your stripPinName LED_PIN = PB_6; // This is the pin you plugged the data wire intostatic NeoPixel *neopixel = NULL;static int test = 0;static bool runTest = false;void setup(){neopixel = new NeoPixel(LED_PIN, NUMBER_OF_LED);runTest = neopixel->init();}void loop(){if (runTest){switch (test % 3){case 0:Serial.println("Rainbow...");neopixel->showRainbowCycle(60, 25, 20, 200);neopixel->showColor(0, 0, 0);break;case 1:Serial.println("Theatre-style crawling lights...");neopixel->showTheaterChase(236, 19, 122, 500);neopixel->showColor(0, 0, 0);break;case 2:Serial.println("Detonate...");neopixel->showDetonate(236, 19, 122, 800);neopixel->showColor(0, 0, 0);break;}test++;}wait_ms(2000);}
From here you can create your own animations and more using the neopixel->showColor() and neopixel->setColor() commands that allow you to set the strip and individual LED's colours respectively.
Files
Driver.zip The header and cpp needed to drive the LED strip
2.8 kB
Example_Project.zip A ready to flash project with the test script.
6.4 kB