Software apps and online services
PivotPi is our new hardware to control servo motors. Its design is made elegant and compact to fit the Raspberry Pi Zero. PivotPi can also be connected to any of our Robots GoPiGo, GrovePi and BrickPi. It can drive up to 8 Servo motors and has two I2C ports to accommodate daisy chaining of other I2C devices. This tutorial will demonstrate a fun project on Waving Flags to get started with PivotPi.Preparing the Flag
In order to make the flag stand on the Servo motor, insert a stick into the straw of the Flag and reduce its width as shown in the image to make it fit on the servo motor.
- Connect the PivotPi with the Raspberry Pi as shown in the image below.
- Connect the Servo motors to Channel 1 and Channel 2 of PivotPi such that the brown connector from the Servo motor is at the top when seen from the channel number as shown in the image below.
- Now connect the 6V battery supply to the 6v socket of the PivotPi, and also power the Raspberry Pi with a micro USB cable. Having done this, you can see the Power LEDs and the Servo LEDs glow as shown in the image below.
This completes the hardware setup and your PivotPi is ready to be programmed!Software and Code
PivotPi can be programmed through the RaspberryPi and we have software support in Python and Scratch to control the Servo motors and Servo LEDs. In this tutorial, we are going to use the Python libraries to program the PivotPi to control the Servo motors.
To get the libraries clone our repository using:
sudo git clone https://www.github.com/DexterInd/PivotPi.git
Open a new file using a Nano editor:
sudo nano flag.py
And type the following code:
# To make the code compatible with python3 from __future__ import print_function from __future__ import division from builtins import input import time import pivotpi try: pivotpi = pivotpi.PivotPi(0x40, 60) #PivotPi I2C address and PWM frequency except: print("PivotPi not found - quitting") exit(-1) print('Moving servos on channel 1-2, press Ctrl-C to quit...') while True: for i in range (0,180,10):#Increasing the Pulse width in steps of 10 Microseconds for j in range(2): #Channels 1 and 2 pivotpi.angle(j, i) #Setting the Servo position between 0 and 180 degrees. time.sleep(0.05)
Save the code by pressing
Run the code using:
See your Flag waving!
sudo python flag.py
You can learn more about the technical specifications of the PivotPi here.