Go Down

Topic: Attiny84 + Servo, anyone got a working library? (Read 279 times) previous topic - next topic

Dean_Bean

Apr 18, 2019, 05:24 pm Last Edit: Apr 19, 2019, 07:54 am by Dean_Bean
EDIT: Bootloader improperly burned at 1MHz, changing to 8MHz and re-burning solved this.


Hey all, just recently I got an Attiny84 to miniaturize a project and I'm getting started with having it automatically control a servo motor (9g). Unfortunately, nothing seems to be working.

I've tried this example, this example, this library, this library, and a few others. Nothing seems to work, there is no error in the various code examples I've used so I can't see an issue there.

This is the example I used with the facebook link :
Code: [Select]
#include <PWMServo.h>
PWMServo myservo;

const int led = 0;

void setup() {
  myservo.attach(SERVO_PIN_A);
  pinMode(led, OUTPUT);
}

void loop() {
  digitalWrite(led, HIGH);

 myservo.write(10);
  delay(800);
  digitalWrite(led, LOW);
myservo.write(170);
  delay(500);
}


And this is the code I used with the tinyservo example that came with the library

Code: [Select]
#include <TinyServo.h>
const byte SERVOS = 3;
const byte servoPin[SERVOS] = {7};
#define WATERSERVO 0
void setup() {
  // put your setup code here, to run once:
setupServos();
}

void loop() {
  // put your main code here, to run repeatedly:
delay(1000);
moveServo(WATERSERVO, 180);
delay(1000);
moveServo(WATERSERVO, 10);




}


If anyone has any suggestions on how to learn what to do/fix this issue, if you have your own examples or libraries I haven't tried or your own code using these existing libraries, I would love to hear.

Thank you for your time.

DrAzzy

#1
Apr 18, 2019, 07:00 pm Last Edit: Apr 18, 2019, 07:02 pm by DrAzzy
With my ATTinyCore, the included Servo library should just work (i include versions of Wire and SPI that also work on all the supported parts, transparently handling the differences in underlying hardware). If it doesnt, thats a bug that should be reported to me to be fixed (it should be an easy fix)

https://github.com/SpenceKonde/ATTinyCore
ATTinyCore for x4/x5/x61/x7/x8/x41/1634/828/x313 megaTinyCore for the megaavr ATtinies - Board Manager:
http://drazzy.com/package_drazzy.com_index.json
ATtiny breakouts, mosfets, awesome prototyping board in my store http://tindie.com/stores/DrAzzy

Dean_Bean

With my ATTinyCore, the included Servo library should just work (i include versions of Wire and SPI that also work on all the supported parts, transparently handling the differences in underlying hardware). If it doesnt, thats a bug that should be reported to me to be fixed (it should be an easy fix)

https://github.com/SpenceKonde/ATTinyCore
Wow, didn't realize the library dev would be responding himself! I'm honored haha.

Alright well sad thing is that's the first thing I tried.

This is the example I used.
Code: [Select]
#include <Servo.h>
Servo myservo;

int pos = 0;



void setup() {
  myservo.attach(6);
  // put your setup code here, to run once:

}

void loop() {
  // put your main code here, to run repeatedly:
myservo.write(10);
delay(2000);
myservo.write(170);
delay(2000);

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 >= 0; 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
  }
}



To make troubleshooting easier I can guarantee that the servo is functional, powered by a separate source other than the Arduino which is already powering the attiny via 3.3v.

When I upload the code the servo activates and only holds it's position where it doesn't want to move. I attached it to physical pin 6 (arduino code pin 7). It also has a 100uf capacitor on the same line just in case.

The settings I'm using are:
Board: ATtiny24/44/84
Chip: ATtiny 84
Clock: 8MHz
B.O.D level: disabled (unchanged)
Save EEPROM: EEPROM retained (unchanged)
Pin Mapping: Clockwise
LTO: disabled


I've tested with other pwm pins but still no change.

DrAzzy

Where is the 100uF cap? Hopefully between power rails, not on the signal line - a cap on that would interfere with the signal.

I'm also unsure of whether those servos are expected to work with a 3.3v signal - do you know if this is expected to work?

I'll try it out if it's not figured out by tomorrow night - I'm at my gf's place tonight, and she unfortunately doesn't have the same extensively stocked electronics workbench here.
ATTinyCore for x4/x5/x61/x7/x8/x41/1634/828/x313 megaTinyCore for the megaavr ATtinies - Board Manager:
http://drazzy.com/package_drazzy.com_index.json
ATtiny breakouts, mosfets, awesome prototyping board in my store http://tindie.com/stores/DrAzzy

Dean_Bean

Where is the 100uF cap? Hopefully between power rails, not on the signal line - a cap on that would interfere with the signal.

I'm also unsure of whether those servos are expected to work with a 3.3v signal - do you know if this is expected to work?

I'll try it out if it's not figured out by tomorrow night - I'm at my gf's place tonight, and she unfortunately doesn't have the same extensively stocked electronics workbench here.
Sorry I'm in Europe and by the time you replied I was fast asleep.

Oh the cap is on the rails don't worry, it wouldn't make sense to put it between the signal line but yeah I should have mentioned it my bad.

Right, it is giving off a 3.3 signal I didn't think of that. I know ATtinys can be powered by 5v as well so maybe that could fix it I'll try that out.

Funny I have a similar issue. I'm trying to fix this before I go to my gfs place in a few days and I won't be able to work on this for a week at that point.

Thanks for trying to test it out as well!

Dean_Bean

HEY QUICK UPDATE

I got it to work. Turns out I had incorrectly burned the bootloader when the 1MHz clock speed was selected. I just changed it to 8MHz, burned, uploaded sketch again, and it worked beautifully.

Thank you for the help! Oh and the servo does respond to when the Attiny is powered by 3.3 AND 5v.

DrAzzy

HEY QUICK UPDATE

I got it to work. Turns out I had incorrectly burned the bootloader when the 1MHz clock speed was selected. I just changed it to 8MHz, burned, uploaded sketch again, and it worked beautifully.

Thank you for the help! Oh and the servo does respond to when the Attiny is powered by 3.3 AND 5v.
Well, that would do it! Glad it's working!
ATTinyCore for x4/x5/x61/x7/x8/x41/1634/828/x313 megaTinyCore for the megaavr ATtinies - Board Manager:
http://drazzy.com/package_drazzy.com_index.json
ATtiny breakouts, mosfets, awesome prototyping board in my store http://tindie.com/stores/DrAzzy

Go Up