Example Code for OpenMV-Analog Servo(PPM)

This article offers an in-depth guide on controlling analog servos using OpenMV Cam, detailing hardware and software preparations, wiring connections, and providing sample code for practical implementation.

Hardware Preparation

Software Preparation

Wiring Diagram

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

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.

Other Preparation Work

  1. When put the expansion shield on the OpenMV motherboard, please pay attention to the direction. The USB port of the expansion shield should be on the same side as the USB port of the OpenMV motherboard.
  2. If you need to drive high current components such as servos and motors, please connect them to P7~P9 ports, then connect the external power supply, and turn the power switch to VIN side.

Sample Code

# Servo Control Example
# This example shows how to use your OpenMV Cam to control servos.
# Hardware : Servo, OpenMV
# connect:
#     Servo    OpenMV
#     VCC       5V
#     GND       GND
#     data      P7
import time
from pyb import Servo,Pin
s1 = Servo(1) # P7
while(True):
    s1.angle(0)
    time.sleep(1000)
    s1.angle(90)
    time.sleep(1000)
    s1.angle(0)
    time.sleep(1000)
    s1.angle(-90)
    time.sleep(1000)

Result

Copy the sample code in the OpenMV IDE and click the start button, you will see the servo constantly spinning.

Was this article helpful?

TOP