Running a servo on ATTiny 85 using Servo8Bit Library

My previous attempt at getting a servo working on an ATTiny 85 gave jittery results. I’ve tried this second servo library – Servo8Bit.

I downloaded the code from GitHub. The ‘Makefile’ needed an update to change to the variable AVRDUDE_PROGRAMMER to ‘usbtiny’ to match my programmer. With a command prompt I navigated to the directory containing the downloaded code in, typed ‘make’ to compile the file then ‘make upload’ to put the code on the board using avrdude.

Initially I had some strange behaviour where the servo just juddered. It seems that the ATTiny 85 chips I had delivered were preset to 1 Mhz, whereas the library works better at 8 Mhz. I’m pretty out of my depth here, but I used this fuse calculator to set the chip to 8 Mhz (I think). I selected the ATTiny 85 from the drop down menu, then unticked the box labelled “Divide clock by 8 internally; [CKDIV8=0]”. Using the output at the bottom of the window I was able to create the following two lines which I ran in the command window (you will need to change the -c parameter to your programmer):

[Note: don’t blindly copy the below, I don’t know what I’m doing and I don’t want to be responsible for blowing up your chips. Please verify the settings yourself.]

avrdude -c usbtiny -p attiny85 -U lfuse:w:0xe2:m -U hfuse:w:0xdf:m
avrdude -c usbtiny -p attiny85 -U efuse:w:0xff:m

I typed ‘make upload’ again (still in the Servo8Bit Library directory) to reupload the code. This time the servo seemed to work smoothly until it reached the end of it’s run, where it does a small jump. I’m not sure what’s causing this, but at least the results are smoother than the last effort. I altered the min and max position of the servo to a smaller range (45 – 135) and that seems to work ok so hopefully it’s a working solution where the full range of the servo isn’t needed.

By the way, if you have the Arduino program set up to deploy to the ATTiny 85 (e.g. using the drivers from HLT at MIT) there’s an easy way to find out what frequency your chip is currently running at (this technique was suggested in the Servo8Bit comments). Open the example Blink sketch in Arduino and change the pin from 13 to 1, then send it to the ATTiny. Attach an LED plus resistor to pin 6 of the ATTiny. If the LED is going on/off once per second then you’re running at 1 Mhz, if it’s going on/off every 0.125 seconds then you’re running at 8 Mhz.


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s