Zumo shield and Servos

Is it possible to use the Zumo shield to still control the motors AND operate a couple servos? Maybe modify the servo.h library for my Uno? Put the motors on some other pins than 9 and10? Maybe I should just by a Leonardo? Would that fit on Zumo shield? Im new with so many questions. Thanks

The Servo library on modern Arduinos does not require any particular pins for servos. It can drive any pins for servo control signals.
The main question I would have would be how you get sufficient power to the servos.

I thought there was a conflict with Servo.h library and pins 9 and 10 of the Zumo motos? I am mounting a gripper to the Zumo shield. It uses two servos. It will use the Sharp distance sensor to run around and grab stuff. I tried several times to post a jpg picture but it always says invalid file format?? Servo power will just come from the battery pack directly to the center pin or red power plug on servos. Of course the grounds all have to be tied together, one going to Arduino board. I learned that lesson.
I guess my question is how to program the two servos and still use zumo motor library. Thanks!

I see what you’re getting at. Pins 9 and 10 use Timer 1 (the 16-bit timer) if you want to do PWM, so the Zumo support library takes over timer 1. Which Servo.h also does.
If you drive pins 9 and 10 only using digital write (full or nothing,) then you can use the Servo.h library (and not use the Zumo support library.)

If you want to generate servo control pulses manually, you can do this with a busy-wait poll loop. However, you can’t do anything else while doing this, which may or may not be OK for you. You can drive multiple pins in parallel this way, too, with a bit of software panache.


// run this every 20-50 milliseconds
digitalWrite(SERVO_PIN, HIGH);
delayMicroseconds(1750); // or whatever
digitalWrite(SERVO_PIN, LOW);

This will jitter a little bit because of the interrupt handlers in the Arduino support library. Thus, you can disable interrupts before this code, and enable interrupts after it, for better timing.

If you want to run multiple pins at the same time, you’re probably better off addressing them directly with PORTB or PORTD or whatever:

PORTB |= 0x13;
PORTB &= ~0x10;
PORTB &= ~0x3;

This will turn on pins 8, 9, and 12, and turn off pin 12 after 1200 microseconds and pins 8 and 9 after 1400 microseconds (give or take a little bit.)

Hi, patman715.

We have some information on controlling a servo with a Zumo-mounted Arduino in the Zumo shield user’s guide. We have some example code for controlling a single servo using Timer 2 on the Uno, but that might not work for you if you need to control more than one. It’s easy to modify the Leonardo’s Servo library to use Timer 3 instead of Timer 1, so I’d suggest trying that approach.

- Kevin

The “delayMicroseconds(1750)” command then acts similiar to the library in that 1500 or 1750us would center the servo? And 0 would reverse it to one end of the range and say 2500 or depending on the servo, the other end of rotation? Stopping or pausing here in the loop should be no problem. I appreciate your help.

Kevin thanks. I assume then a Leonardo will fit on Zumo shield and I wont lose the cool buzzer sounds then. The Sharp distance sensor chirps a signal frequency according to the distance voltage creating a cool sound based on how far away object is.
Just placed my order for Leonardo and looked over 8.1a and b again. Ive never created a library but maybe I should modify servo.h and call it servo2.h? Then #include servo2.h IDE doesnt allow editing .h files, does it?

Our libraries use the Leonardo’s Timer 4 to drive the buzzer, so I think you should be able to do everything you want at once (motors, servos, and buzzer).

- Kevin

Yes, 1500 centers the servo, 1000 goes 45 degrees one way; 2000 goes 45 degrees the other way. If it’s a 180 degree servo, the range expands to 500…2500

If you can use a Leonardo with a modified library, that’s probably even simpler, though :slight_smile:

It is SO Cool it works!

That looks fun! Do you have any videos of it in action?

- Kevin

Zumo grabber: youtu.be/w-1GWoCI3GU

Can I upload mp4 directly here?


Cool robot! We would like to add your project to our community blog posts. Have you posted a write-up about it somewhere? If not, we would be interested to know if you used anything else from us.

I do not think you can upload .mp4 files to our forum; is there a reason you want to do so? Since the video is uploaded to YouTube, you could just embed it in a post.