Quantcast
Channel: Arduino Forum - Latest topics
Viewing all articles
Browse latest Browse all 15544

Follow focus but for the zoom ring..Can't figure out how to do it

$
0
0

Hi ! I'm currently using this script with a nema 17 and a tmc2209 to control the focus ring of my lens with a rotary encoder.

#include <ESP32Encoder.h>
#include <AccelStepper.h>

#define CLK 34  // CLK ENCODER
#define DT 35   // DT ENCODER
ESP32Encoder encoder;

////////////STEPPER FOCUS//////////////////////////////////
const int stepPin = 12;
const int directionPin = 13;

AccelStepper stepperFocus(AccelStepper::DRIVER, stepPin, directionPin);
#define enablePin1 14  ///

int motorSpeedFocus = 10000;  //maximum steps per second (about 5rps / at 8 microsteps)
int motorAccelFocus = 8600;   //steps/second/second to accelerate

///////////////STEPPER ZOOM////////////////
const int stepPin2 = 4;
const int directionPin2 = 26;

AccelStepper stepperZoom(AccelStepper::DRIVER, stepPin2, directionPin2);
#define enablePin2 25  ///

int motorSpeedZoom = 4800;  //maximum steps per second (about 5rps / at 8 microsteps)
int motorAccelZoom = 4800;  //steps/second/second to accelerate

void setup() {
  pinMode(PinSW1, INPUT_PULLUP);  //SW1 A2

  stepperFocus.setMaxSpeed(motorSpeedFocus);
  stepperFocus.setSpeed(motorSpeedFocus);
  stepperFocus.setAcceleration(motorAccelFocus);

  pinMode(enablePin1, OUTPUT);
  pinMode(enablePin2, OUTPUT);

  encoder.attachHalfQuad(DT, CLK);
  encoder.setCount(0);

  //Serial.println(mode);
  Serial.begin(115200);
}

void focuser() {
  long newPosition = encoder.getCount();
  stepperFocus.moveTo(newPosition * 10);
  stepperFocus.run();
}

void loop() {
  focuser();
}

Everything works fine but what I want to do is the same thing but for the zoom ring.

To sum up, I want to control the nema 17 stepper with the rotary encoder (not the speed, the position) and make the stepper stop when the lens zooms to the maximum (minimum too) so as not to damage it, but I can't manage it and don't know how to do it with accelstepper and an endstop because I can't find an example of someone who's done the same thing.

Thanks in advance and sorry for my english..

2 posts - 2 participants

Read full topic


Viewing all articles
Browse latest Browse all 15544