GPIO
GPIO
Servo
GPIO setup
Whenever you use the GPIO pins, you have to import two libraries.
RPi.GPIO (imported as GPIO) allows us to send signals through the pins with
python.
Pigpio uses the raspberry pi’s built in hardware timer to create different
frequencies/signals.
Next, we set the pin mode to the default setting with
GPIO.setwarnings just gets rid of a startup message
Controlling a light
Now that we have our pins set up for use, we can use them to control an led.
Once you are done wiring the LED, you can control it by sending a signal to the
assigned pin.
First assign the pin we are using and make sure it is an output:
Go to the menu open, accessories, click on terminal, then type “sudo pigpiod” and
press enter
Programming PWM to control servos
Make sure you have the proper libraries imported:
Initialize GPIO:
Send a signal:
Serv1ang is a value between 500 and 5000. It is the angle of the servo.
Setting the angle of a servo
To set an angle just use the following line:
Servo1 will be the pin that you connected the orange wire of the servo to, and the
number is a value between 500 and 5000 that control the angle.
The if statement creates boundaries that the servo cannot pass. This is the perfect
example of adding to an angle instead of going to a set angle.
Implementation
Make a program to wave a servo back and forth 5 times.