Fork me on GitHub

Project Notes

#603 ATTiny Servo Drive

Testing various methods and libraries for driving servo motors with an ATtiny85.

Build

Notes

I’d like to use some mini servo motors with an ATtiny85. The standard Arduino Servo library doesn’t work with the ATtiny, so this project is a survey and test of available techniques.

TBH, I thought this would be an easy proposition, but I ran into trouble with many of the sources I found

Construction

Here’s the basic setup. By default I have the ATtiny85 flashed for 8MHz internal clock, and I’m using PB4 (pin 3 on the DIP8 ATTiny85) as the servo control pin.

Breadboard

Schematic

SoftwareServo

There are a few versions of the SoftwareServo library floating around the web, so I cloned the most recent (as none are setup to be imported as a module).

This is the most bare-bones approach - it doesn’t modify timers or PWM, but just requires a callback that uses the current Timer0 count to figure out what to do next with the servo.

Aside from needing to ensure the refresh callback is made, this library is a win - simple and it works.

See UsingSoftwareServo.ino for the sketch I used for testing.

Here’s a quick demo..

clip

PrecisionServo

The PrecisionServo library promises more bells an whistles. I had to clone the library as it was not setup to be imported as a module.

There seems to be a baked-in timing assumption somewhere (I haven’t found yet), as it doesn’t work properly when the ATtiny85 is set to run at 8MHz internal clock.

When I reduce the ATtiny to 1MHz internal clock, it works fine.

See UsingPrecisionServo.ino for the sketch I used for testing.

Servo8Bit

The Servo8Bit library is specifically designed to work with 8-bit timers (e.g ATTiny), using timer interrupts to avoid needing callbacks.

But - it doesn’t work. The code looks like it is doing all the right things, but I’ve yet to discover what is going wrong.

I am little suspicious - the “examples” shown on the web have the servo plugged into PB1. When I initialise the Servo8Bit, I see what I think is the OC1A counter output on PB1, but no output changes on the servo pin I have configured. It looks like the library is not initializing the timer register correctly, but I haven’t gone any further than that.

See UsingServo8Bit.ino for the sketch I used for testing.

Credits and References

About LEAP#603 ArduinoAVRServo
Project Source on GitHub Project Gallery Return to the LEAP Catalog

This page is a web-friendly rendering of my project notes shared in the LEAP GitHub repository.

LEAP is just my personal collection of projects. Two main themes have emerged in recent years, sometimes combined:

  • electronics - usually involving an Arduino or other microprocessor in one way or another. Some are full-blown projects, while many are trivial breadboard experiments, intended to learn and explore something interesting
  • scale modelling - I caught the bug after deciding to build a Harrier during covid to demonstrate an electronic jet engine simulation. Let the fun begin..
To be honest, I haven't quite figured out if these two interests belong in the same GitHub repo or not. But for now - they are all here!

Projects are often inspired by things found wild on the net, or ideas from the many great electronics and scale modelling podcasts and YouTube channels. Feel free to borrow liberally, and if you spot any issues do let me know (or send a PR!). See the individual projects for credits where due.