Controls Code
Controls Code
h>
#include "ADS1115-Driver.h"
ADS1115 ads1115 = ADS1115(ADS1115_I2C_ADDR_GND);
uint16_t adcValue = 0;
// FUNCTIONS ====================================================================
void setupStepper() {
pinMode(stepX,OUTPUT);
pinMode(dirX,OUTPUT);
pinMode(enPin,OUTPUT);
digitalWrite(enPin,LOW);
digitalWrite(dirX,HIGH);
}
}
delayMicroseconds(700);
}
void setupADC() {
ads1115.reset();
ads1115.setDeviceMode(ADS1115_MODE_SINGLE);
ads1115.setDataRate(ADS1115_DR_250_SPS);
ads1115.setPga(ADS1115_PGA_6_144);
ads1115.setMultiplexer(ADS1115_MUX_AIN0_GND);
adcValue = readADC();
}
uint16_t readADC() {
ads1115.startSingleConvertion();
delayMicroseconds(25); // The ADS1115 needs to wake up from sleep mode and
usually it takes 25 uS to do that
while (ads1115.getOperationalStatus() == 0) { makeStep(stepTarget); }
return ads1115.readRawValue();
}
void setup() {
setupStepper();
pinMode(analogInPin, INPUT);
Serial.begin(115200);
if (myPID.err()) {
Serial.println("There is a configuration error!");
for (;;) {}
}
}
void loop() {
//setpointShift = (previousPosition - currentPosition);
Serial.println(String(setpointShift));
activeSetpoint = staticSetpoint + setpointShift;
stepTarget = readADC() - activeSetpoint;
if(loopCounter % 10 == 0) {
//loopCounter = 0;
setpointShift = 0;//(previousPosition - currentPosition);
previousPosition = currentPosition;
//setpointShift = myPID.step(0, currentPosition);
}
makeStep(int(stepTarget));
loopCounter++;
}