Raspberry Pi Remote GPIO

by drselim in Circuits > Raspberry Pi

15907 Views, 6 Favorites, 0 Comments

Raspberry Pi Remote GPIO

Raspberry Pi GPIO Programming with Python - Part 4: Remote GPIO

In this instructable, we'll see how to configure Remote GPIO for the Raspberry Pi and use a remote computer (Windows) to control LEDs and Servo motors connected to the GPIO ports of the Pi.

Supplies

Raspberry Pi, breadboard, jumper cables, LED, Servo Motor

Configuring the Raspberry Pi for Remote GPIO

step_1_greaphical_int.png
step_2_terminal.png

There are a couple of things that need to be done on the Raspberry Pi.

First is to enable Remote GPIO from either the graphical interface or a terminal.

Using the Graphical Interface, go to:

Preferences > Raspberry Pi Configuration > Interfaces > Remote GPIO (Choose enable) and click on OK.

Using the Remote Terminal:

  1. Execute the command : "sudo raspi-config"
  2. Go to "Interfacing Options"
  3. Go to "Remote GPIO"
  4. Choose "Yes"

Second, you need to start the pigpiod from the terminal using the following command:

"sudo systemctl start pigpiod"

and if you'd like to have this daemon run every time the Pi boots, execute the following command as well:

"sudo systemctl enable pigpiod"

Configuring the Windows Computer

step_2_windows_install_library.png

On the Windows computer, you have to install the gpiozero and the pigpio libraries using the following command in the command prompt:

"pip install gpiozero pigpio"

Controlling the LED With Remote GPIO

sterp_3_LED_config.png
GPIO-Pinout-Diagram-2.png

For this example, you need to connect an LED to the GPIO Port 17 on the Raspberry Pi over a resistor (330 Ohm or any other appropriate value in order to not to burn the LED later on). And connect the ground to any of the grounds on the Raspberry Pi.

Then use the following script:

from gpiozero import LED

from gpiozero.pins.pigpio import PiGPIOFactory

from time import sleep

factory = PiGPIOFactory(host='192.168.1.6')

red = LED(17,pin_factory=factory)

while True:

red.on()

sleep(1)

red.off()

sleep(1)

Make sure that you change the "host = " with the ip address of the Raspberry Pi that you'll be using. This script will blink the LED using the remote GPIO

Controlling Servo Motor With Remote GPIO

sterp_4_servo.png
sterp_4_servo2.png

For this example you need to connect the control cable (usually the Yellow one) of the servo motor to the GPIO 17 of the Raspberry Pi and you can use the 5V and Ground connections of the Raspberry Pi to the Servo's Red and Brown cables respectively. Make sure that you don't load any weight on the Servo for avoiding excess current.

The Script:

from gpiozero import Servo

from gpiozero.pins.pigpio import PiGPIOFactory

from time import sleep

factory = PiGPIOFactory(host='192.168.1.6')

servo = Servo(17,min_pulse_width=0.8/1000, max_pulse_width=2.2/1000,pin_factory=factory)

servo.min()

sleep(2)

servo.max()

sleep(2)

servo.min()

In the code above, make sure you use the correct IP address for your Raspberry Pi, also try to use a simple servo instance if you're using a simple, regular servo. In this example, the properties of the Power HD is given in the parameters (min_pulse_width=0.8/1000, max_pulse_width=2.2/1000), for a regular servo the line should be:

servo = Servo(17,pin_factory=factory)

If you like the content please subscribe to my YouTube channel for similar tutorials and projects.

https://www.youtube.com/c/drselim

Thank you for your time..