Forum Rule: Always post complete source code & details to reproduce any issue!
Results 1 to 2 of 2

Thread: [Teensy 3.2] Help! Can't get basic Teensyduino servo example working?

  1. #1
    Junior Member
    Join Date
    Dec 2017
    Posts
    2

    [Teensy 3.2] Help! Can't get basic Teensyduino servo example working?

    Using Teensy 3.2, and the pinout card (this one), I copy/pasted the Servo.h example from here, plugged in a servo (powered by a separate 5V supply) on pin 20, and uploaded and ran the code.

    Literally nothing happens.

    The Serial output is showing that the loop is executing ( I see the values being printed out), but other than that, nothing is happening. I've quadruple checked that I have the servo plugged into the correct pin. What am I doing wrong?

    I've read somewhere that Teensyduino comes with it's own Servo library. How do I know whether I'm importing the correct one?

    Code:
    Code:
    // Sweep
    // by BARRAGAN <http://barraganstudio.com> 
    // from https://www.pjrc.com/teensy/td_libs_Servo.html
    
    #include <Servo.h> 
     
    Servo myservo;  // create servo object to control a servo 
                    // a maximum of eight servo objects can be created 
     
    int pos = 0;    // variable to store the servo position 
     
    void setup() 
    { 
      //Turn on the LED (basic power indicator)
      pinMode(13,OUTPUT);
      digitalWrite(13,HIGH);
      // Initialize the serial port
      Serial.begin(115200);
    
      myservo.attach(20);  // attaches the servo on pin 20 
    } 
     
     
    void loop() 
    {
      for(pos = 10; pos < 170; pos += 1)  // goes from 10 degrees to 170 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 
        Serial.println(pos);
      } 
      for(pos = 10; pos>=170; 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 
        Serial.println(pos);
      } 
    }
    Last edited by roach374; 12-28-2017 at 03:45 PM.

  2. #2
    Senior Member+ KurtE's Avatar
    Join Date
    Jan 2014
    Posts
    3,432
    Might help to see the wiring. For example how is the ground hooked up? Do you have ground hooked up to servo and your +5v power supply and do you have ground hooked up from servo to Teensy?

    Also which servo? I assume it is an RC servo?

    If you have multiple servo libraries on your system. You can normally find out which one is used as the system will tell you as part of the compile that it used X library and not Y...

    Also might help to know things like which version of Arduino, what version of Teensyduino, etc.

    Kurt

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •