8.b. Controlling a servo with an Arduino Leonardo or A-Star 32U4 Prime

It is possible to modify the Servo library that comes with the Arduino IDE to use Timer 3 instead of Timer 1 on the Arduino Leonardo or A-Star 32U4 Prime. The modified Servo library does not interfere with ZumoMotors, making it possible to simultaneously control servos and the motors.

Warning: The modifications described here will affect any sketch for the Arduino Leonardo or A-Star that uses the Servo library.

  1. First, you will need to locate the Arduino IDE’s Servo library, and find the file inside it named ServoTimers.h. For the 1.6.x versions of the IDE, this file can be found in libraries/Servo/src/avr/ServoTimers.h. If you are using Mac OS X, you will need to right-click on the Arduino IDE icon and select “Show Package Contents” to see the files inside.
  2. Open ServoTimers.h in a text editor.
  3. Locate the following lines of code in ServoTimers.h:
    #elif defined(__AVR_ATmega32U4__)  
    #define _useTimer1 
    typedef enum { _timer1, _Nbr_16timers } timer16_Sequence_t ;
  4. The lower two lines of code specify that the library should use Timer 1. To use Timer 3 instead, just change _useTimer1 to _useTimer3 and _timer1 to _timer3.
  5. Save the file.

The Arduino IDE will automatically incorporate your modifications to the Servo library. The next time you compile a sketch for the Arduino Leonardo or A-Star that uses the Servo library, it will use Timer 3 instead of Timer 1.

Related Products

Zumo Reflectance Sensor Array
Zumo Shield for Arduino, v1.2
Zumo Robot Kit for Arduino (No Motors)
Zumo Robot for Arduino (Assembled with 75:1 HP Motors)
Zumo Shield for Arduino, v1.3
Log In
Pololu Robotics & Electronics
Shopping cart
(702) 262-6648
Same-day shipping, worldwide
Menu
Shop Blog Forum Support
My account Comments or questions? About Pololu Contact Ordering information Distributors