Main Content

Control NeoPixel LEDs Using On-Board EEPROM on Arduino

This example shows how to use the Simulink® Support Package for Arduino® Hardware to use the Adafruit® NeoPixel Digital LED strip and Arduino on-board EEPROM to create different lighting effects and patterns in External mode and Connected IO modes.

The NeoPixel LED strip has 24 digital RGB LEDs mounted in a ring fashion. Using the NeoPixel block, you can control the glowing pattern of these LEDs simultaneously and create many colorful lighting effects and patterns. You can specify the EEPROM address to read and write the NeoPixel LED RGB triplet values using the On-board EEPROM Read and On-board EEPROM Write blocks.

You can validate the output on the NeoPixel LED strip using the External mode and Connected IO mode. In Connected IO mode, the LEDs glow successively in different colors creating a chasing effect. In the External mode, a group of eight LEDs glow collectively.

You can explore different lighting effects and patterns based on these factors:

  • Supported Arduino board

  • Available on-board EEPROM memory size

  • NeoPixel LED strip type (RGB or RGBW)

For more information on choosing the Arduino board according to the on-board EEPROM memory size and the accessible address range, see the On-board EEPROM Read and On-board EEPROM Write blocks.

Supported Arduino Boards

  • Arduino Mega 2560

  • Arduino Mega ADK

  • Arduino Uno

  • Arduino Leonardo

  • Arduino Micro

  • Arduino Nano 3.0

Required Hardware

  • Any supported Arduino hardware boards. This example uses the Arduino Mega 2560 board that has 4 KB of on-board EEPROM memory.

  • Adafruit NeoPixel Digital LED strip. This example uses the RGB color format LED type.

  • Connecting wires

Hardware Setup

Make these connections between the Arduino board and the NeoPixel LED strip.

Open the arduinoNeoPixelControlUsingEEPROM Simulink model.

You can configure the Simulink model for Tune and Monitor Model Running on Hardware and Communicate with Hardware Using Connected IO. The NeoPixel block in both the modes use the same configuration parameters.

  1. Set Digital pin (Din) to 9. The example uses the Arduino Digital Input pin number 9 to communicate with the NeoPixel LED strip. You can configure the LED strip to any other Arduino Digital Input pin and indicate the same in this parameter accordingly.

  2. Set No. of pixel to 24, Color format of pixel to GRB, and Frequency of pixel to 800HHz. The example uses a 24 LED NeoPixel strip in the RGB color format and receiving the data from the Arduino board at 800KHz frequency. You can configure these parameters according to your application.

  3. Adjust the brightness level of NeoPixel LEDs. In this example, the brightness input to the block is maximum.

External Mode

In this example, for the External mode, a set of eight NeoPixel LEDs out of 24 illuminate every four seconds creating a cycling effect. The External Mode area includes the Initialize subsystem that triggers the Initialize Function block with every write operation on the Arduino on-board EEPROM. For more information, see Event Listener. The On-board EEPROM Write writes RGB pixel values of colors saffron, white, and green followed by cyan, yellow, and magenta starting from the memory location that you specify in the Start address parameter of the block. The Read RGB color values from Arduino on-board EEPROM subsystem retrieves the RGB color data using the On-board EEPROM Read block. The two color sets are alternatively read every 10 seconds. The data is then reshaped, transposed, and converted into a Nx3 format where, N=24 (number of LEDs on the NeoPixel strip). Configure the same memory address in the On-board EEPROM Read and On-board EEPROM Write blocks.

Connected IO Mode

In this example, for Connected IO mode, each LED on the NeoPixel strip lights up consecutively for every second creating a LED chase effect. Consecutive memory location on the Arduino on-board EEPROM store saffron, white, and green triplet values using the On-board EEPROM Write block. These RGB triplet values are individually read using the On-board EEPROM Read block. These triplet values are then fed as an input to the NeoPixel block through a multiport switch. Configure the same memory address in the On-board EEPROM Read and On-board EEPROM Write blocks.

Run Simulink Model in Connected IO Mode

Follow these steps to run the Simulink model in Connected IO mode.

  1. Select all the subsystems in the External Mode area. Right-click and select Comment Out.

  2. On the Hardware tab of the Simulink model, in the Mode section, select the *Connected IO (inputs/outputs mode) drop-down.

  3. In the Run on Computer section, click the Run with IO drop-down and select Simulation Pacing. On the Simulation Pacing Options dialog box, select Enable pacing to slow down simulation.

  4. Click Run with IO. Observe that eight NeoPixel LEDs glow with the same color for one second each and create an LED chase effect.

Run Simulink Model in External Mode

Follow these steps to run the Simulink model in External mode.

  1. Select all the subsystems in the Connected IO area. Right-click and select Comment Out. Then, select all the subsystems in the External Mode area. Right-click and select Uncomment.

  2. On the Hardware tab of the Simulink model, in the Mode section, select the Run on board (External mode) drop-down.

  3. In the Run on Hardware section, click Monitor & Tune. Observe that each NeoPixel LED glows for one second each and follows the color pattern of saffron, white, and green.

See Also