This advanced project shows you how you can drive a 16 NeoPixel ring and Sharp IR distance sensor using an inexpensive ARM Cortex M0+ LPC824. The LPC824 was used due to it's low cost, and an interesting peripheral it has called the State Configurable Timer, which allows us to offload the tight NeoPixel timing requirements to a HW peripheral.

This project is not based on the Arduino IDE, and uses an Eclipse-based IDE that is designed for this MCU family. Bare metal software development gives you full control over the software development process, but also has a higher learning curve and this should be considered an advanced project as such.

This was largely a personal project, wanting to keep up to date with recent members of the LPC800 device family from NXP, but it's being published here in the hope that it proves useful to other people interested in driving NeoPixels with a small, but powerful and flexible MCU like the LPC824!

Hardware Requirements

End Result

The final project will give you something resembling this:

This project is not based on the Arduino IDE, and uses an Eclipse-based IDE that is designed for this MCU family. Bare metal software development gives you full control over the software development process, but also has a higher learning curve and this should be considered an advanced project as such.

The project was written entirely in C using the free cross-platform LPCXpresso IDE (version 8.2.2 specifically). To add support for the LPC824 MCU, the LPC824 Code Bundle for LPCXpresso (version 1) was also downloaded and installed.

You can perform the following steps to make the software available locally on your development machine:

  1. Download and install the LPCXpresso 8.2.2 IDE for your operating system
  2. Download the LPC824 Code Bundle for LPCXpresso (version 1)
  3. Download the Project Code Bundle, available as a .zip file in the Github repo.

Importing the LPC824 Code Bundle

Before you can import the project files, you need to import the LPC824 Code Bundle, which includes all the low level drivers for this project:

  • Click the Import Projects button in the QuickStart menu in the bottom right-hand corner of the IDE:
  • In the dialogue box that pops up, select the appropriate .zip file in the Archive field:
  • Click the Finish button to import the files, which should results in your Project Explorer looking like this:

Importing the Project Code Bundle

Next, you need to import the project code bundle, which is provided as a .zip file for easy import.

  • Select the Import project menu option again in the Quickstart window:
  • Now point to the project Code Bundle in the Archive field:
  • Click the Finish button and you should have a new project in the Project Explorer called lpc824_neopixel:

You can expand this menu option to see the source code for this project, double-clicking on main.c to see the project entry point:

  • At this point, you can access and modify the source code if required:

NeoPixel Setup

The included project supports both RGB and RGBW NeoPixels, and you can adjust the number of NeoPixels present if you aren't using an identical NeoPixel layout.

Before proceeding any further, make sure the following two values are set to match the NeoPixel setup you are using (these can be found in main.c):

Set WS2812_LED_CLRS to 3 for RGB NeoPixels or 4 for RGBW NeoPixels!
#define	WS2812_LED_CNT	(16)
#define WS2812_LED_CLRS	(3)					// 3 = RGB, 4 = RGBW

Compiling the Project

To make sure everything is installed correctly, you can try to compile the project as follows:

  • Make sure that the correct project is selected in the Project Explorer window on the left-hand side of the IDE
  • Connect your LPCXpresso824-Max board to your development machine via the USB cable (the board includes an on board SWD debugger that will be used to flash and debug the LPC824 MCU)
  • Select the Project > Build Project menu item to build the project as well as any project depencies (peripherals and utilities libraries in this case):
  • Optionally, you can select the Build 'lpc824_neopixel' (Debug) QuickStart menu item:
  • If you get a popup dialogue box (this should only appear once) select the lpc824_neopixel Debug profile, as shown below, then click the Run button:
  • If everything worked correctly, you should see the compilation results in the Console window at the bottom of the IDE:
  • To flash and run the compiled software, click the Debug 'lpc824_neopixel' (Debug) QuickStart menu item with the board connected to your machine:
  • This will cause the IDE to connect to the debugger, flash the sketch, and stop code execution at the project entry point, which is main(void):
  • To continue code execution use the Resume (F8) or other toolbar icons or keyboard shortcuts:

Pinout

To run this demo, connect the NeoPixel ring to the LPC824Max development board as follows:

  • Connect the DATA/DIN pin on the Neopixels to P0.22 (A3 on the LPC824MAX Arduino header)
  • Connect Power 5V DC on the NeoPixel to the +5V pin on the LPC824Max
  • Connect GND on the NeoPixel to GND on the LPC824Max

Then connect the Sharp IR distance sensor as follows:

  • Connect the yellow cable (analog output) to P0.6 (A0 on the LPC824Max Arduino header)
  • Connect the red cable to the +5V pin on the LPC824 Max
  • Connect the black cable to GND on the LPC824Max

Physical Wiring Details

There are numerous ways to solder this project together, depending on the project requirements, but for convenience sake the NeoPixel ring and Sharp IR Sensor were connected to the LPC824MAX development board with silicon wiring since it's heat resistant, flexible, and is easy to work through the back of the enclosure.

The ends of the two sets of three cables were soldered to two sets of 3-pin wide 0.1" male headers pins, which were then inserted into a tiny breadboard:

You may require something more robust if the project is likely to be moved a lot, such as a small piece of proto PCB!

3D Printed Enclosure

To get the project off the table and into a usable form factor, a 3D printed enclosure was designed for the NeoPixel ring and the Sharp IR distance sensor.

The STL files are available with the source code on Github, and consist of two mandatory parts, and an optional third part:

  • Standv1.stl: A stand to support the NeoPixel ring and Sharp IR sensor
  • Neopixelv5.stl: A circular enclosure for the NeoPixel ring and Sharp IR sensor that can be screwed onto the base
  • Neopixelv5_diffuserv4.stl: An optional third diffusion ring that can be printed in a semi-opaque material and snapped on top of the circular enclosure if desired

Preview

A rendered image of the various parts can be seen below. The development board and wires aren't shown.

This guide was first published on Apr 20, 2017. It was last updated on Apr 20, 2017.