MKR 1010 + MKR Connector Carrier + servo

I'm trying to use an MKR 1010 to control a collection of six servos--for development, I'm using just one servo--plugged into an MKR Connector Carrier. The whole "circuit" is the 1010, the carrier, an MKR SD proto shield with nothing on it other than the SD RAM, and a Seeed Grove servo. The whole thing is powered by an external 12VDC power supply connected through the VIN and GND connectors on the connector carrier.

The test code a slight modification of the "sweep" sketch:

/* 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;
int pos = 0;    // variable to store the servo position

void setup() {
  myservo.attach(9);
  pinMode(LED_BUILTIN, OUTPUT);
}

void loop() {
  for (pos = 0; pos <= 180; pos += 1) {
    digitalWrite(LED_BUILTIN, HIGH);
    Serial.println(pos);
    Serial.println(myservo.attached());
    myservo.write(pos);              // tell servo to go to position in variable 'pos'
    delay(30);                       // waits 15ms for the servo to reach the position
    digitalWrite(LED_BUILTIN, LOW);
  }
  for (pos = 180; pos >= 0; pos -= 1) { // goes from 180 degrees to 0 degrees
    digitalWrite(LED_BUILTIN, HIGH);
    Serial.println(pos);
    myservo.write(pos);              // tell servo to go to position in variable 'pos'
    delay(30);                       // waits 15ms for the servo to reach the position
    digitalWrite(LED_BUILTIN, LOW);
  }
}

The problem, of course, is that the servo isn't even twitching.

Has anyone ever tried this configuration, of servos connected through a connector carrier? Is this supposed to work?

The documentation for the connector carrier isn't explicit--is the D0 connector of the connector carrier connected to 1010 pin 9? (I don't have an oscilloscope so I can't see the waveform.)

The delay() of the original sweep sketch was 15ms, which isn't consistent with a 50Hz frequency for the PWM signal. Is that even relevant? I don't know how the servo myservo.write(pos) call works--does it emit just one pulse of the right duration, or is it continuous? If the latter, at what frequency? Does that matter?

Any help would be appreciated.

Problem solved.

The Servo Sweep demo says, in no uncertain terms:

void setup() {
  myservo.attach(9);  // attaches the servo on pin 9 to the servo object
}

Well, that bit about pin 9 may be right for other boards, but it's not for the MKR 1010. On the MKR 1010, the number apparently corresponds to the pin label, Dx, not it's physical pin, so to get pin D0 to sweep, you have to use a 0, D2 gets a 2, and so on:

void setup() {
  myservo0.attach(0);
  myservo2.attach(2);
}

This may have been a foolish misinterpretation on my part, but the documentation could have been clearer.

And, by the way, board D0 is indeed hooked to Connector Carrier connector D0, and so on.

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.