Well I am trying to adapt this code to sue Accelstepper , I need deceleration for this system ( it is a step mtr connected to a air pressure regulator with a air pressure sensor for feedback controlled by 0-3.3vdc in to a Nano board ) I have this working with the older code ( non accelstepper , I left the old code commented out in the file )
I get no pulse on pins 12,13,14 / D8,D9,D10 on the Nano , WHAT am I missing ??
Please comment mainly on the stepper part , I can sort out other issues later ( I will take any help LOL! )
#include <Arduino.h>
//#include "BasicStepperDriver.h"
#include <AccelStepper.h>
//#include "DRV8825.h"
#include <MovingAverage.h>
MovingAverage average(0.01f);
//#define MOTOR_STEPS 400
//#define RPM 30
//#define MICROSTEPS 1
//#define DIR 8
//#define STEP 9
#define ENABLE 10
//DRV8825 stepper(MOTOR_STEPS, DIR, STEP, ENABLE);
AccelStepper stepper( 1, 13, 12); //13step-12dir pins
int sensorValue0 = analogRead(A2); // sensor
int sensorValue1 = analogRead(A3); // pot
int val0 = 0;
int val1 = 0;
float deadBand;
double error;
void setup() {
Serial.begin(1200);
average.reset( analogRead(A2) ); // sensor
// stepper.begin(RPM, MICROSTEPS);
stepper.setMaxSpeed(200.0);
stepper.setAcceleration(100.0);
deadBand = 12; //stop moving when error < deadBand
}
void measurePressure() {
int raReading = analogRead(A2); // sensor
float psi0 = ((30 - 0) / (620.0 - 0.0)) * (raReading - 83.0);
Serial.println(psi0); // 620-0.0, ra = 83
// Serial.println("psi"); // R1 res=10k, R2=20k ohm to gnd
}
void loop() {
( average.update( analogRead(A2) ) );
measurePressure();
int val0 = analogRead(A2); // read the input pin
val0 = map (val0 , 1022 , 102, 1023 , 0);
//val0 = constrain(val0, 0, 1024); // limits to 0-30psi range 102,692
Serial.println(val0); // sensor
//Serial.println("sensor");
val1 = analogRead(A3) ; // read the input pin , add offset=6
// val1 = constrain(val1, 0, 1024); // limits to 0-30psi range 102,692
// Serial.println(val1); // pot
// Serial.println("pot");
error = val0 - val1;
Serial.println(error);
if (abs(error) < deadBand ) error = 0;
// stepper.enable();
// stepper.move(-error);
/// stepper.disable();
stepper.moveTo(-error);
stepper.run();
// delay(5);
}