Pololu Robotics & Electronics
My account Comments or questions? About Pololu Contact Ordering information Distributors

Servo with zumo 32u4


Dear sir/mam
i have a problem with robot zumo 32u4. I like to use servo with it. I change timer1 to timer3 in servo.h ready . After that .The robot can use servo but can not use motor.How to use servo and motor together? I dont know what happend. How to fix it.

This is my code.

include <32u4.h>
include <servo.h>
Zumo32U4ButtonA buttonA;
Zumo32U4ButtonB buttonB;
Zumo32U4ButtonC buttonC;
Zumo32U4Motors motors;
Zumo32U4LCD lcd;
Servo myservo1; // create servo object to control a servo

void setup() {

lcd.print(F("Press A"));

myservo1.attach(5); // attaches the servo on pin 5 (PC6) to the servo object

motors.setSpeeds(200, 200);
motors.setSpeeds(0, 0);


void loop() {
myservo1.write(10); // sets the servo position according to the scaled value
delay(15); // waits for the servo to get there
lcd.print(F("pos 10"));

myservo1.write(100); // sets the servo position according to the scaled value
delay(15); // waits for the servo to get there
lcd.print(F("pos 100"));





It is not clear to me how you modified the Servo Arduino library to use Timer 3 instead of Timer 1. If you have not already done so, you should look at the “Controlling a servo with an Arduino Leonardo or A-Star 32U4 Prime” section in the Pololu Zumo Shield for Arduino User’s Guide for details on how to modify the Servo.h file to make that change so that the Servo library does not interfere with the Zumo32U4Motors library. (Note that the ZumoMotors library also uses Timer 1.)

If you have modified the Servo library correctly and the issue still persists, can you verify that your motors are working by running the MotorTest.ino example sketch on your Zumo 32U4 robot? Can you be more specific about what happens when you run your sketch? Posting a video would be best.

Also, can you post your Servo.h file here as an attachment?

- Amanda


Hello Amandas
With your suggesttion . I did follow the Pololu Zumo Shield fo Arduino User’s Guide in 8b controling a servo with an Arduino Leonado or
A Star 32u4 Prime. "t 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. " and I have modify servo.h already. (change from timer1 to timer3) In the first try after modify servo.h the servo can work normal but motor did not normal
when i run sketch motortest.ino the left motor is work normal it can rotate forward and backward but the right motor only forward rotate.
so I try to copy ServoTimers.h (timer3) into folder libraries/Servo/src/avr/ServoTimers.h. again. and try to run sketch motortest.ino,followline.ine,
encoder.ino,servotest.ino amazing! the robot can run all sketch.I don’t know what the reason. I happy that it can run. Thank you very much
for your suggestion.

     this is ServoTimer.h

 * Defines for 16 bit timers used with  Servo library
 * If _useTimerX is defined then TimerX is a 16 bit timer on the current board
 * timer16_Sequence_t enumerates the sequence that the timers should be allocated
 * _Nbr_16timers indicates how many 16 bit timers are available.

 * AVR Only definitions
 * --------------------

// Say which 16 bit timers can be used and in what order
#if defined(__AVR_ATmega1280__) || defined(__AVR_ATmega2560__)
#define _useTimer5
#define _useTimer1
#define _useTimer3
#define _useTimer4
typedef enum { _timer5, _timer1, _timer3, _timer4, _Nbr_16timers } timer16_Sequence_t;

#elif defined(__AVR_ATmega32U4__)
#define _useTimer3
typedef enum { _timer3, _Nbr_16timers } timer16_Sequence_t;

#elif defined(__AVR_AT90USB646__) || defined(__AVR_AT90USB1286__)
#define _useTimer3
#define _useTimer1
typedef enum { _timer3, _timer1, _Nbr_16timers } timer16_Sequence_t;

#elif defined(__AVR_ATmega128__) || defined(__AVR_ATmega1281__) || defined(__AVR_ATmega1284__) || defined(__AVR_ATmega1284P__) || defined(__AVR_ATmega2561__)
#define _useTimer3
#define _useTimer1
typedef enum { _timer3, _timer1, _Nbr_16timers } timer16_Sequence_t;

#else  // everything else
#define _useTimer1
typedef enum { _timer1, _Nbr_16timers } timer16_Sequence_t;


Thank you for posting your modifications to the Servo library and letting us know that your issue has been resolved.

By the way, I added code tags to your post to make your code more readable. Please use this method to post code in the future. To see the modification, click on the pencil icon in the upper right-hand corner of the edited post and view the raw source.

- Amanda