0

Trinket Mini 5v + Servo = Twitching??
Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.

Trinket Mini 5v + Servo = Twitching??

by TryggrMann on Wed Feb 13, 2019 10:49 pm

Got everything wired up exactly as i'm supposed to, per the tutorial: https://learn.adafruit.com/trinket-gemm ... rol/wiring
and installed the soft servo library. I have successfully done all sorts of coding with LED's, but no luck with the servos yet.

but once I launch it up, my servo acts like it's possessed lol = it will twitch all over and automatically shoots over to 90 or 190-ish degrees and vibrates/buzzes itself until it gets warm. Thoughts? I just need some help troubleshooting, and not sure even what to ask at this point. I'm so frustrated i've been at this for three days now... feeling dumb.

I am using the trinket mini 5v, an SG-90 servo, and a 1K pot, powering the whole set up on a 5v wall power with 700mA

TryggrMann
 
Posts: 16
Joined: Wed Mar 14, 2018 3:08 pm

Re: Trinket Mini 5v + Servo = Twitching??

by franklin97355 on Wed Feb 13, 2019 10:53 pm

How are you providing power to the servo?

franklin97355
 
Posts: 20135
Joined: Mon Apr 21, 2008 2:33 pm
Location: Lacomb, OR.

Re: Trinket Mini 5v + Servo = Twitching??

by TryggrMann on Wed Feb 13, 2019 11:48 pm

power straight to the breadboard power/ground, just like the tutorial image and instructions. data pin going to pin#2 on trinket mini. Soooooo confused on why it's not working. I'm sure it's going to end up being something ridiculously obvious... but it's driving me nuts right now! I'll get a picture up later tonight after I take care of kiddos.

TryggrMann
 
Posts: 16
Joined: Wed Mar 14, 2018 3:08 pm

Re: Trinket Mini 5v + Servo = Twitching??

by XRAD on Thu Feb 14, 2019 7:53 am

Vibrating and buzzing and heating is are signs of poor servo signal, abnormal signal interpretation, or maximum limit. Have you tried the simple SERVO sweep example in the arduino IDE example section? without the pot... I have not tried it with servo soft (vs Servo.h), but it might be another test option...

Also, I have found that some servos react differently, twitching or reverse action...while others are smooth without issues

Another option is to move up to Trinket M0 with easy servo control on several pins...(0,2 best)

Code: Select all | TOGGLE FULL SIZE
/* Sweep
 by BARRAGAN <http://barraganstudio.com>
 This example code is in the public domain.

 modified 8 Nov 2013
 by Scott Fitzgerald
 http://www.arduino.cc/en/Tutorial/Sweep
*/

#include <Servo.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(9);  // attaches the servo on pin 9 to the servo object
}

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'
    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
  }
}

XRAD
 
Posts: 227
Joined: Sat Nov 19, 2016 3:28 pm

Re: Trinket Mini 5v + Servo = Twitching??

by TryggrMann on Fri Mar 01, 2019 12:16 am

XRAD - thanks for the tips! Tried your code example and I can get it to move about 90* now... Regardless of the range of numbers, it starts at about 90* and goes out to about 180* and will not accept anything less hahaha - losing my mind! Negative or larger values make it twitch from one end to the other (end = 90* or 180*, never 0*). Seems to function as expected, except 0=90 and 90=180 regardless of what it's human overlord dictates.

Feeling very much like the dominant species right now. :bashheadintodesk: hahahaha - i'll keep playing with it, but if you have any other tips, PLEASE let me know??

Thank you!!

TryggrMann
 
Posts: 16
Joined: Wed Mar 14, 2018 3:08 pm

Re: Trinket Mini 5v + Servo = Twitching??

by XRAD on Fri Mar 01, 2019 12:56 am

OK, so you get some movement . GOOOD! step one down. Those SG90 servos can have a bad internal pot or corroded electronics.. Try a different one. I usually buy the 8 pack from china for like 12$ on ebay. I have another servo code running a blue plastic sg90 servo back and forth all day today no issue on USB power (no load on servo shaft).

next, make sure ALL grounds are tied together. make sure your wires and connectors are intact and passing current. make sure you have correct servo pin (I used '3' in this example).

I added a few lines, read through carefully. try this check for true 90 degree center. This code forces the servo to 'center' and then swings a max of 90 degrees off center in each direction. The max you want to run these servos is 0-180. To be safe, I usually run them 20-160 degrees.

EDIT: and don't forget that servo code and especially neopix code do not play well together (at same time) ..another reason for twitching. So you have to logically do one thing to completeness, then the other (light or motion, if you use them). you can intertwine the action with non blocking code to a certain degree....


Code: Select all | TOGGLE FULL SIZE
#include <Servo.h>
#define FIRSTPOS 90// initial servo position
#define SERVOPIN 3// PWM 0 2 3 4 on Trinket M0


Servo myservo;  // create servo object to control a servo
 
int pos = 0;    // variable to store the servo position
 
void setup()
{
  myservo.attach(SERVOPIN);  // a PWM output pin to servo
  myservo.write(FIRSTPOS);  // servo move to position
  delay (3000); //3 sec delay to check position
}
 
void loop()
{
  for(pos = 20; pos <= 160; 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 = 160; pos>=20; 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
  }
}

XRAD
 
Posts: 227
Joined: Sat Nov 19, 2016 3:28 pm

Please be positive and constructive with your questions and comments.