Go Down

Topic: Pololu tic + arduino + potentiomer (Read 288 times) previous topic - next topic

Hanna8754

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

wildbill

This isn't doing what the comment says:
Code: [Select]

  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?

Hanna8754

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

cattledog

#3
Apr 21, 2019, 10:31 pm Last Edit: Apr 21, 2019, 10:37 pm by cattledog
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
Code: [Select]

// 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

Code: [Select]
map(value, fromLow, fromHigh, toLow, toHigh)

Typical step speeds might be 1000 to 4000 per second.  See https://forum.arduino.cc/index.php?topic=284828.0

Code: [Select]
newCustom = map(customDelay, 0, 1023, 250, 1000);



Go Up