# Servo Boss

## Overview

![](https://cdn-learn.adafruit.com/assets/assets/000/131/069/medium800/robotics___cnc_srvocmndr-2-2.jpg?1719967775)

https://youtu.be/mjkwMXRGJ9w

You can create a direct servo motor controller with rotary encoder input, saved positions, and animation features. It's all coded in CircuitPython and runs on minimal hardware -- an ESP32-S2 Reverse TFT Feather, two rotary encoders, and batteries all mounted on a perma proto board. Easily swap in different servos and use the display to get all the relevant motor angle details. Become the boss of your servos!

## Parts
Featured
### Adafruit ESP32-S2 Reverse TFT Feather

[Adafruit ESP32-S2 Reverse TFT Feather](https://www.adafruit.com/product/5345)
Like Missy Elliot, we like to ["put our [Feather] down, flip it and reverse it"](https://www.youtube.com/watch?v=cjIvu7e6Wq8)&nbsp;and that's exactly what we've done with this new development board. It's basically our **<a...></a...>**

In Stock
[Buy Now](https://www.adafruit.com/product/5345)
[Related Guides to the Product](https://learn.adafruit.com/products/5345/guides)
![Video of a rectangular microcontroller with a TFT display. A pink manicured finger presses each of the tactile buttons, which are recognized on the TFT display.](https://cdn-shop.adafruit.com/product-videos/640x480/5345-00.jpg)

Featured
### Adafruit Perma-Proto Full-sized Breadboard PCB - Single

[Adafruit Perma-Proto Full-sized Breadboard PCB - Single](https://www.adafruit.com/product/1606)
Customers have asked us to carry basic perf-board, but we never liked the look of most basic perf: it's always crummy quality, with pads that flake off and no labeling. Then we thought about how people **actually** prototype - usually starting with a solderless breadboard and...

In Stock
[Buy Now](https://www.adafruit.com/product/1606)
[Related Guides to the Product](https://learn.adafruit.com/products/1606/guides)
![A white hand with a red manicure holds up an Adafruit Perma-Proto Full-sized Breadboard PCB.](https://cdn-shop.adafruit.com/640x480/1606-04.jpg)

Featured
### 4 x AA Battery Holder with 2.1mm Plug and On/Off Switch

[4 x AA Battery Holder with 2.1mm Plug and On/Off Switch](https://www.adafruit.com/product/3788)
Here's another addition to our growing family of&nbsp;[AA battery holders](https://www.adafruit.com/category/563). Behold! A&nbsp;holder for four (4) AA batteries! It's got&nbsp;a 5" long power cable with a 5.5/2.1mm DC jack at the end, an On/Off switch, and, oh yes,...

In Stock
[Buy Now](https://www.adafruit.com/product/3788)
[Related Guides to the Product](https://learn.adafruit.com/products/3788/guides)
![Angled shot of square black 4 x AA battery holder with 2.1mm plug and on/off switch.](https://cdn-shop.adafruit.com/640x480/3788-00.jpg)

Featured
### Mini Pan-Tilt Kit - Assembled with Micro Servos

[Mini Pan-Tilt Kit - Assembled with Micro Servos](https://www.adafruit.com/product/1967)
This fully-assembled pan-tilt kit is the perfect way to give your project full range&nbsp;motion with two micro servos. The pan-tilt can rotate roughly 180° from side-to-side and can tilt up&downwards around 150°. &nbsp;It also comes fully assembled with two <a...></a...>

Out of Stock
[Buy Now](https://www.adafruit.com/product/1967)
[Related Guides to the Product](https://learn.adafruit.com/products/1967/guides)
![Assembled Mini Pan-Tilt Kit wired to microcontroller board and moving around](https://cdn-shop.adafruit.com/product-videos/640x480/1967-02.jpg)

 **or:**

 **2 each:**

Featured
### Standard servo - TowerPro SG-5010

[Standard servo - TowerPro SG-5010](https://www.adafruit.com/product/155)
This high-torque standard servo can rotate approximately 180 degrees (90 in each direction). You can use any servo code, hardware, or library to control these servos. Good for beginners who want to make stuff move without building a motor controller with feedback & gearbox. Comes with 3...

Out of Stock
[Buy Now](https://www.adafruit.com/product/155)
[Related Guides to the Product](https://learn.adafruit.com/products/155/guides)
![Standard hobby servo with three pin cable](https://cdn-shop.adafruit.com/640x480/155-01.jpg)

 **2 each:**

Featured
### Rotary Encoder + Extras

[Rotary Encoder + Extras](https://www.adafruit.com/product/377)
This rotary encoder is the best of the best, it's a high-quality 24-pulse encoder, with detents and a nice feel. It is panel mountable for placement in a box, or you can plug it into a breadboard (just cut/bend the two mechanical side tabs.) We also include a nice soft-touch knob with an...

In Stock
[Buy Now](https://www.adafruit.com/product/377)
[Related Guides to the Product](https://learn.adafruit.com/products/377/guides)
![Rotary Encoder with rubbery knob](https://cdn-shop.adafruit.com/640x480/377-02.jpg)

### Breadboard-friendly 2.1mm DC barrel jack

[Breadboard-friendly 2.1mm DC barrel jack](https://www.adafruit.com/product/373)
This power jack is designed to fit 2.1mm power plugs snugly and securely. Perfect for adding a power connector to your project. We went for the more expensive "thin pin" type which snap into breadboards or perfboards. They will work where "thick pin" types go also, just...

In Stock
[Buy Now](https://www.adafruit.com/product/373)
[Related Guides to the Product](https://learn.adafruit.com/products/373/guides)
![Small, black, 2.1mm DC barrel jack](https://cdn-shop.adafruit.com/640x480/373-04.jpg)

### Breadboard-friendly SPDT Slide Switch

[Breadboard-friendly SPDT Slide Switch](https://www.adafruit.com/product/805)
These nice switches are perfect for use with breadboard and perfboard projects. They have 0.1" spacing and snap in nicely into a solderless breadboard. They're easy to switch no matter what size fingers you have, but not so easy that they'll get flipped by accident. Work great as...

Out of Stock
[Buy Now](https://www.adafruit.com/product/805)
[Related Guides to the Product](https://learn.adafruit.com/products/805/guides)
![Small, black, SPDT slide switch.](https://cdn-shop.adafruit.com/640x480/805-03.jpg)

### Header Kit for Feather - 12-pin and 16-pin Female Header Set

[Header Kit for Feather - 12-pin and 16-pin Female Header Set](https://www.adafruit.com/product/2886)
These two&nbsp; **Female&nbsp;Headers** &nbsp;alone are, well, lonely. But pair them with any of our&nbsp;[Feather](https://www.adafruit.com/categories/777)&nbsp;boards and you're in business!

What do they do? They get soldered on either side of the Feather...

Out of Stock
[Buy Now](https://www.adafruit.com/product/2886)
[Related Guides to the Product](https://learn.adafruit.com/products/2886/guides)
![Angled shot of a Header Kit for Feather - 12-pin and 16-pin Female Header Set. ](https://cdn-shop.adafruit.com/640x480/2886-00.jpg)

### Lithium Ion Polymer Battery Ideal For Feathers - 3.7V 400mAh

[Lithium Ion Polymer Battery Ideal For Feathers - 3.7V 400mAh](https://www.adafruit.com/product/3898)
Lithium-ion polymer (also known as 'lipo' or 'lipoly') batteries are thin, light, and powerful. The output ranges from 4.2V when completely charged to 3.7V. This battery has a capacity of **400mAh** for a total of about 1.9 Wh. If you need a larger (or smaller!)...

In Stock
[Buy Now](https://www.adafruit.com/product/3898)
[Related Guides to the Product](https://learn.adafruit.com/products/3898/guides)
![Slim Lithium Ion Polymer Battery 3.7v 400mAh with JST 2-PH connector and short cable](https://cdn-shop.adafruit.com/640x480/3898-05.jpg)

### Extra-long break-away 0.1" 16-pin strip male header (5 pieces)

[Extra-long break-away 0.1" 16-pin strip male header (5 pieces)](https://www.adafruit.com/product/400)
Breakaway header is like the duct tape of electronics, and this header is one better with extra long pins on **both** sides. This makes it great for connecting things together that have two sockets - especially solderless breadboards. [We also...](https://www.adafruit.com/products/266)

In Stock
[Buy Now](https://www.adafruit.com/product/400)
[Related Guides to the Product](https://learn.adafruit.com/products/400/guides)
![5 pieces of Extra-long break-away 0.1 inch 16-pin strip male header](https://cdn-shop.adafruit.com/640x480/400-03.jpg)

### Adafruit Swirly Aluminum Mounting Grid for 0.1" Spaced PCBs

[Adafruit Swirly Aluminum Mounting Grid for 0.1" Spaced PCBs](https://www.adafruit.com/product/5781)
With most of our dev boards, sensors and feathers now sporting [plug-and-play stemma QT ports](https://learn.adafruit.com/search?q=stemma%2520qt)&nbsp;it can be very fast to put together projects with half a dozen boards snapped together. But that ease of use has one...

In Stock
[Buy Now](https://www.adafruit.com/product/5781)
[Related Guides to the Product](https://learn.adafruit.com/products/5781/guides)
![Overhead shot of 10x10 aluminum prototyping grid with a microcontroller and three breakout boards.](https://cdn-shop.adafruit.com/640x480/5781-05.jpg)

## Tools and Materials
Featured
### Hook-up Wire Spool Set - 22AWG Stranded-Core - 6 x 25ft

[Hook-up Wire Spool Set - 22AWG Stranded-Core - 6 x 25ft](https://www.adafruit.com/product/3111)
This is a box of **six** &nbsp;25ft **&nbsp;** spools of **stranded-core** wire. Stranded-core wire is best used for wiring jigs where there's bending or movement expected. It also works well with terminal blocks. It's&nbsp;_not&nbsp;_great...

In Stock
[Buy Now](https://www.adafruit.com/product/3111)
[Related Guides to the Product](https://learn.adafruit.com/products/3111/guides)
![Hook-up Wire Spool Set in box with 6 colorful wires coming out](https://cdn-shop.adafruit.com/640x480/3111-02.jpg)

Featured
### Automatic Self-Adjusting Wire Strippers and Cutter

[Automatic Self-Adjusting Wire Strippers and Cutter](https://www.adafruit.com/product/4747)
If you've got a lot of wire-stripping to do, you may want to try out an automatic stripper/cutter! They are fantastic for stripping and cutting stranded and solid-core 24 or thicker AWG wires and ribbon cables. The tool has both metric (up to ~20mm) and imperial (up to 0.75")...

In Stock
[Buy Now](https://www.adafruit.com/product/4747)
[Related Guides to the Product](https://learn.adafruit.com/products/4747/guides)
![Person quickly stripping a piece of wire](https://cdn-shop.adafruit.com/product-videos/640x480/4747-05.jpg)

Featured
### Hakko Precision Flat Pliers

[Hakko Precision Flat Pliers](https://www.adafruit.com/product/1368)
These Italian-made Hakko pliers are excellent for any precision work. The nose is flattened and fairly short to provide excellent control. The inside of the jaws is also flattened so they won't leave ridge-marks. And the grips are ultra comfy too, you can use these all days with no...

In Stock
[Buy Now](https://www.adafruit.com/product/1368)
[Related Guides to the Product](https://learn.adafruit.com/products/1368/guides)
![Red and black flat needle-nose pliers](https://cdn-shop.adafruit.com/640x480/1368-03.jpg)

Featured
### ATTEN 80W 110V Soldering Iron With Station

[ATTEN 80W 110V Soldering Iron With Station](https://www.adafruit.com/product/4921)
This compact but **80 Watt** -powerful stationary soldering iron is a great entry-level soldering station with all the fixins. It's not much more expensive than the chunky 'all-in-one" irons, but comes with a separate power supply and pen. Heats up fast and solders...

Out of Stock
[Buy Now](https://www.adafruit.com/product/4921)
[Related Guides to the Product](https://learn.adafruit.com/products/4921/guides)
![Angled shot of assembled soldering station.](https://cdn-shop.adafruit.com/640x480/4921-00.jpg)

### Solder Wire - 60/40 Rosin Core - 0.5mm/0.02" diameter - 50 grams

[Solder Wire - 60/40 Rosin Core - 0.5mm/0.02" diameter - 50 grams](https://www.adafruit.com/product/1886)
If you want to make a kit you'll need some solder. This 0.1 lb (about 50 grams) spool is a good amount, not too much (like 1 lb spools) and not too little (like those little 'pocket clip' vials).  
  
This spool of solder contains approximately 0.6mm / .02" diameter in...

Out of Stock
[Buy Now](https://www.adafruit.com/product/1886)
[Related Guides to the Product](https://learn.adafruit.com/products/1886/guides)
![Solder Wire - 60/40 Rosin Core - 0.5mm/0.02" diameter.](https://cdn-shop.adafruit.com/640x480/1886-01.jpg)

### Alkaline AA batteries (LR6) - 4 pack

[Alkaline AA batteries (LR6) - 4 pack](https://www.adafruit.com/product/3349)
Battery power for your portable project! These batteries are good quality at a good price, and work fantastic with any of the kits or projects in the shop that use AAs.&nbsp;This is a pack of **4 AA batteries**.  
  
These batteries are Alkaline (MnO2) chemistry, with a...

In Stock
[Buy Now](https://www.adafruit.com/product/3349)
[Related Guides to the Product](https://learn.adafruit.com/products/3349/guides)
![Angled shot of 4 Piscell AA batteries. ](https://cdn-shop.adafruit.com/640x480/3349-00.jpg)

### Black Nylon Machine Screw and Stand-off Set – M2.5 Thread

[Black Nylon Machine Screw and Stand-off Set – M2.5 Thread](https://www.adafruit.com/product/3299)
Totaling 380 pieces, this **M2.5 Screw Set** &nbsp;is a must-have for your workstation.&nbsp;You'll have enough screws, nuts, and hex standoffs to fuel your maker tendencies&nbsp;for days on end! M2.5 size screws fit almost all of the Adafruit breakout/dev board mounting holes...

In Stock
[Buy Now](https://www.adafruit.com/product/3299)
[Related Guides to the Product](https://learn.adafruit.com/products/3299/guides)
![Black Nylon Screw and Stand-off Set with M2.5 Threads, kit box](https://cdn-shop.adafruit.com/640x480/3299-00.jpg)

# Servo Boss

## Build the Servo Boss

![](https://cdn-learn.adafruit.com/assets/assets/000/130/975/medium800/robotics___cnc_servo_commander_fritz.jpg?1719866494)

## Perma Proto

The Servo Boss is built on a perma proto board for long-term stability. Alternately, you can build it on a breadboard.

![robotics___cnc_srvocmndr-9918.jpg](https://cdn-learn.adafruit.com/assets/assets/000/131/018/medium640/robotics___cnc_srvocmndr-9918.jpg?1719959637)

## Power Jack

Solder the power jack as shown, then wire the center pin to the power rail and sleeve pin to ground.

&nbsp;

![robotics___cnc_srvocmndr-9919.jpg](https://cdn-learn.adafruit.com/assets/assets/000/131/019/medium640/robotics___cnc_srvocmndr-9919.jpg?1719959736)

![robotics___cnc_srvocmndr-9921.jpg](https://cdn-learn.adafruit.com/assets/assets/000/131/020/medium640/robotics___cnc_srvocmndr-9921.jpg?1719959765)

![robotics___cnc_srvocmndr-9924.jpg](https://cdn-learn.adafruit.com/assets/assets/000/131/021/medium640/robotics___cnc_srvocmndr-9924.jpg?1719959787)

![robotics___cnc_srvocmndr-9927.jpg](https://cdn-learn.adafruit.com/assets/assets/000/131/022/medium640/robotics___cnc_srvocmndr-9927.jpg?1719959845)

## Encoder Prep

Bend the outer legs as shown -- these are used for mechanically securing the encoders in PCBs, but there aren't holes for this in the perma proto (or breadboard).

![robotics___cnc_srvocmndr-9928.jpg](https://cdn-learn.adafruit.com/assets/assets/000/131/023/medium640/robotics___cnc_srvocmndr-9928.jpg?1719959865)

![robotics___cnc_srvocmndr-9929.jpg](https://cdn-learn.adafruit.com/assets/assets/000/131/024/medium640/robotics___cnc_srvocmndr-9929.jpg?1719959871)

![](https://cdn-learn.adafruit.com/assets/assets/000/131/027/medium800/robotics___cnc_srvocmndr-9930.jpg?1719959947)

## Encoder Soldering

Solder the five encoder pins (per encoder) as shown.

![robotics___cnc_srvocmndr-9933.jpg](https://cdn-learn.adafruit.com/assets/assets/000/131/033/medium640/robotics___cnc_srvocmndr-9933.jpg?1719959963)

## Fancy Servo Headers

If you want extra fancy header pins for your servos you're in the right spot! Long header pins plus color coded plastic nubs do the trick so you can easily differentiate between power, ground, and signal.

Press the long header pins' plastic spacers down with pliers (and the pins on a hard surface), then extricate colored spacers from some donor pins.

Slide the colored spacers over the long header pins as shown, black-red-yellow ordered.

![robotics___cnc_srvocmndr-9934.jpg](https://cdn-learn.adafruit.com/assets/assets/000/131/034/medium640/robotics___cnc_srvocmndr-9934.jpg?1719960010)

![robotics___cnc_srvocmndr-9936.jpg](https://cdn-learn.adafruit.com/assets/assets/000/131/035/medium640/robotics___cnc_srvocmndr-9936.jpg?1719960099)

![robotics___cnc_srvocmndr-9937.jpg](https://cdn-learn.adafruit.com/assets/assets/000/131/036/medium640/robotics___cnc_srvocmndr-9937.jpg?1719960183)

![robotics___cnc_srvocmndr-9938.jpg](https://cdn-learn.adafruit.com/assets/assets/000/131/037/medium640/robotics___cnc_srvocmndr-9938.jpg?1719960191)

## Solder Servo Pins

Place the servo header pins on the board as shown and solder them in place.

![robotics___cnc_srvocmndr-9943.jpg](https://cdn-learn.adafruit.com/assets/assets/000/131/038/medium640/robotics___cnc_srvocmndr-9943.jpg?1719960223)

![robotics___cnc_srvocmndr-9944.jpg](https://cdn-learn.adafruit.com/assets/assets/000/131/039/medium640/robotics___cnc_srvocmndr-9944.jpg?1719960241)

![](https://cdn-learn.adafruit.com/assets/assets/000/131/043/medium800/robotics___cnc_srvocmndr-9945.jpg?1719960288)

## Feather Headers

Next solder in socket headers for the Feather. Since we're using the Reverse TFT Feather it is "face down" compared to typical Feather mounting.

![robotics___cnc_srvocmndr-9950.jpg](https://cdn-learn.adafruit.com/assets/assets/000/131/055/medium640/robotics___cnc_srvocmndr-9950.jpg?1719962252)

![robotics___cnc_srvocmndr-9952.jpg](https://cdn-learn.adafruit.com/assets/assets/000/131/056/medium640/robotics___cnc_srvocmndr-9952.jpg?1719962301)

## Ground Wiring

Trim lengths of black hook-up wire to fit the ground runs from each component shown.

![robotics___cnc_srvocmndr-9966.jpg](https://cdn-learn.adafruit.com/assets/assets/000/131/057/medium640/robotics___cnc_srvocmndr-9966.jpg?1719962323)

![robotics___cnc_srvocmndr-9973.jpg](https://cdn-learn.adafruit.com/assets/assets/000/131/058/medium640/robotics___cnc_srvocmndr-9973.jpg?1719962362)

## Servo Header Power

Solder two red wires to the center pins of the servo headers so they connect to the power rail that'll be fed by the external 5V DC power supply or battery pack.

![robotics___cnc_srvocmndr-9975.jpg](https://cdn-learn.adafruit.com/assets/assets/000/131/059/medium640/robotics___cnc_srvocmndr-9975.jpg?1719962449)

## Servo Signal Wires

Next wire the two servo signal pins to `D10` and `D11` respectively.

![robotics___cnc_srvocmndr-9978.jpg](https://cdn-learn.adafruit.com/assets/assets/000/131/060/medium640/robotics___cnc_srvocmndr-9978.jpg?1719962775)

![robotics___cnc_srvocmndr-9985.jpg](https://cdn-learn.adafruit.com/assets/assets/000/131/061/medium640/robotics___cnc_srvocmndr-9985.jpg?1719962807)

## Rotary Encoder Wiring

Solder the two encoder pulse pins to their associated Feather input pins, `A1`/`A2` and `A4`/`A5`.

![robotics___cnc_srvocmndr-9987.jpg](https://cdn-learn.adafruit.com/assets/assets/000/131/062/medium640/robotics___cnc_srvocmndr-9987.jpg?1719962970)

![robotics___cnc_srvocmndr-9995.jpg](https://cdn-learn.adafruit.com/assets/assets/000/131/063/medium640/robotics___cnc_srvocmndr-9995.jpg?1719963075)

## Push Encoder Button Wiring

Wire the two push encoder button pins to `D12` and `D13`.

![robotics___cnc_srvocmndr-2.jpg](https://cdn-learn.adafruit.com/assets/assets/000/131/064/medium640/robotics___cnc_srvocmndr-2.jpg?1719963141)

## Enable Switch

Solder the slide switch in place as shown, running the center pin to ground and the left pin to the `En` pin on the Feather -- this will turn the Feather on and off.

![robotics___cnc_srvocmndr-0012.jpg](https://cdn-learn.adafruit.com/assets/assets/000/131/065/medium640/robotics___cnc_srvocmndr-0012.jpg?1719963288)

![robotics___cnc_srvocmndr-0013.jpg](https://cdn-learn.adafruit.com/assets/assets/000/131/066/medium640/robotics___cnc_srvocmndr-0013.jpg?1719963298)

![robotics___cnc_srvocmndr-0015.jpg](https://cdn-learn.adafruit.com/assets/assets/000/131/067/medium640/robotics___cnc_srvocmndr-0015.jpg?1719963307)

![robotics___cnc_srvocmndr-0014.jpg](https://cdn-learn.adafruit.com/assets/assets/000/131/068/medium640/robotics___cnc_srvocmndr-0014.jpg?1719963376)

## Mounting

You can go the extra step to mount your Servo Boss perma proto to an aluminum swirly grid using M2.5 screws and standoffs.

Add a AA battery pack secured with double stick foam tape or a zip tie (as seen here) and a pan-tilt servo set. This will give you a portable, all-in-one servo platform!

![](https://cdn-learn.adafruit.com/assets/assets/000/131/070/medium800/robotics___cnc_srvocmndr-0073.jpg?1719968059)

# Servo Boss

## CircuitPython

[CircuitPython](https://github.com/adafruit/circuitpython) is a derivative of [MicroPython](https://micropython.org) designed to simplify experimentation and education on low-cost microcontrollers. It makes it easier than ever to get prototyping by requiring no upfront desktop software downloads. Simply copy and edit files on the **CIRCUITPY** drive to iterate.

## CircuitPython Quickstart

Follow this step-by-step to quickly get CircuitPython running on your board.

[Download the latest version of CircuitPython for this board via circuitpython.org](https://circuitpython.org/board/adafruit_feather_esp32s2_reverse_tft/)
 **Click the link above to download the latest CircuitPython UF2 file.**

Save it wherever is convenient for you.

![install_circuitpython_on_most_boards_CircuitPython_downloaded.jpg](https://cdn-learn.adafruit.com/assets/assets/000/102/129/medium640/install_circuitpython_on_most_boards_CircuitPython_downloaded.jpg?1620922559)

![](https://cdn-learn.adafruit.com/assets/assets/000/118/332/medium800/adafruit_products_FRTFT_reset_button_status_led.jpg?1675887945)

Plug your board into your computer, using a known-good data-sync cable, directly, or via an adapter if needed.

Double-click the **reset** button (highlighted in red above), and you will see the **RGB status LED(s)** turn green (highlighted in green above). If you see red, try another port, or if you're using an adapter or hub, try without the hub, or different adapter or hub.

For this board, tap reset and wait for the LED to turn purple, and as soon as it turns purple, tap reset again. The second tap needs to happen while the LED is still purple.

If double-clicking doesn't work the first time, try again. Sometimes it can take a few tries to get the rhythm right!

A lot of people end up using charge-only USB cables and it is very frustrating! **Make sure you have a USB cable you know is good for data sync.**

You will see a new disk drive appear called **FTHRS2BOOT**.

&nbsp;

Drag the **adafruit\_circuitpython\_etc.uf2** file to **FTHRS2BOOT**.

![adafruit_products_FRTFT_FTHRS2BOOT.png](https://cdn-learn.adafruit.com/assets/assets/000/118/333/medium640/adafruit_products_FRTFT_FTHRS2BOOT.png?1675888469)

![adafruit_products_FRTFT_drag_UF2.png](https://cdn-learn.adafruit.com/assets/assets/000/118/334/medium640/adafruit_products_FRTFT_drag_UF2.png?1675888478)

The **BOOT** drive will disappear and a new disk drive called **CIRCUITPY** will appear.

That's it!

![install_circuitpython_on_most_boards_CIRCUITPY.jpg](https://cdn-learn.adafruit.com/assets/assets/000/102/130/medium640/install_circuitpython_on_most_boards_CIRCUITPY.jpg?1620923145)

# Servo Boss

## Code the Servo Boss

## Text Editor

Adafruit recommends using the&nbsp; **Mu** &nbsp;editor for editing your CircuitPython code. You can get more info in&nbsp;[this guide](https://learn.adafruit.com/welcome-to-circuitpython/installing-mu-editor).

Alternatively, you can use any text editor that saves simple text files.

## Download the Project Bundle

Your project will use a specific set of CircuitPython libraries and the&nbsp; **code.py** &nbsp;file. To get everything you need, click on the&nbsp; **Download Project Bundle** &nbsp;link below, and uncompress the .zip file.

Drag the contents of the uncompressed bundle directory onto your board's&nbsp; **CIRCUITPY** &nbsp;drive, replacing any existing files or directories with the same names, and adding any new ones that are necessary.

![library](https://adafruit.github.io/Adafruit_Learning_System_Guides/Servo_Commander.png )

https://github.com/adafruit/Adafruit_Learning_System_Guides/blob/main/Servo_Commander/code.py

## How It Works

The Servo Boss uses a Feather Reverse TFT ESP32-S2 to control two servo motors using two rotary encoders and several buttons. You can use it to test servo ranges with encoder rotation, store positions using button presses, recall these positions, and play back stored animations.

### Setup

#### Libraries

First, you'll import the required libraries, including `displayio` related libraries, `rotaryio` for encoder reading, and `pwmio` and `adafruit_motor` for driving servos.

```auto
import time
import board
import displayio
import terminalio
from adafruit_display_text import label
from adafruit_display_shapes.rect import Rect
import rotaryio
import pwmio
from adafruit_motor import servo
import keypad
```

#### Servo Configuration

Begin by setting up the servo motors. Two servos are initialized with custom pulse ranges, which define their minimum and maximum pulse widths. The servos are connected to pins D10 and D11:

```auto
s_cfgs = [
    {'min_pulse': 600, 'max_pulse': 2400, 'min_ang': 10, 'max_ang': 170},
    {'min_pulse': 600, 'max_pulse': 2300, 'min_ang': 10, 'max_ang': 170}
]
```

Each servo is configured using the `pwmio` and `adafruit_motor` libraries, and their initial angles are set to 90 degrees:

```auto
pwm_pins = [board.D10, board.D11]
servo_motors = []
for i, config in enumerate(s_cfgs):
    pwm = pwmio.PWMOut(pwm_pins[i], duty_cycle=2**15, frequency=50)
    servo_motor = servo.Servo(pwm, min_pulse=config['min_pulse'], max_pulse=config['max_pulse'])
    servo_motors.append(servo_motor)
    servo_motor.angle = 90
```

### Rotary Encoders

Two rotary encoders are set up to control the angles of the servos. The encoders are connected to pins D10 and D11 and then initialized with a starting position of 90 degrees:

```auto
encs = [
    rotaryio.IncrementalEncoder(board.A2, board.A1),
    rotaryio.IncrementalEncoder(board.A5, board.A4)
]
for enc in encs:
    enc.position = 90
```

### Button Configuration

Several buttons are configured to save and recall positions. Two encoder buttons and the three buttons (D0, D1, D2) on the TFT Feather are set up using the&nbsp;`keypad` library:

```auto
enc_buttons = keypad.Keys((board.D13, board.D12), value_when_pressed=False, pull=True)
tft_d0_button = keypad.Keys((board.D0,), value_when_pressed=False, pull=True)
tft_buttons = keypad.Keys((board.D1, board.D2), value_when_pressed=True, pull=True)
```

### Display Setup

The display is initialized to show the servo pulse ranges, current angles, and saved positions:

```auto
display = board.DISPLAY
group = displayio.Group()
background_rect = Rect(0, 10, display.width, display.height - 10, fill=0x000010)
group.append(background_rect)
# Additional display elements are added here
display.root_group = group
```

### Main Loop

The main loop checks for button presses and encoder changes in order to control the servos and update the display:

#### Button Presses

- **Single Encoder Buttons** : When either encoder button is pressed along with one of the TFT buttons, the current position for the relative servo is stored in that save slot.
- **Both Encoder Buttons** : When both encoder buttons are pressed, the playback function is triggered to play back stored animations.
- **D0, D1, D2 Buttons** : When any of these are pressed on their own, both servo motors go to their saved positions for that save slot. When pressed at the same time as an encoder button saves the current position.

```auto
while True:
    enc_button_event = enc_buttons.events.get()
    if enc_button_event:
        if enc_button_event.pressed:
            if enc_button_event.key_number == 0:
                modifier1 = True
            elif enc_button_event.key_number == 1:
                modifier2 = True

        if enc_button_event.released:
            if enc_button_event.key_number == 0:
                modifier1 = False
            elif enc_button_event.key_number == 1:
                modifier2 = False

    if modifier1 and modifier2:
        print("Playback")
        playback(True, 0.006, 2)

    tft_d0_button_event = tft_d0_button.events.get()
    if tft_d0_button_event and tft_d0_button_event.pressed:
        if modifier1:
            s_saves[0][0] = min(max(encs[0].position, s_cfgs[0]['min_ang']), s_cfgs[0]['max_ang'])
            print("D0 save motor1:", s_saves[0][0])
            labels[4].text = f"D0:{s_saves[0][0]}"
        elif modifier2:
            s_saves[1][0] = min(max(encs[1].position, s_cfgs[1]['min_ang']), s_cfgs[1]['max_ang'])
            print("D0 save motor2:", s_saves[1][0])
            labels[7].text = f"D0:{s_saves[1][0]}"
        else:
            for i in range(len(servo_motors)):
                servo_motor = servo_motors[i]
                enc = encs[i]
                s_save = s_saves[i][0]
                config = s_cfgs[i]
                print(f"D0 recalled motor{i+1}:", s_save)
                set_servo_angle(servo_motor, s_save, enc, config['min_ang'], config['max_ang'])
                labels[2 + i].text = f"Angle:{s_save}"

    tft_buttons_event = tft_buttons.events.get()
    if tft_buttons_event and tft_buttons_event.pressed:
        if tft_buttons_event.key_number == 0:
            if modifier1:
                s_saves[0][1] = min(max(encs[0].position,s_cfgs[0]['min_ang']),s_cfgs[0]['max_ang'])
                print("D1 save motor1:", s_saves[0][1])
                labels[5].text = f"D1:{s_saves[0][1]}"
            elif modifier2:
                s_saves[1][1] = min(max(encs[1].position,s_cfgs[1]['min_ang']),s_cfgs[1]['max_ang'])
                print("D1 save motor2:", s_saves[1][1])
                labels[8].text = f"D1:{s_saves[1][1]}"
            else:
                for i in range(len(servo_motors)):
                    servo_motor = servo_motors[i]
                    enc = encs[i]
                    s_save = s_saves[i][1]
                    config = s_cfgs[i]
                    print(f"D1 recalled motor{i+1}:", s_save)
                    set_servo_angle(servo_motor, s_save, enc, config['min_ang'], config['max_ang'])
                    labels[2 + i].text = f"Angle:{s_save}"
        elif tft_buttons_event.key_number == 1:
            if modifier1:
                s_saves[0][2] = min(max(encs[0].position,s_cfgs[0]['min_ang']),s_cfgs[0]['max_ang'])
                print("D2 save motor1:", s_saves[0][2])
                labels[6].text = f"D2:{s_saves[0][2]}"
            elif modifier2:
                s_saves[1][2] = min(max(encs[1].position,s_cfgs[1]['min_ang']),s_cfgs[1]['max_ang'])
                print("D2 save motor2:", s_saves[1][2])
                labels[9].text = f"D2:{s_saves[1][2]}"
            else:
                for i in range(len(servo_motors)):
                    servo_motor = servo_motors[i]
                    enc = encs[i]
                    s_save = s_saves[i][2]
                    config = s_cfgs[i]
                    print(f"D2 recalled motor{i+1}:", s_save)
                    set_servo_angle(servo_motor, s_save, enc, config['min_ang'], config['max_ang'])
                    labels[2 + i].text = f"Angle:{s_save}"
```

#### Direct Servo Movements

When you turn either rotary encoder, the corresponding servo angle is updated, while clamping the encoder values in the defined range:

```auto
for i in range(len(servo_motors)):
    current_position = encs[i].position
    if current_position != last_positions[i]:
        config = s_cfgs[i]
        angle = min(max(current_position, config['min_ang']), config['max_ang'])
        servo_motor = servo_motors[i]
        enc = encs[i]
        set_servo_angle(servo_motor, angle, enc, config['min_ang'], config['max_ang'])
        labels[2 + i].text = f"Angle:{angle}"
        last_positions[i] = current_position
```

### Playback Function

The playback function animates the servos through saved positions, either smoothly or instantly depending on the mode:

```auto
def playback(mode, speed, steps):
    for k in range(3):
        for m in range(len(servo_motors)):
            p_servo_motor = servo_motors[m]
            p_enc = encs[m]
            save = s_saves[m][k]
            if mode:
                direction = 1 if save > enc.position else -1
                for p_angle in range(enc.position, save, direction * steps):
                    p_servo_motor.angle = p_angle
                    time.sleep(speed)
                p_enc.position = save
            else:
                servo_motor.angle = save
                time.sleep(0.75)
```

# Servo Boss

## Use the Servo Boss

https://youtu.be/mjkwMXRGJ9w

## Display

The display info is split into two halves, left servo and right servo, each with identical information for their respective motors.

- **Pulse** : At the top, the display shows the&nbsp; **Pulse** lengths for the two servos as set in code.
- **Angle** : Next is the&nbsp; **Angle** for the servo as currently set either by the direct knob control or with saved postion recall from one of the buttons.
- **Saved** Positions: Three saved positions, labeled D0, D1, and D2 are shown. These are the minº, 90º, maxº at startup, but can be changed as shown below.

![](https://cdn-learn.adafruit.com/assets/assets/000/131/074/medium800/robotics___cnc_srvocmndr-0104.jpg?1719982971)

## Direct Control

Turn the two encoder knobs to directly rotate the two servo motors. The motor will turn and the display will update the **Angle** value to match.

![](https://cdn-learn.adafruit.com/assets/assets/000/131/072/medium800thumb/robotics___cnc_srvocmndr-0079.jpg?1719982702)

## Position Recall

Press the D0, D1, or D2 buttons on the Feather to recall a pre-saved position. Both servos will go to their saved position for a given save slot.

![](https://cdn-learn.adafruit.com/assets/assets/000/131/073/medium800thumb/robotics___cnc_srvocmndr-0087.jpg?1719982959)

## Save Position

Here are the steps to save a new position:

1. Rotate encoder knob to go to the desired position
2. Press and hold the encoder push knob
3. While keeping the encoder knob pressed, press any of the Feather D0, D1, or D2 buttons to save that angle position to that slot for the selected encoder/servo
4. Release the Feather D0, D1, or D2 button as well as the encoder knob button

That's it, the position is saved. Now, when you press that D0, D1, or D2 button the servo will return to that saved position.&nbsp;

![](https://cdn-learn.adafruit.com/assets/assets/000/131/076/medium800thumb/robotics___cnc_store.jpg?1720019603)

## Playback

Press both encoder buttons at the same time to play back all of the positions in order in a continuous loop. This is great for testing out animatronic animations or robotic motion sequences. Release the two encoder buttons to stop.

![](https://cdn-learn.adafruit.com/assets/assets/000/131/077/medium800thumb/robotics___cnc_animserv.jpg?1720020084)


## Guide Products

### Adafruit ESP32-S2 Reverse TFT Feather

[Adafruit ESP32-S2 Reverse TFT Feather](https://www.adafruit.com/product/5345)
Like Missy Elliot, we like to ["put our [Feather] down, flip it and reverse it"](https://www.youtube.com/watch?v=cjIvu7e6Wq8)&nbsp;and that's exactly what we've done with this new development board. It's basically our **<a...></a...>**

In Stock
[Buy Now](https://www.adafruit.com/product/5345)
[Related Guides to the Product](https://learn.adafruit.com/products/5345/guides)
### Adafruit Perma-Proto Full-sized Breadboard PCB - Single

[Adafruit Perma-Proto Full-sized Breadboard PCB - Single](https://www.adafruit.com/product/1606)
Customers have asked us to carry basic perf-board, but we never liked the look of most basic perf: it's always crummy quality, with pads that flake off and no labeling. Then we thought about how people **actually** prototype - usually starting with a solderless breadboard and...

In Stock
[Buy Now](https://www.adafruit.com/product/1606)
[Related Guides to the Product](https://learn.adafruit.com/products/1606/guides)
### 4 x AA Battery Holder with 2.1mm Plug and On/Off Switch

[4 x AA Battery Holder with 2.1mm Plug and On/Off Switch](https://www.adafruit.com/product/3788)
Here's another addition to our growing family of&nbsp;[AA battery holders](https://www.adafruit.com/category/563). Behold! A&nbsp;holder for four (4) AA batteries! It's got&nbsp;a 5" long power cable with a 5.5/2.1mm DC jack at the end, an On/Off switch, and, oh yes,...

In Stock
[Buy Now](https://www.adafruit.com/product/3788)
[Related Guides to the Product](https://learn.adafruit.com/products/3788/guides)
### Mini Pan-Tilt Kit - Assembled with Micro Servos

[Mini Pan-Tilt Kit - Assembled with Micro Servos](https://www.adafruit.com/product/1967)
This fully-assembled pan-tilt kit is the perfect way to give your project full range&nbsp;motion with two micro servos. The pan-tilt can rotate roughly 180° from side-to-side and can tilt up&downwards around 150°. &nbsp;It also comes fully assembled with two <a...></a...>

Out of Stock
[Buy Now](https://www.adafruit.com/product/1967)
[Related Guides to the Product](https://learn.adafruit.com/products/1967/guides)
### Standard servo - TowerPro SG-5010

[Standard servo - TowerPro SG-5010](https://www.adafruit.com/product/155)
This high-torque standard servo can rotate approximately 180 degrees (90 in each direction). You can use any servo code, hardware, or library to control these servos. Good for beginners who want to make stuff move without building a motor controller with feedback & gearbox. Comes with 3...

Out of Stock
[Buy Now](https://www.adafruit.com/product/155)
[Related Guides to the Product](https://learn.adafruit.com/products/155/guides)
### Rotary Encoder + Extras

[Rotary Encoder + Extras](https://www.adafruit.com/product/377)
This rotary encoder is the best of the best, it's a high-quality 24-pulse encoder, with detents and a nice feel. It is panel mountable for placement in a box, or you can plug it into a breadboard (just cut/bend the two mechanical side tabs.) We also include a nice soft-touch knob with an...

In Stock
[Buy Now](https://www.adafruit.com/product/377)
[Related Guides to the Product](https://learn.adafruit.com/products/377/guides)
### Breadboard-friendly 2.1mm DC barrel jack

[Breadboard-friendly 2.1mm DC barrel jack](https://www.adafruit.com/product/373)
This power jack is designed to fit 2.1mm power plugs snugly and securely. Perfect for adding a power connector to your project. We went for the more expensive "thin pin" type which snap into breadboards or perfboards. They will work where "thick pin" types go also, just...

In Stock
[Buy Now](https://www.adafruit.com/product/373)
[Related Guides to the Product](https://learn.adafruit.com/products/373/guides)
### Breadboard-friendly SPDT Slide Switch

[Breadboard-friendly SPDT Slide Switch](https://www.adafruit.com/product/805)
These nice switches are perfect for use with breadboard and perfboard projects. They have 0.1" spacing and snap in nicely into a solderless breadboard. They're easy to switch no matter what size fingers you have, but not so easy that they'll get flipped by accident. Work great as...

Out of Stock
[Buy Now](https://www.adafruit.com/product/805)
[Related Guides to the Product](https://learn.adafruit.com/products/805/guides)

## Related Guides

- [Adafruit ESP32-S2 Reverse TFT Feather](https://learn.adafruit.com/esp32-s2-reverse-tft-feather.md)
- [Motion Sensor Bat](https://learn.adafruit.com/motion-sensor-bat.md)
- [DIY Pico Mechanical Keyboard with Fritzing and CircuitPython](https://learn.adafruit.com/diy-pico-mechanical-keyboard-with-fritzing-circuitpython.md)
- [Severance Portable Macrodata Refinement Terminal](https://learn.adafruit.com/portable-macrodata-refinement-terminal.md)
- [Adafruit TPL5110 Power Timer Breakout](https://learn.adafruit.com/adafruit-tpl5110-power-timer-breakout.md)
- [Proximity Based Lighting](https://learn.adafruit.com/proximity-based-lighting.md)
- [Bluetooth-Controlled Matrix LED Sign using Bluefruit Connect](https://learn.adafruit.com/bluetooth-controlled-matrix-led-sign-using-bluefruit-connect.md)
- [Cardboard Window Skull With Animated LED Eyes](https://learn.adafruit.com/cardboard-window-skull-animated-led-eyes.md)
- [PyPortal Titano Weather Station](https://learn.adafruit.com/pyportal-titano-weather-station.md)
- [LED Matrix Necklace Pendant](https://learn.adafruit.com/led-matrix-necklace-pendant.md)
- [Adabot Toy Robot Friend](https://learn.adafruit.com/adabot-rp2040.md)
- [Stepper Motor Turntable](https://learn.adafruit.com/stepper-motor-turntable.md)
- [RGB & HSV NeoPixel Dialer](https://learn.adafruit.com/rgb-hsv-neopixel-dialer.md)
- [CircuitPython Servo Tester](https://learn.adafruit.com/circuitpython-servo-tester.md)
- [Compost Friend!](https://learn.adafruit.com/compost-optimization-machine.md)
- [Meeting Time Keeper Stick](https://learn.adafruit.com/meeting-time-keeper-stick-with-cpx.md)
