Servo8Bit Library version 0.6 released

The next version of the Servo8Bit library is released which includes the much sought after integration with Arduino libraries for the Attiny as well as other various improvements.

Here is a run down of what’s new:

  • Now works with various Arduino libraries for the Attiny45 and Attiny85.
  • Added support to run at 1mhz in addition to 8mhz.
  • Added ability to easily select if this library should use timer0 or timer1.
  • By default timer1 is now used. The old default used to be timer0.

Download the Servo8Bit library from its Github page here https://github.com/fri000/Servo8Bit .

ZIP button downloads all library files together

If you’re unfamiliar with Git Hub you should know that you can download all of the library files by click on the “ZIP” button, at the top left corner. Part of the download is an example program that shows you how to use the library on a bare bone Attiny. If you looking to use the Servo8Bit with an Arduino library check out this example, which shows you how to do just that.

When you use Servo8Bit with an Attiny Arduino library (such as the one found here) I recommended that you run the Attiny chip at 8mhz , instead of at 1mhz. The Arduino library uses it own interrupts (in order to keep track of time and what not) which sometimes fire at the same time as the interrupt used by the Servo8bit driver. The interrupts step on each other’s toe, so to speak. The effect is that sometimes the connected servo jerks a bit because the PWM pulse sent to it was too long. Running at 8mhz reduces this effect by a lot.


20 Comments on “Servo8Bit Library version 0.6 released”

  1. Jasper says:

    I’m still having some trouble with the library.

    When I use the Arduino servo sweep example (Arduino Uno) it works perfectly: it sweeps from left to right and back (0 – 180) so I know the servo is fine.

    But when I try to use your code with an ATtiny45, using the Arduino ATTiny library you mention above, on 8mhz and with this code:

    #include "Servo8Bit.h"
    Servo8Bit myServo;

    void setup(){
    myServo.attach(1);
    }

    void loop(){
    myServo.write(0);
    delay(2000);
    myServo.write(90);
    delay(2000);
    myServo.write(180);
    delay(2000);
    myServo.write(90);
    delay(2000);
    }

    I would expect the servo to move left, to the middle, right, and to the middle again, repeating this over and over. Instead, if I manually put the servo at his 90 position before connecting it, it will take steps of around 10 degrees to the left and then keeps ticking and trying to go further left.

    Your example file does the same thing: it keeps trying to go left.

  2. ilya says:

    From what you described it sounds the ATtiny45 is sending to the servo pulses that are way too short. A common way this happens is when the fuse bits are set such that they configure the ATtiny to run at 1mhz, but the code is complied to run at 8mhz. What do you have your fuse bit set to?

    • Jasper says:

      Totally missed that part.
      For others with the same ‘problem’: select your board, and the Arduino as programmer. Than hit ‘burn bootloader’. When that’s done, just upload your sketch.

      Thanks!

  3. pescadito says:

    Hi, i tested your library in a AtTiny85 and it worked perfectly to run 2 servos on pb0 and pb1.
    However i not sure how to connect 2 other more servo. Could i connect in any of the other pins? Could you give a example of how to connet 4 servo to a AtTiny85
    Best Regards, Pescadito

    • ilya says:

      Absolutely! You can connect up to 5 servos and they can be connected to any pin on port B. How were you able to get two servos to work but not four? You just copy and past the servos objects and set a different pin for each one, like this: http://pastebin.com/PfrfSXTh
      (ninja edit: updated link, had typo in previous one)

  4. pescadito says:

    hey ilya, thank you, i will have to put my hands on.
    i’m doing a litte serially configured and programed servo controlled with one pin for buttons, one pin for a led and three servos.
    best regard, pescadito

  5. pescadito says:

    Hello ilya, i get NewSoftSerial work well in AtTiny but regretably it is in conflict with Servo8Bit at the compile time.

    I haven’t any experience with timers and interrupts in avr. Please could you take a look http://pastebin.com/78zr3K6T and suggest any idea on how to correct it.

    Note to use NewSoftSerial from here http://code.google.com/p/arduino-tiny/issues/detail?id=49

    Best Regards, Pescadito

  6. Wayne says:

    I’m using your Servo8Bit with an ATTiny85 and, at RESET, I’m setting an initial neutral position for the servos just after attach() is called. However, I find that the servos always glitch to a different position, then quickly return back to the position the code set. Is there some way to avoid this? Is, perhaps, the code setting an initial position of its own for each servo that corresponds to the glitch position I see?

    • ilya says:

      I took a quick glance at the code and yes I did make it so that the servo gets powered as soon as you call attach(). If no position was ever set (such as your case on power up) then it will start moving to the default position, which is 90 degrees. Seems like I could change that behavior and leave the servo unpowered until the first call to write(). I haven’t looked at this code in a while. I need to peruse it a bit and see what adverse effects this change will have. If there would none I will update this library with this new behavior.

      In the mean time, you can make your problem go away by calling the function write() before you call attach(). This way you give the servo a position and when you call attach() it will go to that position immediately, without trying to go somewhere else for the first split second.

  7. Max says:

    Hi, I am using your library with a Attiny85 and ArduinoISP. Controlling one servo is already working fine but the attached pin is somehow always set to PB1. When I try to attach it to another port nothing happens.
    That makes it impossible to use more than one servo.
    Do you have any idea what Im doing wrong?

    #include “Servo8Bit.h”

    Servo8Bit LH;
    Servo8Bit RH;

    void setup() {

    LH.attach(2);
    RH.attach(1);
    }

    void loop() {
    for(int pos = 0; pos 1; pos–) // goes from 180 degrees to 0 degrees
    {
    LH.write(pos);
    RH.write(pos);
    delay(20); // waits 15ms for the servo to reach the position
    }

    }

    • ilya says:

      Your code looks like it should work. Let’s debug this. What happens if you have just one servo and you attach it to pin two?

  8. Max says:

    Thanks for helping me.
    When I attach a servo to pin to there is no reaction. The only working pin was pin 1.
    But it is already working somehow.
    I deleted the library and copied only the .h and .cpp files to the sketch folder.
    There has not been much time to test it but the servos seem to work with all pins now.
    By the way, are the degree values the same as in the library for Arduino Uno or do I need to adjust them?

  9. ilya says:

    Good to hear it’s working for you. The degree values are the same as in the library for the Arduino Uno. All of the Servo8bit functions are designed to behave exactly the same as their counterparts in the servo library for Arduino.

  10. Max says:

    Great, the robot I am building is supposed to walk so every degree is important to balance it.

  11. Max says:

    OK, now I plugged in 2 Servos and Uploaded the Program for the Walker.
    It is exactly the same as on the Uno but the servos are freaking out every few seconds and than go to their programmed path again.
    Do I have to separate the power for the Servos from the ATtiny or is it another Problem? It is actually planned to run on a single circuit and the servos are really small.

  12. Max says:

    Not a problem anymore.
    Only occurs at 5V from Arduino.
    When I use the 3.7V from the battery everything is running smoothly.

  13. Krist says:

    First off…thank you very much for putting together this library.

    I found the 0.6 version running on an ATtiny85 with internal 8MHz clock works fine. However, when I replace the .h/.cpp files with the 0.7 version, the servo doesn’t run. I didn’t change any code in the .ino file. Any idea what is happening?

    A separate question is regarding the 0.6 library version. When I use the same control program logic and compare the servo operation between standard arduino servo library and your 8-bit library I get a little jumping of the servo rather than a smooth sweep I get from the standard library. Can you explain why this would happen?

    Thanks
    Krist


Leave a Reply

Your email address will not be published.

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>