Introduction: Add an Encoder to Feetech Micro 360 Degree Continuous Rotation Servo FS90R

About: "I'm so full of ideas and here's a good one..." Here I go again creating another prototype and proof of concept for one of my ideas from the Black Magic AI idea factory.

It's very difficult or next to impossible to precisely control wheeled robot motion using open loop motor control. Many applications require accurately setting the pose or travel distance of a wheeled robot. Small continuous rotation micro servo motors are a great low cost solution to drive small robots but they lack the feedback control of larger servo motors.

The Feetech Micro 360 Degree Continuous Rotation Servos (FS90R) are great for robotics projects but sometimes you want the feedback control of larger servos.

Converting these little servos to use closed loop position feedback control is actually very easy once you add a Tamiya analog Encoder sensor and a simple closed loop feedback algorithm to an Arduino or Raspbery Pi controller.

Step 1: Parts Needed

  • FeeTech 9g Continuous Rotation Micro Servo w/ round servo horn Vendor:RobotShop Part #:RB-Fit-02 Qty:1 Unit Cost:$4.99 Total:$4.99

  • Arduino NG w/ ATmega8 or similar Arduino microcontroller
  • Encoder Pair for Tamiya Twin Motor Gearbox Vendor:RobotShop Part #:RB-Rbo-122 Qty:1

  • Avery 8160 1" x 2-5/8" Address labels Vendor: Office Depot Qty: 1 sheet Total: $13.99 pack (25 sheets)
  • Encoder disk graphic from github
  • 5V portable phone charger with Micro USB to USB-A charging cable Vendor: Best Buy Tzumi - PocketJuice Solo 4000 mAh Portable Charger Model:4021BB Part #: 6304825

Raspberry Pi Option

  1. Raspberry Pi 3 - Model B Vendor: Adafruit SKU:PRODUCT ID: 3055
  2. Or Raspberry Pi Zero W Basic Pack - Includes Pi Zero W Vendor: Adafruit Part #:PRODUCT ID: 3409Qty: 1

If you are using a Raspbery Pi or Pi Zero W two additional Pi HATs are needed:

  1. Pimoroni Automation pHAT for Raspberry Pi Zero Vendor: Adafruit Part #:PRODUCT ID: 3352Qty: 1
  2. SparkFun Pi Servo HAT Vendor: SparkFun Part #: DEV-14328Qty: 1
  3. GPIO Stacking Header - Extra-long 2x20 Pins Vendor: Adafruit Part #:PRODUCT ID: 2223Qty: 2

Step 2: Tools Needed

  • Mini Philips Screwdriver
  • Glue Gun & Glue stick or Super Glue
  • Needle Nose pliers
  • A soldering Iron and solder are needed for the Raspberry Pi version (Optional)

Step 3: Print Out the Encoder Disk Graphic Onto the Address Label Paper

  1. Open the Encoder_disk.pdf and print it onto the Avery 8160 address label paper
  2. Use scissors to cut out the Encoder disk graphic along the dashed lines from the label paper and cut out the center hole using the dashed line as a guide

Step 4: Attach the Encoder Disk Graphic to the Round Servo Horn

  1. Peel off the paper backing from the encoder disk graphic from Step 3
  2. Attach the encoder disk graphic to the back of the round servo horn and center the encoder disk graphic hole around the servo horn spline boss
  3. Smooth out the encoder disk graphic to remove any air bubbles or wrinkles

Step 5: Attach the Tamiya Analog Encoder to the Micro Servo Motor

  1. Place a small drop of hot melt or super glue onto the micro servo motor shaft boss. Use hot melt glue as a temporary fastener but use super glue for the final permanent attachment.
  2. Attach the Tamiya Analog encoder ensuring that the hole in the Tamiya Analog encoder circuit board is centered around the micro servo motor shaft with the sensors pointing up/away from the motor

Step 6: Modify Encoder Sensor Cables

  1. The cables provided with the Tamiya Analog encoder need to be modified to work with standard ground-5V-signal configuration on microcontroller analog input pins
  2. Swap ground and 5V wires on one end of the Analog sensor cable so that the 5V wire is in the center of the pin connector and the ground and signal wires are on the edge position of the pin connector
  3. Attach the unmodified end of the cable to the Tamiya Analog encoder pins
  4. Attach the modified end of the cable to the analog input pins of the Arduino microcontroller ensuring that the ground wire on the Arduino pin is connect to the ground pin of the Tamiya Analog encoder
  5. Attach the Micro Servo motor PWM cable to the D9 PWM pins of your Arduino microcontroller

Step 7: Attach Round Servo Horn to Micro Servo Motor

  1. Mount the round servo horn with the encoder disk graphic onto the micro servo motor shaft and attach it using the provided servo horn attachment screw

Step 8: Hardware Connections

Arduino Version

  1. Connect the modified end of the encoder sensor cable to the Analog 4 port of the Arduino observing the correct Ground-5V-Signal pin orientation
  2. Connect the Micro Servo Motor PWM connector to the D9 pins of the Arduino controller
  3. Connect Arduino to a power supply

Raspberry Pi Version

  1. Stack the Pimoroni Automation Phat to the Raspberry Pi GPIO header
  2. Stack the SparkFun Pi Servo HAT on top of the Pimoroni Automation Phat
  3. Connect the Signal pin of the Analog Encoder sensor to the ADC 1 connection on the Pimoroni Automation Phat
  4. Connect the Ground and 5V pins of the Analog Encoder sensor connector to the respective Ground and 5V connections on the Pimoroni Automation Phat
  5. Ensure that the SparkFun Pi Servo HAT Power supply isolation jumper is in open mode (see vendor manual) before connecting the battery power to the hat
  6. Connect battery power to the Raspberry Pi and SparkFun Pi Servo HAT

Step 9: Download and Run the Micro Servo Motor Encoder Demo Code

    Arduino Version

    1. Copy, clone or download the Arduino Encoder Encoder.ino, Encoder.h and Encoder.cpp demo code from github
    2. Open the demo code in the Arduino IDE and select your board from the IDE Tools menu
    3. Upload the code to your board
    4. Once the Arduino board resets it will start the program and run through a sequence of predefined motions that illustrate how to control the Micro servo motor using the Tamiya Analog encoder

    Raspberry Pi Version

    1. Copy, clone or download the encoder.py Python Encoder demo code from github onto your Raspberry Pi SD card
    2. Open the demo code in the Python 3 Idle IDE and run the code from the IDE Run menu
    3. Once the program starts it will start the program and run through a sequence of predefined motions that illustrate how to control the Micro servo motor using the Tamiya Analog encoder. Uncomment to code labelled interactive mode to enter position commands from the Python shell command line

    Step 10: Try the Online Robot Demo

    1. You can test an example robot with encoder controlled Micro Servo motors on the free droidguru.net Web site
    2. Goto: droidguru.net. Watch the tutorial first if you don't know how it works (Help menu). Joystick steers the robot and the A button fires the Airsoft gun unless it's out of BB's or battery dies. (Best when viewed on a laptop/desktop computer)
    3. Follow these steps to start using the example robot
      • Login as a Guest
      • Select the Wheels room from the Join Room Panel
      • Select the Drone Patrol 1 robot from the Room members panel
      • After the countdown timer completes you can control the robot with the joystick or jog buttons
      • Reselect the Drone Patrol 1 robot from the Room members panel to start a new robot control session
    4. The virtual joystick steers the robot and the joystick job arrow buttons control jog/vernier/incremental motor movements using the Analog encoders to better align the airsoft gun with the targets