Example Code for Pyboard-Analog Servo(PPM)

Last revision 2026/01/05

Hardware Preparation

  • pyboard V1.1 x1
  • Gravity: I/O Expansion Shield for Pyboard x1
  • Gravity 3pin sensor Cable (or several DuPont Cables) x1
  • MicroUSB Cable x1
  • 9g Metal Gear Micro Servo x1

Software Preparation

Wiring Diagram

As shown below,connect the servo to the X1 port of the expansion shield.

Path8267.png

Other Preparation Work

The external power supply must be connected to the USB port of the expansion shield! The power switch must be turned to the VIN side.

Sample Code

# Hardware : Servo, PYBoard
# connect:
#     Servo     PYBoard
#     VCC       VCC
#     GND       GND
#     DAT       X1
import pyb
import time
s1=pyb.Servo(1)     # create a servo object on position X1
while(True):
    s1.angle(0)
    time.sleep(1)
    s1.angle(90)
    time.sleep(1)
    s1.angle(0)
    time.sleep(1)
    s1.angle(-90)
    time.sleep(1)

Result

Copy the sample code in the uPyCraft IDE, save it and click the DownloadAndRun button, you will see the servo constantly spinning.

Was this article helpful?

TOP