Pololu tic + arduino + potentiomer

Hi,

I am writing to ask for help with my project. I want to control a stepper motor with a potentiometer using the serial interface with arduino. I do not with to use the analog speed interface as i wish to obtain outputs from my project.

I have connected the interfaces between the arduino and the tic825 and run basic test code to make sure everything works... it does. I just seem to be having trouble writing the code for the potentiometer work. Pls help...

The reason im doing it this way is so i can pull the velocity out and display it

Attached is some basic code, that i have been messing with...

sorry for being so bad at this

steppermotordriver.ino (1016 Bytes)

This isn't doing what the comment says:

  int newCustom = map(customDelay, 0, 12000, 10, 6000); // Convrests the read values of the potentiometer from 0 to 1023 into desireded delay values (300 to 4000)

I suspect that your delays are too short and that therefore you're stepping the stepper faster than it can react.

What size delay did you use in the test code that did step the motor?

I have been messing with values trying to get it to work... I understand that those values correspond to steps, but which ones are delays...

I guess what im trying to say is im not sure what those values represent... can someone pls explain.

sorry

Before you go much further, you should read the sticky posting at the top of each section How to Use this Forum

The part about posting your code in code tags is important, because people using phones can't see attachments. In line viewing is much easier than downloading. With code tags, your code will look like this

// Defines pins numbers
const int stepPin = 4;
const int dirPin = 3;
int customDelay, customDelayMapped; // Defines variables

void setup() {
  // Sets the two pins as Outputs
  pinMode(stepPin, OUTPUT);
  pinMode(dirPin, OUTPUT);

  digitalWrite(dirPin, LOW); //Enables the motor to move in a particular direction
}
void loop() {

  customDelayMapped = speedUp(); // Gets custom delay values from the custom speedUp function
  // Makes pules with custom delay, depending on the Potentiometer, from which the speed of the motor depends
  digitalWrite(stepPin, HIGH);
  delayMicroseconds(customDelayMapped);
  digitalWrite(stepPin, LOW);
  delayMicroseconds(customDelayMapped);
}
// Function for reading the Potentiometer
int speedUp() {
  int customDelay = analogRead(A0); // Reads the potentiometer
  int newCustom = map(customDelay, 0, 12000, 10, 6000); // Convrests the read values of the potentiometer from 0 to 1023 into desireded delay values (300 to 4000)
  return newCustom;
}

Your map syntax is incorrect

map(value, fromLow, fromHigh, toLow, toHigh)

Typical step speeds might be 1000 to 4000 per second. See Stepper Motor Basics - Motors, Mechanics, Power and CNC - Arduino Forum

newCustom = map(customDelay, 0, 1023, 250, 1000);