Cannot get servo to work on RedBoard Artemis

Hi,

I have two brand new RedBoard Artemis. I am trying to control a servo using the Servo.h library.

I have two servos: SG90 (http://www.ee.ic.ac.uk/pcheung/teaching … asheet.pdf) and MG966R (https://www.electronicoscaldas.com/data … er-Pro.pdf). I have tested both servos using a servo tester (https://www.amazon.com/gp/product/B06WV … UTF8&psc=1) and I can confirm both are working.

I have made the following connections:

RedBoard +5V → Servo red cable

RebBoard GND → Servo brown cable

RedBoard 8 → Servo yellow cable

I know it is now recommended to power the servo directly from the board, but for testing purposes, that should be OK.

In the Arduino IDE, I have compiled and uploaded the example code from SparkFun (Example1_BasicServo). Compilation and upload are going without issue.

/*
  Author: Nathan Seidle
  SparkFun Electronics
  Created: August 18th, 2019

  Purchasing from SparkFun helps write code like this and helps us
  release products open source so that we can help each other learn: https://www.sparkfun.com/artemis

  This example demonstrates the control of a servo on pin 8 on the RedBoard Artemis. Any PWM
  pin can control a servo.

  Hardware Connections:
  Load this code
  Connect a Servo to pin 18:
    Red Wire -> 3.3V or 5V
    Black Wire -> GND
    Signal (Yellow or White) -> 8

  The servo will rotate back and forth. 
*/

/* 
// This file is subject to the terms and conditions defined in
// file 'LICENSE.md', which is part of this source code package.
*/

#include <Servo.h>

Servo myServo;

int pos = 0;

void setup()
{
  Serial.begin(9600);
  Serial.println("SparkFun Servo Example");

  myServo.attach(8);
}

void loop()
{
  //Sweep
  for (pos = 0; pos <= 180; pos++) { // goes from 0 degrees to 180 degrees
    myServo.write(pos);              // tell servo to go to position in variable 'pos'
    delay(5);                       // waits 15ms for the servo to reach the position
  }
  for (pos = 180; pos >= 0; pos--) { // goes from 180 degrees to 0 degrees
    myServo.write(pos);              // tell servo to go to position in variable 'pos'
    delay(5);                       // waits 15ms for the servo to reach the position
  }
}

The servo does not budge.

I have tried different pins for the PWM (2,3,4,5,6,7,8,9,10), still no result. I have tried both boards, same (non) result.

I can blink the LED and use the Fade example code, so the board seem to be working.

What am I doing wrong?

On an Artemis board, the following are valid options for myServo.attach():

D0 , D1 , D2 (=A6) , D3 , D4 , D5 , D6 , D7 , D8 (=A8) , D9 (=A9) , D10 (=A10), D11 , D12 , D13 , D15 , D16 (=A0) , D17 (=A1) , D21 ,D31 (= A31), D19 (=A3)

Make sure to use select with ‘D’ in front e.g. myServo.attach(D2) and NOT myServo.attach(2).

paulvha:
Make sure to use select with ‘D’ in front e.g. myServo.attach(D2) and NOT myServo.attach(2).

Thank you Paul, that works. I knew I was making a very simple mistake.

I do have a question though. Where should I have looked to find this information? The example sketch provided by SparkFun with the Artemis uses myServo.attach(8). And I had looked at the pinout sheet (https://cdn.sparkfun.com/assets/learn_t … rtemis.pdf), and the name of the pins are shown as “8” and not “D8”.

These examples are confusing indeed. If you use ‘8’ the library will assume the processor pad, but if you use ‘D8’ the library will take that as the pin number at the side of the board. The library will translate that pin number to the connected processor pad.

Where should I have looked to find this information?

A good start for ANY problem is always to do a search on the forum first.

Many issues have been answered before. In this case, you would have found https://forum.sparkfun.com/viewtopic.ph … ilit=servo.

Another good area to check is ‘https://github.com/sparkfun/Arduino_Apollo3/issues’ here you find a topic ’ https://github.com/sparkfun/Arduino_Apollo3/issues/462’ which includes a spreadsheet with the different pinnumber for each board.

Happy it works for you now.