ATtiny Hacks: ATtiny45/85 Servo Library

ATtiny Hacks Theme Banner

Servo8bit is a library for AVR microcontrollers that allows you to drive servo motors without the need for a 16-bit timer. Obviously, this is quite useful for smaller chips that only have 8-bit timers and it is specifically targeted at the ATtiny45 and ATtiny85 microcontrollers. The library offers 256 steps of resolution, and can drive up to five servos at one time. Servo control pulses can be generated between 512 and 2560 microseconds and if you don’t mind increasing the time between these pulses [Liya] says it would be possible to increase the 5-servo limit.

The library is quite easy to use, but in its current state it would take just a bit of work to port to another device. It’s been written for an 8 Mhz clock signal with PortB used to drive the motors. Using find-and-replace to change the PORTB keywords to use a DEFINE variable should be easy enough, but we don’t know how hard it would be to change the clock frequency.

We wonder if it’s possible to make this a slave device, perhaps implementing a 1-wire protocol?

6 thoughts on “ATtiny Hacks: ATtiny45/85 Servo Library

  1. I have always been looking for a good multi-servo driver chip. I have tried making my own (failed), getting a PICAXE 08M to do it (only support 2 servos) and even considered buing one of these “servo controller” chips that are just a 8 pin PIC programmed with some proprietary code on which I don’t want to depend.

  2. Arduino: 1.6.11 (Windows 10), Board: “ATtiny25/45/85, ATtiny45, Internal 8 MHz”

    In file included from C:\Users\Amin\AppData\Local\Arduino15\packages\arduino\hardware\avr\1.6.10\cores\arduino/Stream.h:26:0,

    from C:\Users\Amin\AppData\Local\Arduino15\packages\arduino\hardware\avr\1.6.10\cores\arduino/HardwareSerial.h:29,

    from C:\Users\Amin\AppData\Local\Arduino15\packages\arduino\hardware\avr\1.6.10\cores\arduino/Arduino.h:224,

    from sketch\sketch_sep19c.ino.cpp:1:

    C:\Users\Amin\AppData\Local\Arduino15\packages\arduino\hardware\avr\1.6.10\cores\arduino/Print.h:32:0: warning: “BIN” redefined

    #define BIN 2


    In file included from c:\program files (x86)\arduino\hardware\tools\avr\avr\include\avr\iotn45.h:38:0,

    from c:\program files (x86)\arduino\hardware\tools\avr\avr\include\avr\io.h:426,

    from c:\program files (x86)\arduino\hardware\tools\avr\avr\include\avr\pgmspace.h:90,

    from C:\Users\Amin\AppData\Local\Arduino15\packages\arduino\hardware\avr\1.6.10\cores\arduino/Arduino.h:28,

    from sketch\sketch_sep19c.ino.cpp:1:

    c:\program files (x86)\arduino\hardware\tools\avr\avr\include\avr\iotnx5.h:55:0: note: this is the location of the previous definition

    #define BIN 7


    sketch\sketch_sep19c.ino.cpp.o: In function `main’:

    C:\Users\Amin\Downloads\Servo8Bit-master\Servo8Bit-master\sketch_sep19c/sketch_sep19c.ino:4: multiple definition of `main’

    sketch\example.cpp.o:sketch/example.cpp:14: first defined here

    collect2.exe: error: ld returned 1 exit status

    exit status 1
    Error compiling for board ATtiny25/45/85.

    This report would have more information with
    “Show verbose output during compilation”
    option enabled in File -> Preferences.

    It shows the message above and does not even pass compilation for my attiny45!!! what should i do?

Leave a Reply

Please be kind and respectful to help make the comments section excellent. (Comment Policy)

This site uses Akismet to reduce spam. Learn how your comment data is processed.