Go Down

Topic: Servo library on STM32F103 partly working (Read 146 times) previous topic - next topic

YO_BE

Hi,

Im using Blue Pill on Arduino IDE
I have no clue why the servo library is only working on some ports.

As long as I use PA6, 7, 8, 9, 10 the software works.
Once I define PB12, 13, 14, 15 OR PA11, 12, 15, It fails.
Or is the library limited to certain pins to be used for servo?

This is the code as example for PA15 => Not working.

#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(PA15);  // 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
  }
}

zoomkat

To put your code in a code box, use the </> icon in the far left of the post tool bar and paste your code between the two bracket sets that appear.

To go back and put your code in a code box, in the bottom right of your post, select "more" and click modify. When the modify post opens, high light your code and click the </> in the far left of the post tool bar. This will put you code in code brackets. Then save the changes.
Google forum search: Use Google Search box in upper right side of this page.
Why I like my 2005 Rio Yellow Honda S2000  https://www.youtube.com/watch?v=pWjMvrkUqX0

johnwasser

 I find it interesting that the pins you say work are PWM pins and the ones that don't are not PWM pins.  It doesn't matter on an Arduino UNO (Servo pins don't have to be PWM) but perhaps that is not true of the Blue Pill core.
Send Bitcoin tips to: 1G2qoGwMRXx8az71DVP1E81jShxtbSh5Hp
See who has no social life: https://forum.arduino.cc/index.php?action=stats :)

Go Up