How to enable remote GPIO

Hello,

I am wondering if anyone has had any success in getting pigpio daemon pigpiod to run on a raspberry pi 3? I have written a .sh startup script with this simple command:

systemctl enable pigpiod

I then get the following error:

Failed to enable unit, unit pigpiod.service does not exist

When I google this I run into some folks talking about having to setup config.txt or raspi-config to enable “remote gpio”

So the question would be how to do this with Balena? Is it an environmental variable and if so how do I set it up?

If not, any other ideas?

Thanks for your help,

Greg

You’ll need to install pigpio before using it.
Also balena base images don’t use systemd by default. I guess you are using an old base image.
Please check https://github.com/guymcswain/pigpio-client/wiki/Install-and-configure-pigpiod

Try a Dockerfile like this (not tested):

FROM balenalib/raspberrypi3-debian:buster-build
RUN apt-get update && apt-get install build-essential unzip wget
WORKDIR /usr/src/app
RUN wget https://github.com/joan2937/pigpio/archive/master.zip
RUN unzip master.zip
WORKDIR /usr/src/app/pigpio-master
RUN make
RUN make install
CMD pigpiod

Thanks zvin,

This helped a little. Now I no longer see the error “Failed to enable unit, unit pigpiod.service does not exist” however there is still an issue with connecting to it. I am getting this additional error:

main Can’t connect to pigpio at localhost(8888)
main Did you start the pigpio daemon? E.g. sudo pigpiod
main
main Did you specify the correct Pi host/port in the environment
main variables PIGPIO_ADDR/PIGPIO_PORT?
E.g. export PIGPIO_ADDR=soft, export PIGPIO_PORT=8888
main
main Did you specify the correct Pi host/port in the
main pigpio.pi() function? E.g. pigpio.pi(‘soft’, 8888)

When I read online there are several mentions of having to turn on “remote gpio” in raspi-config. However that is usually done in Balena by Variables that we set in the device configuration correct?

Any other ideas?

Thanks,
Greg

1 Like

Hello @tofino,

What command(s) are you trying to run when you get the Failed to enable unit, unit pigpiod.service does not exist error?

There’re also some tests included in the repository that you could run to see if pigpiod is working:

./x_pigpiod_if2 # test the C I/F to the pigpio daemon
./x_pigpio.py   # test the Python I/F to the pigpio daemon
./x_pigs        # test the socket I/F to the pigpio daemon
./x_pipe        # test the pipe I/F to the pigpio daemon

Let us know what the results of those tests are.

Cheers,
Nico.

I am trying a totally new approach now which is to try to split pigpiod into its own service container. In my .yml file I expose port 8888 on the pigpio service and then make my other container dependent on it. It looks like it might work but the issue I am having is that both containers are now constantly exiting and restarting. I found another topic on this Container stuck continuously restarting but not sure if that is the issue.

Any suggestions on how to prevent these containers from constantly restarting?

Greg

Hi @tofino,

This sounds like the services are starting their commands, and then exiting, which is why the Supervisor is restarting the containers. Could you paste your Dockerfiles and docker-compose.yml manifest here, that would allow us to see what might be going on.

Best regards,

Heds

Docker-compose:

version: ‘2’
services:
pigpio:
build: ./pigpio
privileged: true
network_mode: host
restart: always
expose:
- “80”
- “8888”
labels:
io.resin.features.supervisor-api: ‘1’
io.resin.features.resin-api: ‘1’
io.resin.update.strategy: download-then-kill
motors:
build: ./motors
privileged: true
network_mode: host
restart: always
depends_on:
- pigpio
ports:
- “5000”
labels:
io.resin.features.supervisor-api: ‘1’
io.resin.features.resin-api: ‘1’
io.resin.update.strategy: download-then-kill

pigpio docker template:

FROM balenalib/raspberrypi3-python:3.7.6
ENV DEBIAN_FRONTEND=noninteractive
ENV DEBCONF_NOWARNINGS yes
RUN apt-get update -y;
apt-get upgrade -y;
apt-get clean all
RUN apt-get update -y;
apt-get install -qy apt-utils
build-essential
unzip
wget
python3-pip
git
libtool
python3-dev
python3-smbus
libtool
rpi-update
raspi-config
systemd
WORKDIR /usr/src/app
RUN wget https://github.com/joan2937/pigpio/archive/master.zip
RUN unzip master.zip
WORKDIR /usr/src/app/pigpio-master
RUN make
RUN make install
COPY . ./
ENV INITSYSTEM on
CMD [“bash”, “./start.sh”]

Motors Docker Template:

FROM balenalib/raspberrypi3-python:3.7.6
ENV DEBIAN_FRONTEND=noninteractive
ENV DEBCONF_NOWARNINGS yes
RUN apt-get update -y;
apt-get upgrade -y;
apt-get clean all
RUN apt-get update -y;
apt-get install -qy apt-utils
build-essential
unzip
wget
python3-pip
git
libtool
python3-dev
python3-smbus
libtool
rpi-update
raspi-config
systemd
RUN sudo pip3 install --upgrade pip
RUN sudo pip3 install setuptools --upgrade pip
COPY ./requirements.txt /requirements.txt
RUN sudo pip3 install -r requirements.txt
WORKDIR /usr/src/app
RUN wget https://github.com/joan2937/pigpio/archive/master.zip
RUN unzip master.zip
WORKDIR /usr/src/app/pigpio-master
RUN make
RUN make install
COPY . ./
ENV INITSYSTEM on
CMD [“python3”, “motor_test_2.py”]

the start.sh file used by CMD in pigpio container is only this single line:

pigpiod

Hi again,

Thanks for these. I notice that you’re trying to use systemd as an init system. The balenalib base images do not include systemd, and so the ENV INITSYSTEM on command will not work. There’s some documentation on these changes here: https://www.balena.io/docs/reference/base-images/base-images/#major-changes which include directions on how you could install your own init system, including systemd.

I suspect this is the root cause of this issue.

Best regards,

Heds

Thanks everyone. I removed all the systemmd and INIT stuff and I have it running now back in a single container. I kept getting this error “init mbox zaps failed” each time it would upload and restart with latest build. Then I found this article in regards to this issue https://raspberrypi.stackexchange.com/questions/29983/pigpio-initialization-failing-with-init-mbox-zaps-failed . I rebooted and it started working. I then went in and upped my GPU memory to 32 and the reboot was not longer required. I also went back to simple approach of apt-get install of pigpio \ python-pigpio \ python3-pigpio and they all worked instead of the more complicated install build ZVIN had suggested above. So I think I am all good.

Thanks everyone.

2 Likes

How did you increase your GPU memory?