Starting and stopping a process via GPIO state

Hello everyone,

I am attempting to use a Raspberry Pi with OSMC/Kodi as a car stereo system, and want to start and stop a service (specifically, the service is “raspivid”) depending on the state of a GPIO pin.

This is a practical application of Pi Camera in OSMC - #6 by bmillham - I’m now trying to make the camera operate when the Pi detects the car is in reverse (I will have a GPIO pin set to go HIGH when reverse is selected).

I’m reaching my technical limits - I can work out how to start “raspivid”, and have it run for a set period of time - but in reality I want to be able to have “raspivid” run WHILE a certain condition is met…

Thanks,

Ewan

You can definitely do this. You can either monitor via a script or introduce udev rules to handle this.

My question is: when would you know when to stop raspivid?

Sam

Hello Sam,

it’s easy - raspivid only needs to run when the car is in reverse - to provide the reverse camera function. It can stop when the reverse signal is no longer present:

  1. I can use a GPIO to sense when the car is in reverse. When the GPIO input indicates the car is in reverse, the Pi needs to run raspivid.

  2. When the GPIO indicates the car is no longer in reverse, then the Pi needs to stop raspivid.

Of course, there’s an alternative - run raspivid (or similar) permanently, and only view the video when the reverse indication is present…

I had also looked at using an alternative method, whereby I used something else (Arduino, perhaps) to take the CSI stream from the camera, process it to a DSI signal, then switch the monitor input from the Pi to the camera module. Unfortunately, this looked a little more complicated!

Ewan

Hi

This is definitely a unique question, and not a typical one we receive here.

I think this thread: Triggering the Camera from GPIO pins - Raspberry Pi Forums will give you enough to go on. You could set the script to run from /etc/rc.local as a quick hack.

Sam