Using Servo.h with robot Zumo32u4

Hello.
At first sorry for my english, but I don’t use it too often.
I have got big problem with my zumo32u4 robot. I want to add servo to it. But servo.h library uses the same timer as zumo32u4 robot’s motors - timer1. On this forum I already found solution for this problem (Servo with zumo 32u4)- It needs to change timer1 to timer3 in ServoTimers.h . But I can’t do it becouse I’m already using timer3 for creating softwareserial port by “Altsoftserial.h” library - for my bluetooth module. I need to use altsoftserial.h library becouse I use already Serial1 port for another sensor. I was trying not to change any timers and using timer1 for servo and motors, but not at the same time - before using motors I detached my servo (myservo.detach()) in my programm, and before using commend "myservo.attach(PIN) I made motors not working. But the problem is that motors dont want to work after single usage of servo. I’m not using timer4 for anything but when I’m changing timer1 to timer4 in Servo.h library there is a fault by compiling the code.
I hope for your help.
Mateusz

Hello, Mateusz.

Timer4 is a 10-bit timer on the ATmega32U4 and the Arduino servo library appears to be designed for 16-bit timers, so modifying that library is probably going to be quite difficult to do. You might try manually timing your pulses using the Arduino’s delayMicroseconds function to control your servo.

- Amanda

Thank you very much for your answer.
I read about this solution on some forums, but I didn’t try to enter it to my project becouse I also read that by manually timing the pulses, there is impossible to do anything in the meantime. And I need to read the value from the sensor, which is mounted on the servo in the meantime. But after your answer i tried to do this and it worked. I’m sending for some short time signal adequate to the servo position, which I want to reach, then write LOW on the pin which controls servo, read the value from the sensor and do it again and again becouse as a final effect i want to scan all of the space in front of my robot. Thank you for your help.
Mateusz.

1 Like