Store › Forums › Digit Shield › Bugs/Problems › Use DigitShield together with Servo
- This topic has 5 replies, 2 voices, and was last updated 9 years, 6 months ago by
Michael.
-
AuthorPosts
-
February 20, 2015 at 11:13 am #752
cemonds
MemberHi,
i’m trying to use the DigitShield together with the standard Arduino Servo library. Unfortunately this doesn’t work as expected. When I use the unchanged library for the digit shield the servo shakes the whole time, a video can be seen at: http://youtu.be/DwVAE8tHC9M
When I tried to use the digit shield library using the other timer, the servo works as expected, but as soon as i callservo.attach(SERVO_PIN);
the digit shield stops working. Is there anyway I can use both, the servo library as well as the digit shield library, without interfering each other?
February 22, 2015 at 2:18 pm #2183Michael
KeymasterThe servo library uses timers and will interfere with any code that uses timers. The DigitShield code uses timers to control the refresh of the display. Many things in the Arduino world are not compatible with one another.
Are you familiar with how to control Arduino timers? If so, you could disable the Digit Shield display while you moved the servo, then turn it on again when the movement is done. Would that help?
February 22, 2015 at 8:07 pm #2185cemonds
MemberUnfortunately I permanently move the servo, so disabling the display is not an option. As far as i know the servo library uses only timer 1 on arduino uno, right? since the digit shield uses also timer 1 this seems to be the cause of the problem. There is some code (currently commented out) within the digit shield library for using timer 2 would that be an option? I tried to use this code path, but didn’t get it to work. Since this project is especially aimed at beginners i don’t want to use a non standard method to control the servo, but i would be glad to be able to use the digit shield also.
February 22, 2015 at 8:30 pm #2186Michael
KeymasterThe Digit Shield library uses timer2, not timer1. The commented-out code is for timer1.
You can certainly try different timers in the Digit Shield library if it helps get around compatibilty issues with your servo. You won’t break the Digit Shield. ;DFebruary 22, 2015 at 9:38 pm #2187cemonds
MemberYou are right about the timer2, sorry. Ok, I made some tests and found a workaround. It seems if using the servo library somehow disables the ISR of the DigitShield library and so the display is not updated. If i don’t use any delay() and call regularly DigitShield.isr() in my loop() the display is working. Right now I have no idea why the workaround is necessary but I can live with that. Thanks for your assistance 🙂
February 22, 2015 at 10:34 pm #2188Michael
KeymasterGood job. Sometimes a quick hack is good enough.
-
AuthorPosts
- You must be logged in to reply to this topic.