Servo8Bit Library Not Working

Hi Gang

I’d like to program an ATTiny via the Arduino IDE. Specifically, I’d like to use the Servo8Bit library but I’m not having much luck. I’ve read and downloaded the following;

ATTiny

Servo8Bit Library

I’ve placed both the above in my sketchbook folder as per Arduino preferences. ATTiny in hardware folder and Servo8Bit in software folder.

I’ve uploaded the following sketch to test.

#include "Servo8Bit.h"

Servo8Bit myServo;  //create a servo object.
                    //a maximum of five servo objects can be created


void setup()
{ 
  //myServo.attach(1,544,2400);  //this is the default values
  myServo.attach(1,544,2200);  //attach the servo to pin PB1      
}


void loop()
{
    
    for(int pos = 0; pos < 180; pos++)  // goes from 0 degrees to 180 degrees
    {                                   // in steps of 1 degree
        myServo.write(pos);             // tell servo to go to position in variable 'pos'
        delay(15);                      // waits 15ms for the servo to reach the position
    }

    for(int pos = 180; pos > 1; pos--)  // goes from 180 degrees to 0 degrees
    {
        myServo.write(pos);             // tell servo to go to position in variable 'pos'
        delay(15);                      // waits 15ms for the servo to reach the position
    }
}

When I upload this using the Arduino Uno as an ISP the servo doesn’t move.

If I use the SoftwareServo library then the servo does move.

// Sweep
// by BARRAGAN <http://barraganstudio.com> 
// This example code is in the public domain.


#include <Servo.h> 
 
Servo myservo;  // create servo object to control a servo 
                // a maximum of eight servo objects can be created 
 
int pos = 0;    // variable to store the servo position 
 
void setup() 
{ 
  myservo.attach(9);  // attaches the servo on pin 9 to the servo object 
} 
 
 
void loop() 
{ 
  for(pos = 0; pos < 180; pos += 1)  // goes from 0 degrees to 180 degrees 
  {                                  // in steps of 1 degree 
    myservo.write(pos);              // tell servo to go to position in variable 'pos' 
    delay(15);                       // waits 15ms for the servo to reach the position 
  } 
  for(pos = 180; pos>=1; pos-=1)     // goes from 180 degrees to 0 degrees 
  {                                
    myservo.write(pos);              // tell servo to go to position in variable 'pos' 
    delay(15);                       // waits 15ms for the servo to reach the position 
  } 
}

I’d prefer to use the Servo8Bit library as it has more functionality. Can someone suggest what I may be doing wrong?

Cheers

Jase :slight_smile:

Reports of problems with ATTiny servo libraries is exactly what prompted me to write my own from scratch:

http://forum.arduino.cc/index.php?topic=198337.0

Note: you will have to change from the HLT Core to this one: https://code.google.com/p/arduino-tiny/

What functionality does the Servo8bit library have that SoftwareServo lacks?

Hi tylernt

Thanks for getting back to me. So aside from changing the core is the process for uploading sketches identical (UNO as ISP etc)? Is the TinyServo library part of your core rather than an add on (similar to Arduino Servo library)? I particularly interested in the writeMicroseconds function as this gives me far more control a feature that is not available using the SoftwareServo library. Really appreciate your help.

Cheers

Jase :)

Once you load the new core and update boards.txt, yes, you program your ATTiny the same way you do now.

My library is not included in the core, though I would not object if the Tiny Core folks wanted to include it. For now, you must load it separately.

My library doesn't go down into the 1-microsecond range, but it does allow for finer grained control than just 0-180 degrees. You can specify the number of timer ticks to leave the signal pin HIGH, and how many timer ticks equates to how many microseconds depends on which ATTiny you're using (and if you have moved the core millis() to an alternate timer on ATtiny85). The included example sketch lists those timer tick options out for you in comments towards the end.

EDIT:

Looks like the ATtiny85's position accuracy is even worse than 1.0° since it has only an 8-bit timer, and that's what you're stuck with.

The ATtiny84 and x313, on the other hand, can do better (using the 16-bit timer). However, I have not optimized the timer prescaler for 16-bit operation, so you currently only get 0.8° precision. The prescaler could be changed to /8 instead of /64 and the data types changed to 'word' instead of 'byte' to get finer control on those two chips. I believe that would get you very close to 1-microsecond and 0.1° precision.

Hi tylernt

I'm using the ATTiny45 so I've taken on your advice and settled on using the SoftwareServo library. As stated earlier a really appreciate the help and wish you the best of luck with your project.

Cheers

Jase :)