Attiny85 and servo

I am at a breaking point here.
I have the attiny85 and cunning turtle (servo8bit) library.

#include <Servo8Bit.h>













Servo8Bit myServo;  //create a servo object.


void setup()
{



  myServo.attach(0);  
  delay(1);


}

void loop()
{
  myServo.writeMicroseconds(1500);
  delay(1000);
}

There's the code. All it's supposed to do is start up and make the continuous rotation servo spin. It doesn't spin. It doesn't do anything. I'm out of patience. i've been waiting a few months now for an updated servo library to surface but nothing has come up. I need help here.

Have you looked at the example he used in his GITHUB library? He has written his own delay functions to avoid conflicts with timer0.
see: Servo8Bit/example.cpp at master · fri000/Servo8Bit · GitHub

I suspect if you add the delay functions at the end of your code and the forward declaration at the top it might actually work.

nicoverduin:
Have you looked at the example he used in his GITHUB library? He has written his own delay functions to avoid conflicts with timer0.
see: Servo8Bit/example.cpp at master · fri000/Servo8Bit · GitHub

I suspect if you add the delay functions at the end of your code and the forward declaration at the top it might actually work.

// Servo8Bit Example code
// Ilya Brutman

#include "Servo8Bit.h"
void delay(uint16_t milliseconds);  //forward declaration to the delay function

Servo8Bit myServo;  //create a servo object.
int led = 0;

void setup()
{
  
                        

    myServo.attach(0);  //attach the servo to pin PB3
    delay(1);

   
}
    
   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(1);                      // 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(1);                      // waits 15ms for the servo to reach the position
        }
    }
void delay(uint16_t milliseconds)
{
    for(uint16_t i = 0; i < milliseconds; i++)
    {
        delayMicroseconds(1000);
    }
}//end delay

Like this? I try this and I get an error saying "call of overloaded 'delay(int)' is ambiguous".

Well, call it myDelay or some different name.

And while you aare at it, may as well add his function of delayMicroSeconds also:

void delayMicroseconds(uint16_t us)
{
#if F_CPU >= 16000000L
    // for the 16 MHz clock on most Arduino boards

    // for a one-microsecond delay, simply return. the overhead
    // of the function call yields a delay of approximately 1 1/8 us.
    if (--us == 0)
        return;

    // the following loop takes a quarter of a microsecond (4 cycles)
    // per iteration, so execute it four times for each microsecond of
    // delay requested.
    us <<= 2;

    // account for the time taken in the preceeding commands.
    us -= 2;
#else
    // for the 8 MHz internal clock on the ATmega168

    // for a one- or two-microsecond delay, simply return. the overhead of
    // the function calls takes more than two microseconds. can't just
    // subtract two, since us is unsigned; we'd overflow.
    if (--us == 0)
        return;
    if (--us == 0)
        return;

    // the following loop takes half of a microsecond (4 cycles)
    // per iteration, so execute it twice for each microsecond of
    // delay requested.
    us <<= 1;

    // partially compensate for the time taken by the preceeding commands.
    // we can't subtract any more than this or we'd overflow w/ small delays.
    us--;
#endif

    // busy wait
    __asm__ __volatile__ (
        "1: sbiw %0,1" "\n\t" // 2 cycles
        "brne 1b" : "=w" (us) : "0" (us) // 2 cycles
    );
}//end delayMicroseconds

And what's with

all the blank lines in your code?

It doesn't make it any more readable.

// Servo8Bit Example code
// Ilya Brutman

#include "Servo8Bit.h"
void mydelay(uint16_t milliseconds);  //forward declaration to the delay function

Servo8Bit myServo;  //create a servo object.
int led = 0;

void setup()
{
  myServo.attach(0);  //attach the servo to pin PB3
    delay(1);
}
   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(1);                      // 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(1);                      // waits 15ms for the servo to reach the position
        }
    }
void mydelay(uint16_t milliseconds)
{
    for(uint16_t i = 0; i < milliseconds; i++)
    {
        delayMicroseconds(1000);
    }
}//end delay

I put it as mydelay, but still no luck.
By the way, should I be using the attiny on a 1mhz or 8 mhz clock?

Does it works with another arduino? Double check connections.
However, I have heard that attiny is not fully compatible with arduino - few libraries/ functions might not work

ky9129:
Does it works with another arduino? Double check connections.
However, I have heard that attiny is not fully compatible with arduino - few libraries/ functions might not work

The connections are simple.

The servo is hooked into the proper pins on the programmer.
For some reason though, the servo spins on pin 1 of the attiny, but that's all it does. Spin.

// Servo8Bit Example code
// Ilya Brutman

#include "Servo8Bit.h"
void mydelay(uint16_t milliseconds);  //forward declaration to the delay function

Servo8Bit myServo;  //create a servo object.
int led = 0;

void setup()
{
  myServo.attach(0);  //attach the servo to pin PB3
    delay(1);
}
   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(1);                      // 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(1);                      // waits 15ms for the servo to reach the position
        }
    }
void mydelay(uint16_t milliseconds)
{
    for(uint16_t i = 0; i < milliseconds; i++)
    {
        delayMicroseconds(1000);
    }
}//end delay

How hard is it to write a library? I think it may be quicker for me to write one instead of waiting for cunningturtle to update his.

WireJunky:

[quote author=Nick Gammon link=topic=183185.msg1357096#msg1357096 date=1376809141]
Well, call it myDelay or some different name.

// Servo8Bit Example code
// Ilya Brutman

#include "Servo8Bit.h"
void mydelay(uint16_t milliseconds);  //forward declaration to the delay function

Servo8Bit myServo;  //create a servo object.
int led = 0;

void setup()
{
  myServo.attach(0);  //attach the servo to pin PB3
    delay(1);   // <---------- mydelay (1);
}

I put it as mydelay, but still no luck.
By the way, should I be using the attiny on a 1mhz or 8 mhz clock?
[/quote]

Yes but you have to call mydelay, not delay.

Yes but you have to call mydelay, not delay.
[/quote]

What do you mean by call mydelay?
Forgive my ignorance, I'm a beginner in this stuff.

    delay(1);

This line calls (invokes) the function. Thus if you are renaming delay as mydelay you have to do it everywhere in the sketch. You haven't done that.

// Servo8Bit Example code
// Ilya Brutman

#include "Servo8Bit.h"
void mydelay(uint16_t milliseconds); //forward declaration to the delay function

Servo8Bit myServo; //create a servo object.
int led = 0;

void setup()
{
myServo.attach(1); //attach the servo to pin PB3
mydelay(1);
}
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'
mydelay(1); // 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'
mydelay(1); // waits 15ms for the servo to reach the position
}
}
void mydelay(uint16_t milliseconds)
{
for(uint16_t i = 0; i < milliseconds; i++)
{
delayMicroseconds(1000);
}
}//end delay

Like this? I must be missing something, this doesn't work either.

Can you put your code in code tags please, and post your error message?

Read this before posting a programming question

this doesn't work

... doesn't tell us much. It doesn't compile? It doesn't run?

// Servo8Bit Example code
// Ilya Brutman

#include "Servo8Bit.h"
void mydelay(uint16_t milliseconds);  //forward declaration to the delay function

Servo8Bit myServo;  //create a servo object.
int led = 0;

void setup()
{
  myServo.attach(1);  //attach the servo to pin PB3
    mydelay(1);
}
   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'
            mydelay(1);                      // 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'
            mydelay(1);                      // waits 15ms for the servo to reach the position
        }
    }
void mydelay(uint16_t milliseconds)
{
    for(uint16_t i = 0; i < milliseconds; i++)
    {
        delayMicroseconds(1000);
    }
}//end delay

I don't get an error message. By 'it doesn't work' I mean that when I power it up, all the servo does is spin in a circle. Even with standard servo it does nothing. And now when I try to upload it doesn't even upload.