CNC Shield with O/A speed control potentiometer?

Hi, back again after a break!
Thanks to a bunch of you, especially Mr WildBill who basically rewrote my code into something that actually worked :slight_smile:

Time to move on, and I’d like to add a pot so the user can adjust the speed without reprogramming the Arduino…

The code below, drives the 1.7A NEMA17 motor approx 900mm fowards and then 900mm reverse in 16 minutes (please ignore the “30 minute” multiplier… needed to double the speed quick at the request of the user and forgot about it! I’ll fix it later, but first, I’d like to know, can I actually connect a pot to the Arduino/CNC shield combo, I’m sure this must be possible, but information seems to be unavailable???

I’m using UNO with 4 axis v3 CNC shield, so I can add more machines later, all controlled from here…

// Stepper Code with Limit Switch for 
// CNC Shield V2.1 on Y axis by WildBill and me
// Shield loaded with full jumpers for full microsteps

const byte EnablePin = 8;
const byte Y_DirectionPin = 6;
const byte Y_StepPin = 3;
const byte Y_LimitPin = 10;

unsigned long Stepdelay = (432 / 4);      //Speed Microseconds 600 = 20mm/min
unsigned long RequiredSteps = (720et99UL * 30); //revolutions(1 minute) * 30 minutes

unsigned long StepCount = 0;
int EndPointDelay = 6660; // Milliseconds

void Step(byte StepPin)
{
  digitalWrite(StepPin, HIGH);
  delayMicroseconds(Stepdelay);
  digitalWrite(StepPin, LOW);
  delayMicroseconds(Stepdelay);
  StepCount++;
}

void setup()
{
  Serial.begin(115200);
  Serial.println("Starting Mervs Mover");
  pinMode(Y_DirectionPin, OUTPUT);
  pinMode(Y_StepPin, OUTPUT);
  pinMode(EnablePin, OUTPUT);
  digitalWrite(EnablePin, LOW);
  pinMode(Y_LimitPin, INPUT_PULLUP);
  HomeStepper(Y_DirectionPin, Y_StepPin, Y_LimitPin);
}

void loop()
{
  if (StepCount < RequiredSteps)
  {
    Step(Y_StepPin);
  }
  else
  {
    delay(EndPointDelay);
    HomeStepper(Y_DirectionPin, Y_StepPin, Y_LimitPin);
  }
}

void HomeStepper(byte DirectionPin, byte StepPin, byte LimitPin)
{
  Serial.println("Home Stepper");
  digitalWrite(DirectionPin, LOW);
  while (digitalRead(LimitPin) == HIGH)
  {
    Step(StepPin);
  }
  StepCount = 0;
  digitalWrite(DirectionPin, HIGH);
  Serial.println("Stepper at home");
  delay(EndPointDelay);
}

AxeGrinder:
I'm using UNO with 4 axis v3 CNC shield, so I can add more machines later, all controlled from here...

Please post a link to the datasheet for the CNC shield so we can see how the Arduino I/O pins are used by the shield.

...R

Robin2:
Please post a link to the datasheet for the CNC shield so we can see how the Arduino I/O pins are used by the shield.

…R

CNC Shield Info here: Arduino CNC Shield – 100% GRBL Compatable | Protoneer.co.nz

AxeGrinder:
CNC Shield Info here:

It seems that pins A4 and A5 are not used.

Write a short program using analogRead() on those pins and see what results you get.

...R

Here is the pin to pin map of the CNC shield to the Uno.

cnc shield Uno pins.jpg

You can use any of the analog inputs that you are not using for the pot(s). A4 and A5 are on the CNC shield in the blue box. The cyan box shows where the rest of the analog pins are.

cnc shield analog pins.jpg

cnc shield Uno pins.jpg

cnc shield analog pins.jpg

Thanks guys! I even asked the guy who sold the shield, and he thought I'd "struggle" to get a pot to work with the shield, but I was sure it must be possible... here we go again, trying to get my head around Arduino lol

On the header with SCL and SDA there are 5V and ground pins available that you can use to supply the pot. Connect one end of the pot to 5V the other end to ground and the wiper to the pin marked Resume. Read the pot with

const byte analogIn = A2; // resume on CNC shield

void setup()
{
   Serial.begin(115200);
}

void loop()
{
   static unsigned long timer = 0;
   unsigned long interval = 1000;
   if (millis() - timer >= interval)
   {
      timer = millis();
      unsigned int analogValue = analogRead(analogIn);
      Serial.print(" analog value = ");
      Serial.println(analogValue);
   }
}

groundFungus:
On the header with SCL and SDA there are 5V and ground pins available the you can use to supply the pot. Connect one end of the pot to 5V the other end to ground and the wiper to the pin marked Resume. Read the pot with

Wow, this is a great start, thanks... I think I shall try ans spend some time breaking it down before I go hacking at it :slight_smile:

So, I ran the code provided by GroundFungus, wired as proposed, with a cheap 10k breadboard pot and, and watched the terminal...

It's interesting that the reading falls from it's start at around 500 and diminishes to below 300, then fluctuates between 280 and 300 (see attachment)... I'm guessing this is just the capacitors doing their thing?

However, as I adjust the pot, I see no change in the figures... Also, tho it still works, I smoked the pot a couple of times before I realized you can't turn the knob all the way to the left! At first I was quite happy, as this position shut down the boards, till smoke appeared from the pot! I am guessing (again) that this is due to the breadboard pot not having an "off" position, and so I need a pot with a switch, which is an outcome I like, as at present the machine is powered up by connecting the 12v power supply direct to the Arduino input. I hope my guess is correct? In the mean time, until I get a decent potentiometer, I may have to raid one of my guitars!

BTW: I just check the 10K pot, which is operating just fine, ranging from approx 150 Ohms to 13K Ohms, so I am trying to understand why there is no change to the reading, which I understand is an integer of the voltage read at a2. I checked the voltage at a2/gnd, which ranges from 0 to 2.0mV, past 2mV and the pot starts to smoke at the stop lol

Sorry about the lengthy note, but I'm just trying to understand what I'm seeing on the terminal, and why nothing changes as I adjust the pot?

I actually connected a 10K linear taper pot as described to my CNC shield and tested the code before I posted the code so I know that it works. The pot should never smoke if connected properly. My guess is that you connected the wiper and one end of the pot to ground and 5V and the other end of the pot to resume (A2). That would cause a dead short at one end of the pot travel. Here is the right way.

groundFungus:
I actually connected a 10K linear taper pot as described to my CNC shield and tested the code before I posted the code so I know that it works. The pot should never smoke if connected properly. My guess is that you connected the wiper and one end of the pot to ground and 5V and the other end of the pot to resume (A2).

Thanks for this... I think the wiring is correct, see images... red and black are power, and white is the wiper connected to A2, resume.
I wonder if the trimpot is suitable, or has a fault?

Wiring looks right.

I wonder if the trimpot is suitable, or has a fault?

What resistance is measured from red to black? From black to white while the pot is rotated?