I want to read temp from two max6675 and print on nextion display and at the same time stepper motor working as well , but the problem is writing data to nextion make interrupt on stepper motor , can anyone help me ?
#include <Stepper.h>
#include "EasyNextionLibrary.h"
#include "max6675.h"
const int stepsPerRevolution = 200; // change this to fit the number of steps per revolution
// for your motor
const int REFRESH_TIME = 100;
unsigned long refresh_timer = millis();
float dtempc = 0.0f;
float dtempf = 0.0f;
float btempc = 0.0f;
float btempf = 0.0f;
//============Drum Pin Temp digital pin in atmega============
int thermoDO = 4;
int thermoCS = 5;
int thermoCLK = 6;
int thermoDO1 = 7;
int thermoCS1 = 8;
int thermoCLK1 = 9;
EasyNex myNex(Serial);
MAX6675 thermocouple(thermoCLK, thermoCS, thermoDO);
MAX6675 thermocouple1(thermoCLK1, thermoCS1, thermoDO1);
// initialize the stepper library on pins 8 through 11:
Stepper myStepper(stepsPerRevolution, 10, 11, 12, 13);
int stepCount = 0; // number of steps the motor has taken
void setup() {
// nothing to do inside the setup
myNex.begin(9600);
}
void loop() {
myNex.NextionListen();
// read the sensor value:
int sensorReading = analogRead(A0);
// map it to a range from 0 to 100:
int motorSpeed = map(sensorReading, 0, 1023, 0, 100);
// set the motor speed:
if (motorSpeed > 0) {
myStepper.setSpeed(motorSpeed);
// step 1/100 of a revolution:
myStepper.step(stepsPerRevolution / 100);
}
printonnextion();
}
void printonnextion(){
if((millis()-refresh_timer) > REFRESH_TIME)
{
dtempc = thermocouple.readCelsius();
dtempf = thermocouple.readFahrenheit();
btempc = thermocouple1.readCelsius();
btempf = thermocouple1.readFahrenheit();
myNex.writeStr("dtempc.txt", String(dtempc)+"C");
myNex.writeStr("dtempf.txt", String(dtempf)+"F");
myNex.writeStr("btempc.txt", String(btempc)+"C");
myNex.writeStr("btempf.txt", String(btempf)+"F");
myNex.writeNum("drumtemp.val", dtempc);
myNex.writeNum("beantemp.val", btempc);
refresh_timer = millis();
}
}
but the problem is writing data to nextion make interrupt on stepper motor , can anyone help me ?