Raspberry Pi Controlling a Servo
From Xojo Documentation
A servo is a small rotary motor. From a neutral (0) position it can rotate +90 and -90 degrees. You can connect things to the servo in order to make them move.
- SG90 Micro-Servo
- 3 jumper wires
Wire the Circuit
The servo has a connector to which you will connect three jumper wires. The connectors are for power, ground and signal. This chart shows how the wires on the servo connector map to GPIO pins:
Create the Xojo App
You'll use the open-source Xojo GPIO library to control the servo. This library has the GPIO.Servo module which contains methods you can call to easily set the servo positions. This code moves the servo to its neutral and the left (-90) and right (90) positions:
Const kServoPin = 6 ' Change to the pin you used
Dim servo As New GPIO.Servo(kServoPin)
If servo.ErrorCode = 0 Then
Transfer the built app to the Pi to test it out.