Hey Community!
After days of research and contacting the customer support of Stepperonline way too many times, i was thinking about reaching out to this amazing community with my problem:
I want to run NEMA23 (https://www.omc-stepperonline.com/p-series-ip65-waterproof-nema-23-closed-loop-stepper-motor-2nm-283-28oz-in-with-encoder-1000cpr.html?search=water) and NEMA34 (https://www.omc-stepperonline.com/p-series-ip65-waterproof-nema-34-closed-loop-stepper-motor-4-5nm-637-38oz-in-with-encoder-1000cpr.html?search=water) stepper-motors. They have an included encoder (closed loop). The feedback is used so far by the driver (manual: https://www.omc-stepperonline.com/download/CL57T.pdf) to check if there is a lack of positioning.
My goal is to use this feedback in the arduino code. One reason is to have a value to work with (measurement), because i am controlling many steppers after each other and i want to make sure that they have arrived as planned, before the next one starts. Another reason is that with the "standard" code to drive those steppers, i donĀ“t always get the same result as planned and that is crucial to my machine:
digitalWrite(stepPin, HIGH);
delayMicroseconds(1000);
digitalWrite(stepPin, LOW);
delayMicroseconds(1000);
The answer of the Stepperonline Customer support was:
"This is the way to get the encoder position. Check the position of the motor shaft by the number of pulses output from the serial port.
Note that because the encoder is a differential signal, AB should be isolated from GND. But ARDUINO shares a common ground.
It may cause signal interference.
Because A + A- needs to form a loop.
It seems that A- must be connectted to GND. If it is connected to other digital ports of ARDUINO, there will be no level change of A +."
const int stepPin = 34;
const int dirPin = stepPin + 1;
const int enPin = stepPin + 2;
const int schrittvorgabe = 200;
int outputA = 15; // Connection to A+
int outputB = 16; // Connection to B+
int counter = 0;
int aState;
int aLastState;
void setup() {
// Sets the two pins as Outputs
pinMode(stepPin, OUTPUT);
pinMode(dirPin, OUTPUT);
pinMode(enPin, OUTPUT);
pinMode (outputA, INPUT);
pinMode (outputB, INPUT);
Serial.begin (9600);
// Reads the initial state of the outputA
aLastState = digitalRead(outputA);
}
void loop() {
digitalWrite(dirPin, LOW); // Enables the motor to move in a particular direction
while (counter >= -50) {
//Motoren fahren*********
// Makes 400 pulses for making two full cycle rotation
digitalWrite(stepPin, HIGH);
delayMicroseconds(1000);
digitalWrite(stepPin, LOW);
delayMicroseconds(1000);
//ENCODER AUSLESEN*********
aState = digitalRead(outputA); // Reads the "current" state of the outputA
//Serial.print(outputA);
// If the previous and the current state of the outputA are different, that means a Pulse has occured
if (aState != aLastState) {
// If the outputB state is different to the outputA state, that means the encoder is rotating clockwise
if (digitalRead(outputB) != aState) {
counter ++;
} else {
counter --;
}
Serial.print("Position: ");
Serial.println(counter);
}
aLastState = aState; // Updates the previous state of the outputA with the current state
}
I hope that somebody can help me with the code and show me how to connect the feedback to Arduino correctly. Yet i have put A- and B- on GND of Arduino but think that this could be the mistake.
Thank you in advance!