Driving Servo With ATtiny84A, Only Goes From 0° to 45°

I suspect it has something to do with the PWM frequency being different from the Arduino itself, because when I run the same servo program on my Uno, it works fine. But, as the title says, on my ATtiny, it will start at 0 and only go to about 45. It will keep sending a signal, however, and my servo gets hot.

I'm running it at 8mhz, I have my output on one of the chip's PWM pins, and I'm using the SoftwareServo library.

Any help here? Apologies if this is the wrong category. I can send code and pictures if necessary.

Are you using Attinycore?
it supports servo without an additional library.

Posting your code in codetags is always a good idea.

I don't have ATtiny84. I have executed the following sketch using DigisprakATtiny85 Board (Fig-1, 2), and the SG-90 Servo Motor turns from 00 to 1800 (Fig-3).

#include <Servo_ATTinyCore.h>

Servo myservo;  // create servo object to control a servo
// twelve servo objects can be created on most boards

int pos = 0;    // variable to store the servo position

void setup() 
{
  myservo.attach(1);  // PB1
}

void loop()
{
  for (pos = 0; pos <= 180; pos += 1)
  {
    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 >= 0; pos -= 1)
  {
    myservo.write(pos);              // tell servo to go to position in variable 'pos'
    delay(15);                       // waits 15ms for the servo to reach the position
  }
}

DigisparkAttiny85Board
Figure-1:

image
Figure-2:

image
Figure-3:

Yes, I've tried it with SoftwareServo and the default library that comes installed with the IDE, they both produce the same result. But yes, I'm using ATTinyCore.

Here's the code:

#include <Servo.h>
Servo myservo;

void setup() {
  myservo.attach(A6); 
  }

void loop() {
    for (int i = 0; i < 180; i++) {
        myservo.write(i);      
        delay(15);     
        }                 
  }

I can post a picture of my circuit if necessary.

There is a chance that your IDE includes another servo library than the one that comes with Attinycore.
better use this include:

#include <Servo_ATTinyCore.h>
Servo myservo;

void setup() {
  myservo.attach(A6); 
  }

void loop() {
    for (int i = 0; i < 180; i++) {
        myservo.write(i);      
        delay(15);     
        }                 
  }

Just tested with a Attiny84a and I get:

  • 552 us servopulse for 0 degrees
  • 1481 us servopulse for 90 degrees (mid point)
  • 2409 us servopulse for 180 degrees

All at 50Hz, so it is not your code that is misbehaving.

I am using IDE 1.8.19 portable with Attinycore 1.5.2

edit: and you don't forget to do "burn bootloader" to set the fuses right, before you upload your sketch?

1 Like

that solved it. Thanks man

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.