Author Topic: TowerPro micro servo sg90  (Read 13980 times)

Tom

  • Newbie
  • *
  • Posts: 4
TowerPro micro servo sg90
« on: February 01, 2013, 06:01:47 pm »
Did anyone try to control this servo with the Digispark?All I get is a weird jitter instead of doing to sweep between 0 to 180. 
I've tried:
Code: [Select]
#include <SoftwareServo.h>SoftwareServo servo;void setup(){    servo.attach(0);}void loop(){  servo.write(180);                  // sets the servo position according to the scaled value delay_refresh(1000);  servo.write(0);                  // sets the servo position according to the scaled value delay_refresh(1000);}void delay_refresh(int delaytime){   for(int x=0;x<delaytime;x=x+25){      delay(25);      SoftwareServo::refresh();      }}AND:
Code: [Select]
#include <SoftwareServo.h>SoftwareServo servo;void setup(){    servo.attach(0);}void loop(){  servo.write(180);                  // sets the servo position according to the scaled value   delay(15);   SoftwareServo::refresh();delay(1000);  servo.write(0);                  // sets the servo position according to the scaled value   delay(15);   SoftwareServo::refresh();delay(1000);}

Eje_G

  • Newbie
  • *
  • Posts: 13
Re: TowerPro micro servo sg90
« Reply #1 on: February 03, 2013, 03:43:03 pm »
I'm at a similar position.

No matter what I do it's jitters and only want to go clockwise and continue trying to go clockwise once it reached the end.

I tried to change setMinimumPulse and setMaximumPulse values but not matter what the values nothing seem to change anything. Just rapid movement all the way clockwise until the program loop terminates the changing of the servo. Tried on 3 different boards all powered from a computer USB and AC connected USB charger as well numerous different ports. No difference.

I wrote a simple loop that sent a single 1ms pulse to the servo waited 20ms sent another single 1ms pulse, than waited 1sec and wrote a 2ms pulse 3 times (with a 20ms delay).
This caused the servo to first turn a bit clockwise, than turn a bit more anticlockwise, so after running for a numerous seconds the servo finally reached all over to the most anticlockwise location.

Rude and crude. But to me at least seems to prove that the servo is functional at the very least and long/short enough pulse will turn it in the right direction.

Anyone had any working success with servos? Would be nice to be able to do a nice sweep and a bit more nicer control of the servo moment that this crude hack I did.

digistump

  • Administrator
  • Hero Member
  • *****
  • Posts: 1465
Re: TowerPro micro servo sg90
« Reply #2 on: February 04, 2013, 02:02:07 am »
Which Digispark version do you have? http://digistump.com/wiki/digispark/tutorials/modelbi2c


If you have model B try using Pin 1 instead of Pin 0


In fact try Pin 1 either way and see if it works.


Eje_G

  • Newbie
  • *
  • Posts: 13
Re: TowerPro micro servo sg90
« Reply #3 on: February 04, 2013, 03:47:02 pm »
I tried both p0, p1 and p2. Same results. Rapid movement all the way clockwise than sitting there jittering.

Played with different values of setMinimumPulse and setMaximumPulse but no matter what values I use it either just moves all the way clockwise and jitters there or it locks in place at curent position and jitters there.

The following code makes a flowing movement starting out all the way counterclock wise and moves all the way clockwise, stops and moves back to 0 again.
So I'm fairly certain the servo is fine and not broken since it now move correctly with this hack.

I even went so far doing a excel spread sheet to figure out the max and min values for SoftwareServo based on the pulse0 formula and clockcycles per microsecond for 16MHz (might done my math wrong) and tried out the values it gave me even doubled, quadrupled and halved as well quarted those values for setMax/MinimumPulse to no avail.

Unfortunately do not have a voltage probe tester for the scope at work so can't check what signal is being output from the SoftwaresServo. I put a Hz meter to it and looks like I'm getting a 36Hz signal (think it was) or a pulse every 20ms as I should.


Quote
void setup()
{
 pinMode(1,OUTPUT);
 pinMode(2,OUTPUT);
 digitalWrite(1,LOW);
 digitalWrite(2,LOW);
 
   for(int startpos = 0; startpos < 100; startpos +=1)
   {
   digitalWrite(2,HIGH);
   delayMicroseconds(1400);
   digitalWrite(2,LOW);
   delayMicroseconds(1400);
   delay(20);   
   }
   
}

void loop()
{
  // blink LED 3 times before start
  for(int blinks = 0; blinks < 3; blinks +=1)
  {
   digitalWrite(1,HIGH);
   delay(1000);
   digitalWrite(1,LOW);
  }
   
  // sweep 1 counter clockwise
   for(int pos = 400; pos < 2300; pos +=10)
   {
   digitalWrite(2,HIGH);
   delayMicroseconds(pos);
   digitalWrite(2,LOW);
   delayMicroseconds(pos);
   delay(20);
   }

  // blink LED 6 times to tell us done with sweep 1 and start of sweep 2
  for(int blinks = 0; blinks < 5; blinks +=1)
  {
   digitalWrite(1,HIGH);
   delay(400);
   digitalWrite(1,LOW);
  }

  // sweep 1 clock wise
   for(int pos = 2300; pos > 400; pos -=10)
   {
   digitalWrite(2,HIGH);
   delayMicroseconds(pos);
   digitalWrite(2,LOW);
   delayMicroseconds(pos);
   delay(20);
   }
   
}


cwhummel

  • Newbie
  • *
  • Posts: 11
Re: TowerPro micro servo sg90
« Reply #4 on: February 04, 2013, 04:47:44 pm »
I am having this exact same problem. I have a Hitec HS-311 servo and am having the same jitter issue.

digistump

  • Administrator
  • Hero Member
  • *****
  • Posts: 1465
Re: TowerPro micro servo sg90
« Reply #5 on: February 05, 2013, 12:25:32 am »
I've sent an email to runberde - the guy who had the code working on his servo to see what kind of servo he has - hopefully that will help with the mystery.


I'll try with some servos as well, once I find them in my closet.

Eje_G

  • Newbie
  • *
  • Posts: 13
Re: TowerPro micro servo sg90
« Reply #6 on: February 05, 2013, 11:35:50 am »
Curious would one be able to utilize DigiScope to try to get some readings on the servo issue?

digistump

  • Administrator
  • Hero Member
  • *****
  • Posts: 1465
Re: TowerPro micro servo sg90
« Reply #7 on: February 05, 2013, 01:44:05 pm »
You could try it with the DigiScope - it is very much a proof on concept and I can't attest to how well it can actually be used yet. I was able to see I2C signals with it, so there is a good chance it could be useful for this.


I contacted runberde[/size] he is using this servo [/size]https://www.sparkfun.com/products/9065 with the softwareservo code with success

Eje_G

  • Newbie
  • *
  • Posts: 13
Re: TowerPro micro servo sg90
« Reply #8 on: February 05, 2013, 02:23:15 pm »
I got it to see stuff but the precompiled version of DigiScope didn't have any timing value or zoom function. Think also the delay time in Digiscope is to long because didn't see signal as frequently as I expected it seemed there where "missed" reads (which isn't that important if I can just figure out the length of a single pulse, but they just looked more like spikes due to resolution issues).

Going to try to get the .py version running..

That servo is interesting if it's the same as the HS-55 then the values are "600usec to 2400usec" with center of 1500us. The servo I have IIRC is 1200us to 1800us. But would think it would go counter clockwise even if rapidly to the limits. I took my Heli apart and pulled one of the servos out of it with same bad result as previous. Even looked at one of my RC cars but the servo in it has a bunch of wires going into it so didn't feel like trying to figure out that servo.

cwhummel

  • Newbie
  • *
  • Posts: 11
Re: TowerPro micro servo sg90
« Reply #9 on: February 09, 2013, 07:22:25 am »
Any update on this?


Thanks

bjh

  • Newbie
  • *
  • Posts: 31
Re: TowerPro micro servo sg90
« Reply #10 on: February 16, 2013, 11:25:04 am »
I'm having the same problems with SoftwareServo just producing jittery seizures in both the sg90 and Futaba S3003, though Eje_G's bit-bang code does work. 


I couldn't get Digiscope running, but I suddenly remembered watching my dad debug a circuit using a small speaker!


I modified the example from this thread that some had reported success with to, in theory, put the servo at 90ยบ and keep refreshing.  It produces a low buzz and the frequency counter on my meter wanders between about 58-62 Hz


I similarly modified Eje_G's example to just output at the middle of the range, 1350us pulses 20ms apart.  It produces a, to my ear, a slightly clearer and higher-pitched buzz even though the frequency counter shows a steady 49-50Hz.  (Though, I can't be sure they're both trying to send quite the same pulse length, because SoftwareServo doesn't implement writeMicroseconds() method like the standard servo library)


Bluebie

  • Sr. Member
  • ****
  • Posts: 486
Re: TowerPro micro servo sg90
« Reply #11 on: February 16, 2013, 03:27:33 pm »
This is a timing problem. I've seen it before. The pulses arriving to the servo aren't within spec and it's reacting strangely as a result. It's probably related to how delay() doesn't seem to work properly half the time on digispark either, or how millis() mysteriously stops working when digiusb is included.

bjh

  • Newbie
  • *
  • Posts: 31
Re: TowerPro micro servo sg90
« Reply #12 on: February 16, 2013, 05:30:38 pm »
Timing and / or noisy: the bit-banged signal is a crisp buzz, adding random jitter makes the servo twitchy and adds a sort of warble to the sound.  The SoftwareServo signal has audible jitter, and the pulses in the buzz are not crisp, they sound more like "puff puff" or "chuff chuff" and and are lower in tone. 


Guess I'll hack around with the bit-bang code.

bjh

  • Newbie
  • *
  • Posts: 31
Re: TowerPro micro servo sg90
« Reply #13 on: February 17, 2013, 10:57:46 pm »
So, said hacking around with bit-banging has yielded a (very) first cut of my SimpleServo library; more hacking and testing to come, but so far it's working with my TowerPro SG90s, at least...

s.rege

  • Newbie
  • *
  • Posts: 1
Re: TowerPro micro servo sg90
« Reply #14 on: November 27, 2013, 10:34:46 am »
I had the same problem a few days ago. The only difference: i used an arduino UNO

Solution: External power supply to power the servo. PLUS: connect the ground of the external power supply to the ground of UNO board. Works like a dream. :)