ReSpeaker LED manager
A simple management daemon for the ReSpeaker 4-mic LED ring
What is it?
The ReSpeaker 4-mic is a Raspberry Pi "hat" which provides an array of 4 microphones and an LED ring, and is used for audio input and user feedback for Pi-based voice control devices such as my own contraptions. This repository provides a simple daemon to manage the LED components in an asynchronous and extensible way, suitable to be called from another application such as Kalliope or via the CLI directly.
This daemon is based on the following components:
How to use it
- Clone this repo into an available directory (I use
cd /srv git clone <repo>
- Enable the service unit file:
systemctl enable /srv/respeaker-led/respeaker-led.service
- Start the service:
systemctl start respeaker-led.service
- Trigger a test command:
/srv/respeaker-led/trigger.py hold white 5
The client command processor. It sends its arguments to the
cmd_socket (by default
/run/respeaker-led.sock) of the daemon and then exits.
This is the main control daemon. It first opens a command pipe at
cmd_socket, then runs in a loop scanning for commands from the pipe and executing them.
A simple Systemd service unit file to run
daemon.py and restart it on failure. It features a nifty pre-start command to automatically
git pull the repo to ensure it's up-to-date (and simplifying administrator or developer work when modifying the daemon - just restart it to get the latest code!) Note that for my own purposes, running as a dedicated user on many independent Raspbian instances and pulling from my local protected GitLab instance, this requires a Git deploy SSH key located at
/srv/git-deploy.key; you should remove this if your setup does not require such security methods (which a clone from GitHub would not). You should also modify the daemon user and group as required.
$ daemon.py [<user>:<group>]
- The user and group names that should own the
cmd_socketfile (mode 644); defaults to
root:rootif not set or invalid
$ trigger.py <action> [<colour>] [<holdtime>]
- none: Print usage
- off: Turn off LEDs (unless held)
- on: Turn on LEDs until next off action
- flash: Flash LEDs until next off action
- hold: Keep LEDs on for some time unless overridden
- The duration in seconds to keep the LEDs on (
holdaction only); defaults to 3 seconds if not set
For a full description of the entire project, please see this post on my website.
My main use-case for this daemon, and hence my selection of valid colours, "patterns", and functions, is as a visual user feedback device for a Kalliope instance which does not produce any sound responses. To achieve this, the Kalliope instance calls
trigger.py directly from the
shell neuron inside its "hook" orders, which are built-in to Kalliope. The following Kalliope
brain.yml section provides a description of how the functions and colours are used in this context.
- name: "on-triggered-synapse" signals:  neurons: - shell: cmd: /srv/respeaker-led/trigger.py on white - name: "on-waiting-for-trigger-synapse" signals:  neurons: - shell: cmd: /srv/respeaker-led/trigger.py off - name: "on-start-listening-synapse" signals:  neurons: - shell: cmd: /srv/respeaker-led/trigger.py on blue - name: "on-stop-listening-synapse" signals:  neurons: - shell: cmd: /srv/respeaker-led/trigger.py off - name: "on-order-found-synapse" signals:  neurons: - shell: cmd: /srv/respeaker-led/trigger.py hold green 3 - name: "on-order-not-found-synapse" signals:  neurons: - shell: cmd: /srv/respeaker-led/trigger.py hold red 3 - name: "on-start-synapse" signals:  neurons: - shell: cmd: /srv/respeaker-led/trigger.py flash magenta - shell: cmd: /bin/sleep 4.5 # Just long enough for 5 blinks
Of course, Kalliope isn't the only possible use-case for this daemon, so feel free to adapt it to suit your needs!
This project is licensed under the GNU GPL version
3.0 or any later version.