I have a problem with stepmotor working when I check sensors in loop or via millis() method it stops or lower the velocity or only bumping. My code:
// Define stepper motor connections:
#define dirPin 14
#define stepPin 27
#include <OneWire.h>
#include <DallasTemperature.h>
// Data wire is plugged into port 15 on the ESP32
#define ONE_WIRE_BUS 15
#include <Adafruit_ADS1X15.h>
Adafruit_ADS1115 ads; /* Use thi for the 12-bit version */
// Setup a oneWire instance to communicate with any OneWire devices
OneWire oneWire(ONE_WIRE_BUS);
// Pass our oneWire reference to Dallas Temperature.
DallasTemperature sensors(&oneWire);
// variable to hold device addresses
DeviceAddress Thermometer;
int deviceCount = 0;
uint8_t sensor1[8] = {0x28, 0x93, 0x74, 0x31, 0x00, 0x00, 0x00, 0x43};
uint8_t sensor2[8] = {0x28, 0xA4, 0xDA, 0x76, 0x00, 0x00, 0x00, 0xDC};
uint8_t sensor3[8] = {0x28, 0x96, 0x0C, 0x77, 0x00, 0x00, 0x00, 0x12};
uint8_t sensor4[8] = {0x28, 0x93, 0x74, 0x31, 0x00, 0x00, 0x00, 0x43};
float tempSensor1, tempSensor2, tempSensor3, tempSensor4;
// These four lines result in 1 step:
int value = 200;
// Im wyższa częstotliwość tym więcej amper, im mniejsza tym szybciej idzie
float voltage;
void setup() {
Serial.begin(115200);
ads.begin();
pinMode(4, OUTPUT);
digitalWrite(4, LOW);
// Declare pins as output:
pinMode(stepPin, OUTPUT);
pinMode(dirPin, OUTPUT);
// Set the spinning direction CW/CCW:
digitalWrite(dirPin, HIGH);
// Start up the library
sensors.begin();
}
void loop() {
int16_t adc0;
digitalWrite(stepPin, HIGH);
delayMicroseconds(value);
digitalWrite(stepPin, LOW);
delayMicroseconds(value);
temperature();
adc0 = ads.readADC_SingleEnded(0);
Serial.println(((adc0 * 0.1875)/1000),3);
}
void temperature() {
sensors.requestTemperatures();
tempSensor1 = sensors.getTempC(sensor1); // Gets the values of the temperature
tempSensor2 = sensors.getTempC(sensor2); // Gets the values of the temperature
tempSensor3 = sensors.getTempC(sensor3); // Gets the values of the temperature
tempSensor4 = sensors.getTempC(sensor4); // Gets the values of the temperature
Serial.println(tempSensor1);
Serial.println(tempSensor2);
Serial.println(tempSensor3);
Serial.println(tempSensor4);
}
What can I do to get sensor values and also have continous step motor driving? I want to change step motor speed depending on readed values but not make to stop step motor, it need to work always, continously.
Sorry for my English. Thanks in advance. I think it is only programming problem, which can be solved by some code, but I don't know how to do it