Toggle GPIO from host at startup


I have a LTE hat/shield for my Raspberry Pi. I want to use this for internet backhaul connectivity. ModemManager can use the hat, but to power on the hat I need to toggle GPIO18 low for 1 second. Only after powering on the hat I have a serial connection to talk to the modem, and only then ModemManager can detect and use the modem.

Is there a way to install a simple systemd service on the host that will run before ModemManager starts up, and which can toggle the GPIO for me?

Raspberry Pi + SIM800 for GPRS

Hi @jpmeijers,

You could toggle the GPIO when your container applications starts.

Then ModemManager should start the connection on your modem.


Yes, in theory this is possible, but not an ideal solution. Managing network connections and making sure there is an internet connection is a job for the host. Then also how do one deploy a container to a system if the host can’t make the internet connection?

I also do not think it’s a good solution to have to deploy a second container just to dial the LTE connection. Let’s follow isolation of responsibility principles and leave the dialling of the LTE to the host.

So how can one make the host manage the LTE modem, including resetting it and powering it up at system startup? Maybe we can use UMTSkeeper in conjunction with some custom scripts? Or is ModemManager good enough?


Hi @jpmeijers,

You could preload an image with an application container so you have the container running without internet access:

If you don’t want to do this from the container, this can be done from hostOS.

If your modem is supported by our OS then you should only add a systemd script that toggles the GPIO and udev + ModemManager should take care of connecting.

To add a systemd service to your board you could use multiple methods.

Method 1
Remount your board’s fs as RW:
mount -o remount,rw
Add your systemd service that toggles the GPIOS in the /lib/systemd/system folder
Enable your service with: systemctl enable your_service_name


  • you need to do this manually for every board
  • if you do hostOS updates you will lose your service

Method 2:
Clone our RPi repo and build your own OS where you add a package into the build that contains your systemd service

  • some Yocto know-how is needed, but not very complicated

Method 3
Pay Balena for custom device type and we will maintain an image for your board.


  • you need to pay



Ahh yes, using systemd on the host to do this is indeed a more elegant solution. It’s unfortunate that an OS update will override it.

Is there any way one can install a systemd service from a script in the /boot partition, similar to how udev rules are installed from the config.json file?


Hey @jpmeijers,

There isn’t a way to do that.