Raw code for servo motor on CNC shield V3.

Greetings fellow forum members,

I am new to this forum so please forgive me and tell me whenever I do not comply to the customs that are at work here.

I am working on a project with the Arduino Uno and I have a hard time finding information on how to get a hobby servo motor (SM-S2309S) working with the CNC shield.
I know a much that the shield is not designed for servo motors, but I see many plotter projects that have one, two or three stepper motors AND a servo working alongside of each other.
My project contains two stepper motors(which i have gotten working) and a servo. The stepper motors realize the movements in the X and Z direction while the servo needs to open and close a gripper.
I want to realize these actions with the use of the CNC shield, but I do not want to use any form of GRBL. I want to understand and be able to write the raw code for this project, so I can easily adapt and correct it when necessary.
My question to you is how I can control this servo motor through the CNC shield. I understand how it works on the UNO directly but I cannot figure out which pins to use for output to servo.

I hope I have formulated my question clearly and you are able to provide some information for me.

With kind regards,

MrGls

ps: I am running an external power supply of 12v (8xAA).

I don't really understand why you want to drive servos through a shield not intended for use with servos. But you certainly should say exactly which of the many possible "CNC Shields" you are using. A link to it would be good.

Steve

For this CNC shield.

cnc shield.jpg

You can use any of the pins that are unused in your setup to control a servo. Here is an example using the coolant enable pin (A3) for a servo. It is the Servo sweep example, modified. Note that a servo will probably need an external power supply as the Uno 5V or USB power may not be sufficient.

#include <Servo.h>

Servo servo;

const byte servoPin = A3; // coolant enable
byte pos = 0;

void setup()
{
   Serial.begin(115200);
   servo.attach(servoPin);
}

void loop()
{
  for (pos = 0; pos <= 180; pos += 1) { // goes from 0 degrees to 180 degrees
    // in steps of 1 degree
    servo.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
    servo.write(pos);              // tell servo to go to position in variable 'pos'
    delay(15);                       // waits 15ms for the servo to reach the position
  }
}

Here are how the CNC shield pins are assigned to an Uno.

cnc shield Uno pins.jpg

Thank you so much groundFungus. I got my servo working.
As I explained, the one thing I was missing was to identify the output pin. In this case you say the cooler enable is connected to A3. If I understand you correctly then I can also, for example, connect the servo to the limit Z-Axis by code: "servo.attach(11)". Is that correct? I also wondered where pin A4 and A5 are connected to. Which pins are these on the CNC shield?

To Steve:
I defined the shield in the topic title. I forgot to specify it in my post. The reason I want to put the servo on my CNC shield is that I will most likely have 3 or four stepper motors running when my project continues and I was looking for a shield that could provide me this. Then I found this CNC v3 shield that let me do that. Later I realized that I needed space for a servo too. Since the CNC goes straight onto my UNO I had difficulties finding a way to use the CNC shield and add the servo all together.

With kind regards,

MrGls

also wondered where pin A4 and A5 are connected to.

Above the header for connecting limit swices is a seperate 8 pin (4x2) header. The SDA (A4) and SCL (A5) are boken out on that header.

then I can also, for example, connect the servo to the limit Z-Axis by code: "servo.attach(11)". Is that correct?

Yes.