Demo: APA102 RGB LED

Zephyr RTOS driving RGB LEDS on CANHUBK344 board.

Introduction

This tutorial describes how to connect and operate APA102 LEDs on MR-CANHUBK3 board and control them using Zephyr RTOS.

Items needed

Items #9 and #10 could be replaced with any similar setup of 12 APA102 LEDs daisy chained together.

Hardware procedure

You will connect a SPI port (Zephyr lpspi4) on the CANHUBK344 Pin headers to drive the clock and data signal going to the APA102 LEDs. Note that in application, it may be desireable to use a different SPI connection and provide 5V power independently to the LEDs.)

Block diagram of CANHUBK344 connecting to string of APA102 LEDs, plus debugger and serial consolde.

Connections from APA102 to P8B (Connector that houses LPSPI4)

APA102 Pin
Name
Color
PIN # on connector P8B on CANHUBK344

1

Voltage

Red

2

2

Ground

Black

1

3

SPI Clock

Yellow

17 (LPSPI4 Clock)

4

SPI MOSI

Blue

18 (LPSPI4 MOSI)

Create your own SPI to STEMMA QT cable

Other SPI interfaces with JST-GH

Note there are also two other SPI interface on CANHUBK344 which have a 7 pin JST-GH plug. Alternatively a cable could be prepared to connect to one of these interefaces. Teh Zephyr overlay would need to also be modified to match the SPI port chosen.

Alternative sources for 5V LED power

SPI and Power connection on MR-CANHUBK344 header for LEDs in this Demo

P8B connector on CANHUBK3 for connecting APA102 LED to LPSPI4 in Zephyr
Wiring connections from APA102 to P8B (side view)

Software procedure

Initialize west workspace

mkdir apa102_canhubk3
west init -m git@github.com:zephyrproject-rtos/zephyr.git apa102_canhubk3
cd apa102_canhubk3
west update
cd zephyr
git checkout a04a1d8991e312ece8530f0ab35b444010113fb9
APA102 LED Patch
git apply apa102_canhubk3_v3.0.patch

Building & flashing "led_apa102" application

This application displays a 3-colour pattern (red - green - blue) that walks the strip until it reaches the end, then starts at the beginning again; by default, the delay between each message is 40 ms.

By default, this application is configured for 20 APA102 LED daisy chained together. Hence, you will see a delay in motion if you have less that 20 LEDs.

Optionally, you may change the value of the "STRIP_NUM_LEDS" macro in "zephyr/samples/drivers/led_apa102/src/main.c" to the number of LEDs in your setup.

west build -b mr_canhubk3 samples/drivers/led_apa102/ -p
west flash

Video demo 1

Demo video for "led_apa102" application

Building & flashing "led_apa102_indicators" application

This application demonstrates the lighting of turn indicators for vehicles. It cycles between the four turn indicators - front left, front right, back left and back right. These turn indicators have LED patterns respectively: 2 → 1 → 0, 3 → 4 → 5, 8 → 7 → 6 and 9 → 10 → 11.

west build -b mr_canhubk3 samples/drivers/led_apa102_indicators/ -p
west flash

Video Demo 2

Demo video for "led_apa102_indicators" application

LED Daisy Chain configuration

APA102 LED connection diagram for "led_apa102_indicators"
APA102 LED connection demonstration for "led_apa102_indicators"

Last updated