'how to remotely control raspberry pi gpio
I'm doing a face recognition project that uses opencv and python to recognize a person's face on a pc. Now, my goal is to use a raspberry pi to access one of my gpio ports, and when One face was detected in my pc then to turn on a led. My problem is how can I connect my pc to a raspberry pi and use the code that runs on my pc to run the raspberry pi gpio?
Solution 1:[1]
I would recommend GPIO Zero due to its excellent remote GPIO support.
Solution 2:[2]
I recently wrote "mqtt-gpio" which connects MQTT topics to Raspberry Pi GPIO pins. It is a general purpose connector which supports input and output pins; groups of pins; and complex inching. Configurable with YAML, and will be very easy to switch a LED on and off based on a MQTT topic.
There are prebuilt container images on Docker Hub. The docs/source are on GitHub: README.md.
I run it in K3s (but will work on Docker too) on Raspberry Pi OS. The service is built on gpiozero. At present I use it to:
- drive relays for my irrigation solenoids and ball valve manipulators,
- detect open/closed state of doors/windows,
- and remotely press various buttons.
Setting up a MQTT broker and publishing to a MQTT is relatively easy too. You can install Eclipse Mosquitto, or just use EMQ X or other free cloud MQTT providers. Publishing to a MQTT topic from Python is also simple using the paho.mqtt library.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Kristjan Variksoo |
| Solution 2 |
