Controlling gpio 12 and 13 of respeaker 2

I’m trying to control the gpio 12 and 13 pins on the respeaker 2 hat from within node-red (installed in a docker-container).
If I could use these pins it would open a possibility to add infrared transmitter possibilities to the rhasspy-raspberry system.
I tried two ways to do it, but none of them works :frowning:
Here’s my node-red flow:
https://www.dropbox.com/s/oxcr5c3bzbmrb5k/gpioflow.json?dl=1

any idea how to do it using node-red (without making a modified node-red image)?

kind regards,
hugo

Yes, I did this last year successfully to control a button and a LED with Node-RED. I don’t have the configuration or flow at hand here, but what I remember is this:

  • I installed the node-red-node-pi-gpiod node in Node-RED.
  • I let this node communicate to the GPIOs with pigpiod, which I installed in a Docker container (I think it was the corbosman/pigpiod image). But running pigpiod directly on Raspberry Pi OS should be fine too.

Unfortunately node-red-node-pi-gpiod refuses to install in node-red at this very moment as can be seen in this log file:
https://www.dropbox.com/s/mtt62oav3z1qsov/2020-08-24T16_01_13_976Z-debug.log?dl=1

kind regards,
hugo

I’m not sure what is happening there. Maybe try these proposed solutions, this looks like the same issue: https://github.com/cncjs/cncjs/issues/172

I’m not sure what is happening there. Maybe try these proposed solutions, this looks like the same issue: https://github.com/cncjs/cncjs/issues/172

What do you mean by “there”?

  1. The node-red servers
  2. My particular installation

Another little question:
Is it safe to perform the following manoeuvre (to be able to directly enter npm-commands )?
Won’t that interfere with the node-red gui entered stuff?

docker exec -it node-red bash
or
docker container exec -u 0 -it node-red bash

kind regards,
hugo

I tried this:
docker exec -it node-red bash

npm install node-red-node-pi-gpiod

the thing installed but with this warning (after doing an npm-audit) :

Low Sensitive Data Exposure

Package put

Patched in No patch available

Dependency of node-red-node-pi-gpiod

Path node-red-node-pi-gpiod > js-pigpio > put

More info https://npmjs.com/advisories/1007

found 1 low severity vulnerability in 347 scanned packages

However even though it seemed to install, it was not visible/available in the node-red webinterface. And didn’t want to install there. So I removed it:
npm uninstall node-red-node-pi-gpiod

Your installation. I have never seen this error.

koan wrote:

Yes, I did this last year successfully to control a button and a LED with Node-RED. I don’t have the configuration or flow at hand here, but what I remember is this:

  • I installed the node-red-node-pi-gpiod node in Node-RED.
  • I let this node communicate to the GPIOs with pigpiod , which I installed in a Docker container (I think it was the corbosman/pigpiod image). But running pigpiod directly on Raspberry Pi OS should be fine too.

I installed pigpiod in node-red (using manage palette), this time it installed without problems.
I made the following docker-compose.yml

---
version: '3.7'

services:
 pigpiod:
  image: corbosman/pigpiod
  container_name: pigpiod
  restart: always
 rhasspy:
  image: rhasspy/rhasspy
  container_name: rhasspy
  restart: always
  volumes:
   - /home/pi/containers/rhasspy/profiles:/profiles
  ports:
   - 12101:12101
  devices:
   - /dev/snd:/dev/snd
  command: --user-profiles /profiles --profile nl
 node-red:
  image: nodered/node-red
  container_name: node-red
  restart: always
  volumes:
   - ./containers/node-red:/data
   - ./containers/certificates:/etc/ssl/private:ro
   - /etc/localtime:/etc/localtime:ro
  ports:
   - 1880:1880
   - 8888:8888
  environment:
   - TZ=Europe/Brussels
 mosquitto:
  image: eclipse-mosquitto
  container_name: mosquitto
  restart: always
  ports:
   - "1883:1883"
   - "9001:9001"
  volumes:
   - ./containers/mosquitto/config:/mosquitto/config
   - ./containers/mosquitto/data:/mosquitto/data
   - ./containers/mosquitto/log:/mosquitto/log
   - /etc/localtime:/etc/localtime:ro
  user: "1000:1000"

docker-compose up -d doesn’t give any error messages
However the node-red-flow I made to test it, doesn’t make my led at pin 12 light up.
I am puzzled by this text in the documentation of pigpiod:

If using with Docker on Pi then the default Host IP should be 172.17.0.1 . You will also need to run sudo pigpiod on the host.

However the host ip on my system is:
172.18.0.3
Should/Can I change that? How?
And does the ‘sudo pigdiod’-passage mean I should add a user-line to the pigpiod-part of the docker-compose.yml?

Here is the node-red flow:
https://www.dropbox.com/s/9gpr26p3vsqf62c/pigpiodflows.json?dl=1

kind regards,
hugo

I have no experience with pigpiod but to use gpios in docker you need to at least add a device to your docker compose. To get access to WiringPi via docker I needed to add those lines to my docker-compose, pigpiod might need something similar:

devices:
  - /dev/gpiomem:/dev/gpiomem
  - /dev/mem:/dev/mem
cap_add: 
  - SYS_RAWIO
privileged: true

You might only need some of those but my research to using gpio pins via docker told me at least one of them is needed, which depends on the library used and I only experimented with WiringPi

1 Like

Note that corbosman/pigpiod is supposed to run with the —privileged flag.

If you succeed to run it with your docker compose file, then accessing it is easy.

All container in a docker compose share by default the same sub network so the containers know each other by their name.

Your container is named pigpiod (using container_name) so you can use that as the host to access it. No need to access the host IP.

Hope this helps.

1 Like

Thanks for the replies fastjack and Daenara. I got it working:
I changed my docker-compose.yml to this:

---
version: '3.7'

services:
 pigpiod:
  image: corbosman/pigpiod
  container_name: pigpiod
  restart: always
  privileged: true
 rhasspy:
  image: rhasspy/rhasspy
  container_name: rhasspy
  restart: always
  volumes:
   - /home/pi/containers/rhasspy/profiles:/profiles
  ports:
   - 12101:12101
  devices:
   - /dev/snd:/dev/snd
  command: --user-profiles /profiles --profile nl
 node-red:
  image: nodered/node-red
  container_name: node-red
  restart: always
  volumes:
   - ./containers/node-red:/data
   - ./containers/certificates:/etc/ssl/private:ro
   - /etc/localtime:/etc/localtime:ro
  ports:
   - 1880:1880
   - 8888:8888
  environment:
   - TZ=Europe/Brussels
 mosquitto:
  image: eclipse-mosquitto
  container_name: mosquitto
  restart: always
  ports:
   - "1883:1883"
   - "9001:9001"
  volumes:
   - ./containers/mosquitto/config:/mosquitto/config
   - ./containers/mosquitto/data:/mosquitto/data
   - ./containers/mosquitto/log:/mosquitto/log
   - /etc/localtime:/etc/localtime:ro
  user: "1000:1000"

and changed the name of the host in the pigpiod-output node to pigpiod

I changed the node-red flow I did upload in the previous mail too.

thanks a lot for helping me out
kind regards,
hugo

Congrats :blush:
Now the fun part begins :nerd_face:
Can you flag this topic as « solved »?

Cheers

1 Like

I noticed that my respeaker-2 started acting strange after installing the corbosman/pigpiod

Suddenly the respeaker-2 started speaking slowly and with a very low bass voice. Music also played too slowly and frequencies were shifted to the low frequency range.
I reinstalled the drivers for the respeaker-2 but that didn’t help. Finally I removed the pigpiod container and restarted the raspberry. Now the respeaker-2 is acting normally again.

kind regards,
Hugo

That’s really weird! I searched in the ReSpeaker repository’s issues, but couldn’t find anything related. Maybe open an issue there?

1 Like

That’s really weird! I searched in the ReSpeaker repository’s issues , but couldn’t find anything related. Maybe open an issue there?

I have posted the issue in the issues-repository you mentioned

kind regards,
hugo

I think your pigpiod might be configured to use PCM as its clock peripheral, and that is also needed for the sound output of the respeaker. There is a option to choose either PWM or PCM. If you choose PWM instead the onboard headphone output will not work.
http://abyz.me.uk/rpi/pigpio/pigpiod.html
Try to run pigpiod with -t 0 option to choose PWM instead of PCM and the audio of your respeaker-2 should work again.

If i understand it right you can somehow pass those options to your container.

Unfortunately I don’t have any idea how to modify my docker-compose.yml to achieve that

kind regards,
Hugo

Try to add command: -t 0 to your pigpiod container…

Try to add command: -t 0 to your pigpiod container…

It works, thanks for the help fastjack and moqart
This is what I have now in my docker-compose.yml for pigpiod:
pigpiod:
image: corbosman/pigpiod
container_name: pigpiod
restart: always
privileged: true
command: -t 0

kind regards,
Hugo