Need detailed help on automatic activation of backup camera

gwynethh
Posts: 41
Joined: Sat Aug 09, 2025 4:53 pm

Need detailed help on automatic activation of backup camera

Post by gwynethh »

After going thru a relocation of USB hardware (away from the Pi ports) and a full software reload, I have reached my penultimate issue. I see the developers have provided at least one option to automatically display the backup USB camera I think. They have provided "ReverseCamera.py" which I guess was to do this. However being Python (or HTML or Fortran or Basic) challenged I do not see how I can use a GPIO pin going high (say BCM7 or BCM17) to activate the viewing of the reverse camera.

So has anyone done this? How? Details please TIA.
hudiy
Site Admin
Posts: 515
Joined: Mon Jul 14, 2025 7:42 pm

Re: Need detailed help on automatic activation of backup camera

Post by hudiy »

We are currently working on examples for using GPIO with Hudiy which will be available on our GitHub soon.
Hudiy Team
hudiy
Site Admin
Posts: 515
Joined: Mon Jul 14, 2025 7:42 pm

Re: Need detailed help on automatic activation of backup camera

Post by hudiy »

The examples should be available on our GitHub later this week, along with the new release. In the meantime, you can try using this Python script (adjust the GPIO number and the pull_up to your needs https://gpiozero.readthedocs.io/en/stab ... tml#button).

You can drop the script into the examples directory of the repository downloaded from our GitHub (https://github.com/wiboma/hudiy/tree/ma ... api/python) as it has dependencies on the API.

Also following dependencies must be installed to make it work:

Code: Select all

sudo apt install -y python3-gpiozero python3-protobuf python3-websocket
ReverseCameraGPIO.py

Code: Select all

import common.Api_pb2 as hudiy_api
from common.Client import Client, ClientEventHandler
from gpiozero import Button


class EventHandler(ClientEventHandler):

    def __init__(self):
        self._gpio_button = Button(26, bounce_time=0.05)

    def on_hello_response(self, client, message):
        print(
            "received hello response, result: {}, app version: {}.{}, api version: {}.{}"
            .format(message.result, message.app_version.major,
                    message.app_version.minor, message.api_version.major,
                    message.api_version.minor))

        self._gpio_button.when_pressed = lambda: self.send_reverse_camera_status(
            client, True)
        self._gpio_button.when_released = lambda: self.send_reverse_camera_status(
            client, False)

    def send_reverse_camera_status(self, client, visible):
        set_reverse_camera_status = hudiy_api.SetReverseCameraStatus()
        set_reverse_camera_status.visible = visible
        client.send(hudiy_api.MESSAGE_SET_REVERSE_CAMERA_STATUS, 0,
                    set_reverse_camera_status.SerializeToString())


def main():
    client = Client("reverse camera gpio example")
    event_handler = EventHandler()
    client.set_event_handler(event_handler)
    client.connect('127.0.0.1', 44405)

    active = True
    while active:
        try:
            active = client.wait_for_message()
        except KeyboardInterrupt:
            break

    client.disconnect()


if __name__ == "__main__":
    main()
Hudiy Team
Tommiedw
Posts: 17
Joined: Wed Feb 18, 2026 11:01 am

Re: Need detailed help on automatic activation of backup camera

Post by Tommiedw »

Could you maybe assist with the API script. I created the script and made sure the common directories are in the same folder. If I run the script without Hudiy running it fails. But if I run Hudiy and switch windows and run it in the terminal it works perfect. Do I need to place the python script in a specific location to load with Hudiy at startup?
hudiy
Site Admin
Posts: 515
Joined: Mon Jul 14, 2025 7:42 pm

Re: Need detailed help on automatic activation of backup camera

Post by hudiy »

The script assumes that Hudiy is already running. You can either execute it after Hudiy starts up (e.g., in $HOME/.hudiy/share/hudiy_startup.sh after the $HOME/.hudiy/share/hudiy command or in $HOME/.config/labwc/autostart) or add simple logic to keep reconnecting to the API endpoint until Hudiy starts, based on the idle_screen or charts examples:

https://github.com/wiboma/hudiy/blob/ma ... /charts.py
https://github.com/wiboma/hudiy/blob/ma ... _screen.py

Code: Select all

import common.Api_pb2 as hudiy_api
import time
from common.Client import Client, ClientEventHandler
from gpiozero import Button


class EventHandler(ClientEventHandler):

    def __init__(self):
        self._gpio_button = Button(26, bounce_time=0.05)

    def on_hello_response(self, client, message):
        print(
            "received hello response, result: {}, app version: {}.{}, api version: {}.{}"
            .format(message.result, message.app_version.major,
                    message.app_version.minor, message.api_version.major,
                    message.api_version.minor))

        self._gpio_button.when_pressed = lambda: self.send_reverse_camera_status(
            client, True)
        self._gpio_button.when_released = lambda: self.send_reverse_camera_status(
            client, False)

    def send_reverse_camera_status(self, client, visible):
        set_reverse_camera_status = hudiy_api.SetReverseCameraStatus()
        set_reverse_camera_status.visible = visible
        client.send(hudiy_api.MESSAGE_SET_REVERSE_CAMERA_STATUS, 0,
                    set_reverse_camera_status.SerializeToString())


def main():
    client = Client("reverse camera gpio example")
    event_handler = EventHandler()
    client.set_event_handler(event_handler)

    try:
        while True:
            try:
                client.connect('127.0.0.1', 44405)
                while True:
                    if not client.wait_for_message():
                        break
            except Exception:
                pass
            time.sleep(2)
    except KeyboardInterrupt:
        pass
    finally:
        client.disconnect()


if __name__ == "__main__":
    main()
Hudiy Team
Tommiedw
Posts: 17
Joined: Wed Feb 18, 2026 11:01 am

Re: Need detailed help on automatic activation of backup camera

Post by Tommiedw »

Ok great, got it working! Thanks as always :)
gwynethh
Posts: 41
Joined: Sat Aug 09, 2025 4:53 pm

Re: Need detailed help on automatic activation of backup camera

Post by gwynethh »

Thanx for the help. Sadly I ran into a problem right of the start. "sudo apt install -y python3-gpiozero python3-protobuf python3-websocket" returns an error message of
"gwyneth@CarPi:~ $ sudo apt install -y python3-gpiozero python3-protobuf python3-websocket
Package python3-protobuf is not available, but is referred to by another package.
This may mean that the package is missing, has been obsoleted, or
is only available from another source

Error: Package 'python3-protobuf' has no installation candidate
Error: Unable to locate package python3-websocket
gwyneth@CarPi:~ $ "

also I am confused about "You can drop the script into the examples directory of the repository downloaded from our GitHub (https://github.com/wiboma/hudiy/tree/ma ... api/python) as it has dependencies on the API.You can drop the script into the examples directory of the repository downloaded from our GitHub (https://github.com/wiboma/hudiy/tree/ma ... api/python) as it has dependencies on the API.

where should I place "ReverseCameraGPIO.py" on my machine?

Sorry for these noob questions
hudiy
Site Admin
Posts: 515
Joined: Mon Jul 14, 2025 7:42 pm

Re: Need detailed help on automatic activation of backup camera

Post by hudiy »

What Raspberry Pi OS version are you using?

Try to execute the sudo apt update command before the sudo apt install .... It will refresh the list of the available packages. After that, please redo the sudo apt install -y python3-gpiozero python3-protobuf python3-websocket command.

The scripts are now available on our GitHub, so you can just clone the entire repository and run the script from there

Code: Select all

sudo apt install git
cd
git clone git@github.com:wiboma/hudiy.git
python3 $HOME/hudiy/examples/gpio/ReverseCamera.py
Hudiy Team
gwynethh
Posts: 41
Joined: Sat Aug 09, 2025 4:53 pm

Re: Need detailed help on automatic activation of backup camera

Post by gwynethh »

Thanx. I will try that tomorrow. I am running latest and updated Trixie 64 bit
gwynethh
Posts: 41
Joined: Sat Aug 09, 2025 4:53 pm

Re: Need detailed help on automatic activation of backup camera

Post by gwynethh »

Sadly again a failure after the first suggested step of sudo apt update. error message below


gwyneth@CarPi:~ $ sudo apt install -y python3-gpiozero python3-protobuf python3-websocket
Package python3-protobuf is not available, but is referred to by another package.
This may mean that the package is missing, has been obsoleted, or
is only available from another source

Error: Package 'python3-protobuf' has no installation candidate
Error: Unable to locate package python3-websocket
gwyneth@CarPi:~ $

bummer
Last edited by gwynethh on Tue Apr 07, 2026 10:18 pm, edited 2 times in total.
Post Reply