Author Topic: Servo (SG90) wont turn 180° with Digispark ATTINY85  (Read 486 times)

AntoAnto

  • Newbie
  • *
  • Posts: 5
Servo (SG90) wont turn 180° with Digispark ATTINY85
« on: March 15, 2019, 09:26:18 am »
Hiho everyone,

I´m new in the community and new to the programming of Digisparks in general. 

I´m trying to troubleshoot my issue since a few days already and didn´t find any solution. So I´m asking now the pros over here. :)

Here my issue:
I´m trying to reach a sweep movement from a SG90 servo and to control the sweeping speed with a potentiometer.
Everything works fine, but the servo wont turn 180° (it turns 90° or something around that) :'(
By trying the same on an Arduino UNO, everything is fine....

Below the code:
Code: [Select]
#include <SoftRcPulseOut.h>

SoftRcPulseOut myservo;  // create servo object to control a servo
               

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

int val;        // variable to read the value from the analog pin



void setup()
{
  pinMode(1, OUTPUT); // To Servo
  pinMode(2, INPUT);  // Poti Input
  myservo.attach(1);  // attaches the servo on pin 1 to the servo object
  myservo.setMaximumPulse(9600);
}


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'
    val = map(analogRead(1), 0, 1023, 0, 10);
    Serial.println(val);
    delay(val);                       // waits for the servo to reach the position
    myservo.refresh(20);
  }
  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'
   val = map(analogRead(1), 0, 1023, 0, 10);
   Serial.println(val);
   delay(val);                       // waits for the servo to reach the position
   myservo.refresh(20);
  }
}

Any idea on how to solve this issue?


Thanks in advice,
Anto

jbalat

  • Newbie
  • *
  • Posts: 5
Re: Servo (SG90) wont turn 180° with Digispark ATTINY85
« Reply #1 on: March 16, 2019, 01:34:13 am »
increase the maximum servo pulse

AntoAnto

  • Newbie
  • *
  • Posts: 5
Re: Servo (SG90) wont turn 180° with Digispark ATTINY85
« Reply #2 on: March 16, 2019, 01:38:03 pm »
Did that already. The only consequence is that the servo moves faster but not more in angle... :(

jbalat

  • Newbie
  • *
  • Posts: 5
Re: Servo (SG90) wont turn 180° with Digispark ATTINY85
« Reply #3 on: March 16, 2019, 04:14:11 pm »
Weird I just did that on mine and it worked. I changed it to 18000
Maybe you need to set your minimum as well since the servo might not be centred ?

Anyway I am using the digispark simpleservo library which is a bit easier but I’m having an issue trying to get the servo to hold its angle when I apply a large load, there is no refresh command in simpleservo and if you write the same angle it doesn’t refresh

AntoAnto

  • Newbie
  • *
  • Posts: 5
Re: Servo (SG90) wont turn 180° with Digispark ATTINY85
« Reply #4 on: March 18, 2019, 11:07:10 am »
Nope, it still runs just faster but not at 180 degrees. Also, if I increase the speed, the angle gets smaller...
The servo is centred.
Adding MinPulse brings the servo to run super slow and to ignore the maximum pulse. Even if both are set. I´m really confused I have to say...

By using SimpleServo.h I don´t get nearly as good results as with SoftRcPulsOut.h

AntoAnto

  • Newbie
  • *
  • Posts: 5
Re: Servo (SG90) wont turn 180° with Digispark ATTINY85
« Reply #5 on: March 23, 2019, 02:17:08 pm »
EDIT: solved the problem by increasing the maximum pulse to 35.300.
Steangely enough it only works by putting the value at That number. Anything else brings the servo to move less than 180 degrees again....