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

<p>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.</p> <p class="note_warning"><strong>Warning:</strong> The modifications described here will affect any sketch for the Arduino Leonardo or A-Star that uses the Servo library.</p> <ol> <li>First, you will need to locate the Arduino IDE&#8217;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 <em>libraries/Servo/src/avr/ServoTimers.h</em>. If you are using Mac OS X, you will need to right-click on the Arduino IDE icon and select &#8220;Show Package Contents&#8221; to see the files inside.</li> <li>Open ServoTimers.h in a text editor.</li> <li>Locate the following lines of code in ServoTimers.h:<br/> <pre name="code" class="c">&#x000A;#elif defined(__AVR_ATmega32U4__) &#x000A;#define _useTimer1 &#x000A;typedef enum { _timer1, _Nbr_16timers } timer16_Sequence_t ;</pre></li> <li>The lower two lines of code specify that the library should use Timer 1. To use Timer 3 instead, just change <code>_useTimer1</code> to <code>_useTimer3</code> and <code>_timer1</code> to <code>_timer3</code>.</li> <li>Save the file.</li> </ol> <p>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.</p>

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