Servo issues - Weird things happening!!



  • Hi guys,

    I tried to connect a servo to a Uno board and uploaded the standard sketch ServoActuator.
    It really does some weird things. It's almost like it runs too long to one side. And if I try to e.g. push "open" twice it runs in the other direction instead of to the same side again.
    I have tried to modify the max & min values but it still does the weird things.
    The communication to the gateway is fine and the values from the Vera are received with the correct values.

    It's connected to a 5V adapter and grounded to the Arduino.

    I have uploaded a video to show what's happening:

    http://youtu.be/awpe0I8m-R8

    I have tried to connect the servo motor without the Mysensors sketch and used the Sweep sketch. To make it respond correctly I had to modify the delay value to around 5 in the line:
    delay(15); // waits for the servo to get there
    Otherwise it did something similar.

    Any suggestions?? Hope you can help!



  • @Mouridsen Try this sketch I use to test servolimits. Just enter the position (percentage) you want in serial monitor. This will probably tell you if there's something wrong with your servo or if there's a problem with the sketch. I can't test the mysensors example with my TowerPro because my radios still haven't arrived.

    link text

    If this works as expected there's something in the example sketch that doesn't agree with your servo. But try this first.



  • @slarti Sorry for my late answer! I did try your sketch but it's still the same. I really don't know what the issue can be. I have considered to try buying the motor that's on the mysensors page instead. I don't know what the difference is between the two. Any ideas what I could try with the current motors???



  • Sorry, no idea. I think your servo is faulty somehow.

    Here's my current sketch I use with my fake futaba 3003's which works fine with them. I got some TowerPro MG996R's but they don't move the whole 180 degrees for some reason. Went with the futabas and modified the TowerPros to continuous rotation.

    https://codebender.cc/sketch:79845



  • Just to let you know that I solved the issue.
    I found a library where you can control the speed and make sure it get to it's position.
    You can find it here: https://github.com/netlabtoolkit/VarSpeedServo
    I incorporated it in the Mysensor sketch and it works eventhoug it looks like it only goes like 90 degrees but it's enough for me :

    
    #include <MySensor.h>
    #include <SPI.h>
    #include <VarSpeedServo.h> 
    // #include <Servo.h> 
    
    #define SERVO_DIGITAL_OUT_PIN 3
    #define SERVO_MIN 0 // Fine tune your servos min. 0-180
    #define SERVO_MAX 180  // Fine tune your servos max. 0-180
    #define DETACH_DELAY 900 // Tune this to let your movement finish before detaching the servo
    #define CHILD_ID 10   // Id of the sensor child
    
    MySensor gw;
    MyMessage msg(CHILD_ID, V_DIMMER);
    VarSpeedServo myservo;  // create servo object to control a servo 
                            // a maximum of eight servo objects can be created 
    // Servo myservo;  // create servo object to control a servo 
                    // a maximum of eight servo objects can be created Sensor gw(9,10);
    unsigned long timeOfLastChange = 0;
    bool attachedServo = false;
                
    void setup() 
    { 
      // Attach method for incoming messages
      gw.begin(incomingMessage);
    
      // Send the sketch version information to the gateway and Controller
      gw.sendSketchInfo("Servo", "1.0");
    
      // Register all sensors to gw (they will be created as child devices)
      gw.present(CHILD_ID, S_COVER);
    
      // Request last servo state at startup
      gw.request(CHILD_ID, V_DIMMER);
    } 
    
    void loop() 
    { 
      gw.process();
      if (attachedServo && millis() - timeOfLastChange > DETACH_DELAY) {
         myservo.detach();
         attachedServo = false;
      }
    } 
    
    void incomingMessage(const MyMessage &message) {
      myservo.attach(SERVO_DIGITAL_OUT_PIN);   
      attachedServo = true;
      if (message.type==V_DIMMER) { // This could be M_ACK_VARIABLE or M_SET_VARIABLE
         int val = message.getInt();
         myservo.write(SERVO_MAX + (SERVO_MIN-SERVO_MAX)/100 * val,255,true); // sets the servo position 0-180
         // Write some debug info
         Serial.print("Servo changed. new state: ");
         Serial.println(val);
       } else if (message.type==V_UP) {
         Serial.println("Servo UP command");
         myservo.write(SERVO_MIN,255,true);
         gw.send(msg.set(100));
       } else if (message.type==V_DOWN) {
         Serial.println("Servo DOWN command");
         myservo.write(SERVO_MAX,255,true); 
         gw.send(msg.set(0));
       } else if (message.type==V_STOP) {
         Serial.println("Servo STOP command");
         myservo.detach();
         attachedServo = false;
    
       }
       timeOfLastChange = millis();
    }
    

Log in to reply
 

Suggested Topics

0
Online

11.2k
Users

11.1k
Topics

112.5k
Posts