Curious what I do wrong.
Button currrently controls up and down movement of the stepper motor.
Code works but as soon as I uncomment a line related to serial.print it also stops to work correctly.
I need the combination as I use the stepper to compress a spring and measure the force and the current position which need to be send to a PC application.
Am I asking to much from this combo?
Paco
#include <HX711.h>
// HX711.DOUT - pin #A1
// HX711.PD_SCK - pin #A0
HX711 scale(A1, A0); //load cell libary
int Analog2 = 16; // Use analog port on shield for push button to control movement and Direction
int Analog3 = 17; // Use analog port on shield for push button to control movement and Direction
int Distance = 0; // Record the number of steps the motor has done
int delayTimeUp = 300;
int delayTimeDown = 100;
int Position = 1000;
boolean MotorStopDown = 0;
boolean MotorStopUp = 0;
boolean flagStartInit = 0;
boolean flagRecording = 0;
boolean flagReturn = 0;
const int DirPin = 8;
const int StepPin =9;
const int EnablePin = 10;
int IncomingData = 0;
int outByte = 0;
int cmdTemp = 0;
int MaxTravel = 0;
boolean LeftTurn = 0;
boolean RightTurn = 0;
void setup()
{
pinMode(DirPin, OUTPUT);
pinMode(StepPin, OUTPUT);
pinMode(EnablePin, OUTPUT);
pinMode(Analog2,INPUT); // set the A2 pin to input
pinMode(Analog3,INPUT); // set the A3 pin to input
digitalWrite(DirPin, LOW);
digitalWrite(StepPin, LOW);
digitalWrite(EnablePin, HIGH);
Serial.begin(9600);
}
void loop()
{
LeftTurn = digitalRead(Analog2);
RightTurn = digitalRead(Analog3);
if (LeftTurn == 1) // upwards
{
digitalWrite(EnablePin, LOW);
digitalWrite(DirPin, LOW);
digitalWrite(StepPin, HIGH);
delayMicroseconds(delayTimeUp);
digitalWrite(StepPin, LOW);
delayMicroseconds(delayTimeUp);
digitalWrite(EnablePin, HIGH);
digitalWrite(DirPin, LOW);
Distance = Distance + 1; // record this Step as part of a rotation where 900 is a quarter rotation
if (Distance == 900);
{
digitalWrite(EnablePin, HIGH);
digitalWrite(DirPin, LOW);
Distance = 0; // reset the Motorstep counter to 0
Position = Position - 1;
}
}
else if (RightTurn == 1) // downwards
{
digitalWrite(EnablePin, LOW);
digitalWrite(DirPin, HIGH);
digitalWrite(StepPin, HIGH);
delayMicroseconds(delayTimeDown);
digitalWrite(StepPin, LOW);
delayMicroseconds(delayTimeDown);
digitalWrite(EnablePin, HIGH);
digitalWrite(DirPin, LOW);
Distance = Distance + 1; // record this Step as part of a rotation where 900 is a quarter rotation
if (Distance == 900);
{
digitalWrite(EnablePin, HIGH);
digitalWrite(DirPin, LOW);
Distance = 0; // reset the Motorstep counter to 0
Position = Position + 1;
}
}
else
{
digitalWrite(EnablePin, HIGH);
digitalWrite(DirPin, LOW);
}
//Serial.print ("A,");
//Serial.println (Position); // keeps score of the steps done to calulate the movement in 0.5 mm + or -
//Serial.print ("B,");
//Serial.println(scale.read()/100); //raw loadcell data devided by 100
}