How can I use PyCharm (Python) to access a Raspberry Pi that is on a different network

170 views Asked by At

The code below in PyCharm only works if the PC and Raspberry Pi are on the same network. If I want the Raspberry Pi to be on a different network, what changes should I make to the code for that to work?

from gpiozero import LED, Button  
from gpiozero.pins.pigpio import PiGPIOFactory  
from time import sleep  
  
factory=PiGPIOFactory(host='192.168.182.240')  
GPIO17=LED(17,pin_factory=factory)  
1

There are 1 answers

0
emptyhua On

After network changed, try to ping the new IP address of Pi

  1. if the ping test passed, replace host='192.168.182.240' with the new IP.
  2. if failed, i recommand you to install zerotier on both PC and Pi, and connect to Pi via virtual lan ip provided by zerotier.