Control LED's using C++ and SPI - Respeaker 4 Mic Array

Hi



I have just purchased a Respeaker 4 Mic Array for the Raspberry PI (Mine is Model 3B+) and i have installed the drivers and got the microphones working correctly. I then when on to install the Alexa for Raspberry PI (https://github.com/alexa/avs-device-sdk/wiki/Raspberry-Pi-Quick-Start-Guide-with-Script) which works well with the ReSpeaker 4Mic array.



I now want to extend the Alexa App which is written in C++ to control the LED’s on the ReSpeaker. I have run the python examples and the Raspberry PI can control the LEDs as expected.



I understand that the LED’s are controlled via the SPI interface. Do you have any example code in C++ to control the LED’s or any resources to do this.



Many thanks.



Peter Tewkesbury

Hello,



I’ve got exactly the same problem.



I would like to use led in C++ from Respeaker 4 Mic Array but I don’t find any samples.



I need help too.



Regards,

What about that one:

https://github.com/snipsco/snips-skill-respeaker

Hi there,


  1. You have to turn on the spi first.



    sudo raspi-config

    Go to “Interfacing Options”

    Go to “SPI”

    Enable SPI

    Exit the tool


  2. use gpio -v to verify if you install wiringpi library correctly.



    http://wiringpi.com/download-and-install/


  3. then you can create led.cpp file. you can understand the apa102 logic by reading <LINK_TEXT text=“https://cpldcpu.wordpress.com/2014/11/3 … -superled/”>https://cpldcpu.wordpress.com/2014/11/30/understanding-the-apa102-superled/</LINK_TEXT>

[code]#include <wiringPi.h>
#include <wiringPiSPI.h>
#include
#include <stdint.h>

int main() {
wiringPiSetup();
if(wiringPiSPISetup(0, 6000000) < 0) {
std::cerr << “wiringPiSPISetup failed” << std::endl;
}

pinMode (21, OUTPUT);
digitalWrite (21, HIGH);

uint8_t buf[1];
for(int i = 0; i < 4; i++) {
buf[0] = 0x00;
wiringPiSPIDataRW(0, buf, 1);
}

uint8_t r, g, b, brightness;
r = 0xFF;
g = 0x00;
b = 0x00;
brightness = 100;
uint8_t led_frame[4];

for(int i = 0; i < 12; i++) {
led_frame[0] = 0b11100000 | (0b00011111 & brightness);
led_frame[1] = b;
led_frame[2] = g;
led_frame[3] = r;

wiringPiSPIDataRW(0, led_frame, 4);

}

for(int i = 0; i < 4; i++) {
buf[0] = 0xFF;
wiringPiSPIDataRW(0, buf, 1);
}

delay(5000);

return 0;

}
[/code]


4. run below command to compile the file

g++ -Wall -o led led.cpp -lwiringPi


5. run below command

sudo ./led

thanks.