Use DigitShield together with Servo

Store Forums Digit Shield Bugs/Problems Use DigitShield together with Servo

Viewing 6 posts - 1 through 6 (of 6 total)
  • Author
    Posts
  • #752
    cemonds
    Member

    Hi,

    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 call

    servo.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?

    #2183
    Michael
    Keymaster

    The 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?

    #2185
    cemonds
    Member

    Unfortunately 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.

    #2186
    Michael
    Keymaster

    The 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. ;D

    #2187
    cemonds
    Member

    You 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 🙂

    #2188
    Michael
    Keymaster

    Good job. Sometimes a quick hack is good enough.

Viewing 6 posts - 1 through 6 (of 6 total)
  • You must be logged in to reply to this topic.