1

I am running a main python program on a Windows PC that is hooked to equipment that cannot be ran on an Raspberry pi. At a certain point in the main program, I want to call/execute a Rpi program to run. I need the GPIO pins from the Rpi to turn on a relay/s. Is there a way to wirelessly(or serially) open and run the program on the raspberry pi from the main program already running on the Windows PC?

Maybe I am not thinking of something, is there an easier and just as cheap solution to turn on a relay from the Windows PC program?

Any points in the right direction would be greatly appreciated.

4
  • ssh can be given a program to execute on the remote host. You could, from the PC, run ssh with the path of the second program to execute on the Pi. Commented Jun 6, 2021 at 15:23
  • You could add a part of the Rpi program to act as a client listening for commands from server code hosted on the PC. This can be achieved in many ways, e.g. HTTP, sockets, a serial connection, file transfer protocols, etc. Maybe this SO question can help you get started. Commented Jun 6, 2021 at 15:28
  • If you want to do it wirelessly, you can use an nRF24L01+ 2.4GHz transceiver to send a signal to the Pi. Commented Jun 6, 2021 at 15:34
  • you could simply use a usb interface relay such as -- amazon.com/SMAKN%C2%AE-LCUS-1-module-intelligent-control/dp/… Commented Jun 7, 2021 at 15:26

2 Answers 2

0

The easiest way to do this is with Remote GPIO which is all documented at that link. However, the gist of it is pretty simple as follows.


On the Raspberry Pi, run these steps:

  • sudo apt install pigpio
  • sudo raspi-config and enable "Remote GPIO"
  • sudo systemctl enable pigpiod

On the Windows PC, run these steps:

  • pip install gpiozero pigpio
  • Assuming your RaspberryPi has IP address 192.168.1.3, run PIGPIO_ADDR=192.168.1.3 python3 YourScript.py

Your script on Windows PC would then look like this:

from gpiozero import LED
from time import sleep

red = LED(17)

while True:
    red.on()
    sleep(1)
    red.off()
    sleep(1)
Sign up to request clarification or add additional context in comments.

Comments

0

depending on security requirements. Assuming that the Desktop PC and raspberry pi are on the same network, you could create an HTTP REST endpoint on the pi, you could use flask or fastapi for this. then call that from the app running on the desktop. for help with flask see https://flask.palletsprojects.com/en/2.0.x/ if you are familiar with python flask is fairly simple to get started with.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.