Shop OBEX P1 Docs P2 Docs Learn Events
servo only moving to first position — Parallax Forums

servo only moving to first position

jsully83jsully83 Posts: 5
edited 2015-04-08 13:16 in Propeller 1
I'm trying to port the Ping)))Dar to the propeller 1 board with no success. I've hooked up a standard servo to port 16 on the Propeller Activity Board and tried running the provided code to move a servo to three different positions. It only moves to the first position and stops. Does anyone have any ideas as to why this would happen?

Thanks

Comments

  • PublisonPublison Posts: 12,366
    edited 2015-04-07 14:34
    Could you please post the code that did not work?

    attachment.php?attachmentid=78421&d=1297987572
  • jsully83jsully83 Posts: 5
    edited 2015-04-07 14:42
    This is in the examples folder in the SimpleIDE install
    /*
      Standard Servo Position.c
      
      Moves servo to 0, 90 and 180 degrees.  Holds each position for 2 s.
      Connect servo to P16 port on Propeller Activity Board.
      
      http://learn.parallax.com/propeller-c-simple-devices/standard-servo
    */
    
    #include "simpletools.h"                      // Include simpletools header
    #include "servo.h"                            // Include servo header
    
    int main()                                    // main function
    {
      servo_angle(12, 0);                         // P16 servo to 0 degrees
      pause(3000);                                // ...for 3 seconds
      servo_angle(12, 900);                       // P16 servo to 90 degrees
      pause(3000);                                // ...for 3 seconds
      servo_angle(12, 1800);                      // P16 servo to 180 degrees
      pause(3000);                                // ...for 3 seconds
      servo_stop();                               // Stop servo process
    }
    

    /code
  • Courtney JacobsCourtney Jacobs Posts: 903
    edited 2015-04-07 14:51
    Immediately I notice you have the servo set to use P12 in your example there, not P16.
    servo_angle(12, 0);                         // P16 servo to 0 degrees
    
    should be
    servo_angle(16, 0);                         // P16 servo to 0 degrees
    
    etc.

    The most current SimpleIDE Learn folder shows the example starts with pin 16; did you modify the code commands? If not, I first suggest downloading/installing the newest Learn folder and trying again. Changing the the code to P16 or moving the servo connection to P12 should work too.
  • jsully83jsully83 Posts: 5
    edited 2015-04-07 17:56
    You're right. That would be the problem. I've tried multiple ports which is why the code says 12. Let me give a more full explanation of what's happening.

    I'm using the Propeller Activity Bot with the P8X32A processor on the board. I'm trying to port the PingDar code written for the basicstamp to C with SimpleIDE.

    I can get the servo to move to a specific position and stop. For example, in the starter code provided in the SimpleIDE install which I've posted here the servo will spin to the first position (0 degrees), but it will not move to the second position (90 degrees) or the third position (180 degrees). I've tried using different servos (all standard servos). I've tried different ports (0, 1, 12, 16). I've tried using different 2 types of code in SimpleIDE and in PropellerIDE. Nothing is working, and I've no clue why.

    The code in SimpleIDE I'm using is the above code (always in the correct port) and this code using the servo.h library -
    #include "simpletools.h"                    
    #include "servo.h"                            
    
    
    
    int main()                   
    {
      while(1)
      {
        for(int i = 0; i >= 1800; i++)
        {
         servo_angle(0,i);
         pause(5); 
        }      
      }         
    }  
    

    and this code using the information for the standard servo documentation about PWM:
    #include "simpletools.h"                    
    #include "servo.h"                            
    
    
    
    int main()                   
    {
      while(1)
      {
        for(int i = 0; i >= 1000; i++)
        {
         high(0);
         pause(3);
         low(0);
         pause(20);
        } 
        
        pause(500);
        
        
        for(int i = 0; i >= 1000; i++)
        {
         high(0);
         pause(15);
         low(0);
         pause(20);
        }  
        
        pause(500);    
      }         
    }  
    
    

    and also this starter code in PropellerIDE -
    OBJ
    
      system : "Propeller Board of Education"               ' PropBOE configuration tools
      servo  : "PropBOE Servos"                        ' Servo control object
      time   : "Timing"                                     ' Timing convenience methods
    
    PUB Go                                                 ' Program starts here
    
      system.Clock(80_000_000)                             ' Propeller system clock -> 80 MHz
    
      servo.Set(16, -450)                                  ' Set servo to approximately -45� 
      time.Pause(2000)                                     ' ..for 1 second
    
      servo.Set(16, 0)                                     ' Set servo to approximately 0� 
      time.Pause(2000)                                     ' ..for 1 second
    
      servo.Set(16, 450)                                   ' Set servo to approximately 45� 
      time.Pause(2000)                                     ' ..for 1 second
    
      servo.Disable(14)                                    ' Stop servo signal
    
    
    


    I all cases the servo(I've tried 3 separate ones) will either 1) move to the first position and stop or 2) not move at all.

    Any help is appreciated.
  • Hal AlbachHal Albach Posts: 747
    edited 2015-04-07 18:40
    Possibly the voltage to the Activity board is sagging when the servo starts drawing power, resetting the Propeller. The Standard Servo Tutorial states that you should not be using USB power alone for that program. You will need to supply 6 - 9 Volts to the power jack, and be sure to move the power switch to position 2 so that you see two green lights by the switch. Also make sure the jumpers between the servo headers are in the 5V position. It doesn't matter which servo position you plug into as long as that position is reflected in the servo_angle() statement.
  • jsully83jsully83 Posts: 5
    edited 2015-04-07 18:48
    Hal - Thanks for your reply. This has crossed my mind. I have double checked that the jumper is set to 5V when I use pin 16 and I always use position 2 on the power switch. Also, we are using the wall adapter from the kit so we are getting good power all the time (after 10 AA batteries I switched to power from an extension cord completely).

    For the life of me I can't seem to figure out why this is happening.
  • RaymanRayman Posts: 14,652
    edited 2015-04-08 02:30
    This sounds like a power surge causing Propeller to reset issue to me... Servos draw a lot of power, especially on the first move.

    If you could power your servos from a separate source, say 4 AA batteries, I bet your trouble would go away.

    Also, to verify that is what is happening, you can use the serial port to send messages to a computer running "Parallax Serial Terminal" at points in your code.
    When the messages stop, that is probably when the Prop got reset. If program is in EEPROM, you'll see it start over...
  • jsully83jsully83 Posts: 5
    edited 2015-04-08 06:33
    Rayman -

    You were RIGHT! Thank you so much! I don't have a separate battery pack, but I did try loading to EEPROM and putting in a simple print command. The board is resetting after every first move. After doing this I went through the standard servo documentation more carefully, like I should have in the first place, and noticed that there is a sentence on how the standard servo may work unexpectedly if using unregulated wall-mount power. It works like it should when I only use the 5 AA battery pack mounted under the chassis.

    Thanks for your help!!
Sign In or Register to comment.