Skip to content
  • Home
  • Account
  • Restricted content
  • OBEX
  • Chips Tips
  • Logout
  • Shop
  • QuickBytes
Propeller OBEX
  • OBEX
  • Forum
Login
Propeller OBEX

Propeller 2

  • Configuring Visual Studio Code for Programming the P2 on Mac, Windows, and Linux
  • Breakout Board Options for P2 Edge Modules
  • Solar Panel Monitoring Demo (Intro to Using Video 3 of 3)
  • Wireless Programming with the ESP8266 WX Module
  • Brushless DC Motor Control Demo
  • Colorful Terminal Output with ANSI Escape Sequences
  • XBee RF Transparent and API Mode Demo
  • DS3231 Real Time Clock I2C Demo
  • Multiple Servo Control (up to 64) Object
  • Multiple Serial Port (8 UART – 16 Tx/Rx) Object
  • Goertzel Operation with Ultrasonic Transducers
  • Web Page Control of WS2811 LEDs Using the IoT Gateway on Raspberry Pi
  • 320×240 LCD Driver for ILI9341 Controller and XPT2046 Touch Screen
  • Digital Sample ADC to DAC + Analog Frequency to DAC
  • Using Smart Pins to Measure Frequency Output of TSL235R Light-to-Frequency Sensor
  • Ping))) Ultrasonic Distance Sensor with Graphical Debug Demo
  • Simple Analog Input
  • P2 Edge 16 MB Flash Reader and Explorer Utility
  • LED Matrix used as an I/O Test Utility
  • Arlo Conversion to P2 with the Universal Motor Controller
  • Five Buttons On One Pin
  • P2 RTC Add-on Board Demo
  • Simple Video Driver – Using Images (Intro to Using Video 2 of 3)
  • Starting Your P2 Project with a Spin2 Template
  • E-Ink Display Demo
  • MAX7219 LED Display SPI Demo
  • DHT11, DHT22, CM2302 Humidity and Temperature Sensor Object
  • NMEA GPS String Parsing
  • Floating Point Math: DEBUG and Terminal Display Example
  • LEDs – Beyond the Basics
  • Quadrature Encoder Object
  • P2 RTC Add-on with GPS Module
  • DVI/VGA Text Driver Demo
  • PCF8574 I2C LCD Demo
  • Simple Sound Engine Demo
  • 1-Wire Driver with DS18B20 Temperature Sensor Demo
  • Send Email from the Propeller 2 Using the IoT Gateway on Raspberry Pi
  • I2C Device Bus Scanner Utility
  • 32-Channel ADC Object
  • Tetris
  • Video Hardware with Character Map Demo (Intro to Using Video 1 of 3)
  • WS2811, WS2812, WS2812b, WS2813, SK6812x NeoPixel Object
View Categories
  • Home
  • Docs
  • Quick Bytes
  • Propeller 2
  • Multiple Servo Control (up to 64) Object

Multiple Servo Control (up to 64) Object

Reading Time: 3 min read

Description #

The jm_servo_multi.spin2 simple servo driver that uses P2 smart pins to create the servo signal on up to 32 outputs. A second instance of the object may be started to drive 32 more servos, or 64 total. 

This object uses the Propeller 2 smart pins and leaves all seven remaining processors open for other tasks, like monitoring an R/C receiver, sensors, or servo drive routines.

Ramping and other slow-motion behavior of the servos is controlled by the parent application jm_servo_multi_demo.spin2.

All channels must fit within the A pins group (0..31) or the B pins group (32..63); using pins 58..63 is not recommended. If you need to control more than 32 servos, simply create another instance of the object. 

When controlling more than eight servos from the P2 Edge Breakout Breadboard – the “JonnyMac” (#64020) you will run out of 3-pin servo ports that are already connected to Vin, Vss, and will need to wire 5V to the breadboard power rails. Use caution not to connect the 5V to a P2 Edge IO pin, or you will damage the module. 

To use the object, it’s easiest to put your servos on groups of I/O pins. In the jm_servo_multi_demo.spin2 top object file, identify the base pin I/O attached to the first servo. 

con { app io pins }

  SVO_BASE = 0  { O }                               ' servos base pin

The N_SERVOS is the total number of servos connected from the SVO_BASE pin. 

con

  #true,  ON, OFF
  #false, NO, YES

  N_SERVOS = 16                                                  ' # of servos to run

Within the pub main() method the example code sets all servos in the same position (angle of 0), moves them together from 0 to 180 degrees, and then one at a time before repeating the whole process. 

pub main() | angle, ch

  setup()

  'wait_for_terminal(true)

  repeat
    svos.write_all(svos.M_ANGLE, 0)           ' fast move all to 0 degrees

    waitms(500)

    repeat angle from 1 to 180                ' sweep to 180 position
      svos.write_all(svos.M_ANGLE, angle)     ' sweep all
      waitus(2_000_000 / 180)                 '  in 2 seconds

    waitms(500)

    repeat ch from 0 to N_SERVOS-1            ' loop through servos
      repeat angle from 179 to 90             ' sweep back to 90 degrees
        svos.write(ch, svos.M_ANGLE, angle)   '  one at a time
        waitus(1_000_000 / 360)               '  in 1 second

    waitms(500)

Inside the jm_servo_multi.spin2 object you’ll see how the pinstart and wypin commands are used to configure the smart pin.

The pinstart() function configures the IO pin for PWM using output with the enabled (so we can drive the servo). The x register has been configured for standard servo timing (20ms refresh window, and 1us position units), and the y register (us) is the starting position. While we could start all the servos at the same time, it is common practice to stagger the servo outputs so that servo command pulses do not overlap, hence we enable the outputs in a loop.

pinstart(sp0+ch, P_PWM_SAWTOOTH | P_OE, x, us) '  enable smart pin for servo  

After the servo pin has been configured, changing the output is a simple matter of writing the new position (in microseconds) to the smart pin y register; this is accomplished with wypin(). The new position value will be output starting with the next servo refresh cycle.

 wypin(sp0+ch, usecs[ch])                      ' update servo 
Parts Used #
  • P2 Edge Module
  • P2 Edge Breadboard
  • Parallax Standard Servo (16)
Source Code #
  • jm_multi-servo-Archive.zip
Programming Language #
  • Spin 2
Tools and Operating System #
  • Propeller Tool for Windows
Additional Resources #
  • Propeller 2 Spin Documentation
Document Author #
  • Ken Gracey
Source Code Author #
  • Jon McPhalen
Was this useful ?

Share This Article :

  • Facebook
  • X
  • LinkedIn
Still stuck? How can we help?

Still stuck? How can we help?

Updated on September 27, 2026
DS3231 Real Time Clock I2C DemoMultiple Serial Port (8 UART – 16 Tx/Rx) Object
Table of Contents
  • Description
  • Parts Used
  • Source Code
  • Programming Language
  • Tools and Operating System
  • Additional Resources
  • Document Author
  • Source Code Author

Copyright © 2026 - Parallax Inc.
599 Menlo Drive | Rocklin, CA 95765 | USA