I have a stepper running in a closed loop using a air pressure sensor (0.5-4.5vdc output) and stepper motor attached to a manual air pressure regulator , when the stepper is running I get no update of the values from the sensor and a pot I use as a setpoint.
the question ? Does the Teensy 3.5 still read the analog inputs while the stepper is running even though the serial port does not print it out ? My stepper seems to over run the setpoint if it has to move very far.
Thanks < If I missed any info let me know please. I may be doing something completely wrong !
the question ? Does the Teensy 3.5 still read the analog inputs while the stepper is running even though the serial port does not print it out ? My stepper seems to over run the setpoint if it has to move very far.
Thanks < If I missed any info let me know please. I may be doing something completely wrong !
Code:
#include <Arduino.h>
//#include "BasicStepperDriver.h"
#include "A4988.h"
#include <MovingAverage.h>
MovingAverage average(0.1f);
const int ANALOG_PIN0 = A2;
const int ANALOG_PIN1 = A3;
// Motor steps per revolution. Most steppers are 200 steps or 1.8 degrees/step
#define MOTOR_STEPS 400
#define RPM 10
int sensorValue0 = analogRead(A2); // sensor
int sensorValue1 = analogRead(A3); // pot
int val0 = 0;
int val1 = 0;
// 1=full step, 2=half step etc.
#define MICROSTEPS 1
// All the wires needed for full functionality
#define DIR 8
#define STEP 9
//Uncomment line to use enable/disable functionality
#define ENABLE 13
//Uncomment line to use enable/disable functionality
BasicStepperDriver stepper(MOTOR_STEPS, DIR, STEP, ENABLE);
float deadBand;
double error;
void setup() {
Serial.begin(9600);
average.reset( analogRead(A3) );
stepper.begin(RPM, MICROSTEPS);
deadBand = 35.0; //stop moving when error < deadBand
}
void measurePressure() {
int raReading = analogRead(A2);
float psi0 = ((30 - 0) / (920.7 - 157.3)) * (raReading - 156.3);
Serial.println(psi0);
Serial.println(" ");
}
void loop() {
//analogReadResolution(12);// set to 12bit ACD
val0 = analogRead(A2); // read the input pin
Serial.println(val0); // debug value
Serial.println("val0");
val1 = analogRead(A3); // read the input pin
Serial.println(val1); // debug value
Serial.println("val1");
error = val0 - val1;
if (abs(error) < deadBand ) error = 0;
measurePressure();
delay (50);
// energize coils - the motor will hold position
stepper.enable();
// stepper.rotate(1080);
stepper.move(-error);
// pause and allow the motor to be moved by hand
stepper.disable();
delay(150);
}