Go Down

Topic: Simple stepper program help (Read 464 times) previous topic - next topic

Johnredearth

Hi
I am new and want to get a simple pot controller to control the motion of stepper.  Ie half a turn to the left and the stepper mimics the movement and stops. Basically to work like a servo.  Ultimately once this is going want to make it respond to RC and use it on a model. However the first part is always the hardest.

I have NEMA 11 stepper, arduino uno, an easy driver and using Accelstepper library. External 12v on the easy driver.  I am trying to get the proportional  sketch to work in accordance with my needs without any success at all.  Analog-in is working properly.  Have modified as below.

I have tried to find 'starter code' to get going with this but this is the closest I can get to.

This does not work. 

Code: [Select]


// ProportionalControl.pde
// -*- mode: C++ -*-
//
// Make a single stepper follow the analog value read from a pot or whatever
// The stepper will move at a constant speed to each newly set posiiton,
// depending on the value of the pot.
//
// Copyright (C) 2012 Mike McCauley
// $Id: ProportionalControl.pde,v 1.1 2011/01/05 01:51:01 mikem Exp mikem $

#include <AccelStepper.h>

// Define a stepper and the pins it will use
AccelStepper stepper; // Defaults to AccelStepper::FULL4WIRE (4 pins) on 2, 3, 4, 5

// This defines the analog input pin for reading the control voltage
// Tested with a 10k linear pot between 5v and GND
#define ANALOG_IN A0

void setup()

  stepper.setMaxSpeed(1000);
}

void loop()
{
 
 {
  int val = analogRead(ANALOG_IN);
  val = map(ANALOG_IN, 0, 1023, 0, 1600);
 
  stepper.runToNewPosition(val);
}


}


PaulS

Code: [Select]
  int val = analogRead(ANALOG_IN);
  val = map(ANALOG_IN, 0, 1023, 0, 1600);

I can not see the value of mapping a constant pin number from some unrealistic range to another range.

Mapping the value read from the analog pin does make sense.


Go Up