Digistump Forums
The Digispark => Digispark (Original) Support => Topic started by: AntoAnto 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:
#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
-
increase the maximum servo pulse
-
Did that already. The only consequence is that the servo moves faster but not more in angle... :(
-
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
-
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
-
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....