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
S. No. | Name | Quantity |
---|---|---|
1 | 1 | |
2 | USB-A (Male) to 2-Wire (Female) Power Cable | 1 |
3 | 1 | |
4 | 1 | |
5 | JST GH 1.25mm Pitch 7 Pin Cable (Female to Female) | 1 |
6 | 1 | |
7 | 1 | |
8 | 1 | |
9 | 3-LED (daisy chained) APA102 Strip | 4 |
10 | 4 |
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.)
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
You will need to convert one end of a STEMMA QT / Qwiic JST SH 4-Pin Cables to female connectors in order to plug into the male pins of the P8B port.
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
NOTE the power available from the 5V supply on MR-CANHUBK344 is limited. It is quite likely that too many LEDs fully illuminated will draw too much power from the board. In this case 5V power should be supplied from somewhere else. Good options are: - A "BEC" (RC Hobby DC-DC converter) that is typically used to supply 5V to servos. - The 5V power output from PDB board on the MR-B3RB (NXP Buggy3 RevB)
SPI and Power connection on MR-CANHUBK344 header for LEDs in this Demo
Software procedure
Initialize west workspace
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.
Video demo 1
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.
Video Demo 2
LED Daisy Chain configuration
This application requires 12 APA102 LED daisy chained together as explained in the diagram below, but due to hardware constraints videos above show only the first 9 LED.
Last updated