Hi,
I have a 5 inch Nextion display and I am trying to have it connect with my arduino for a project, I have no idea how to code for it though. What I'm trying to do is have it start and stop the main code with two buttons, and have it be able to change the temperature variable within my main code so alarms will go off at the right temp.
Here is my main code
#include <Adafruit_MAX31856.h>
#include <RunningAverage.h>
#include <LiquidCrystal.h>
#include <SPI.h>
#include <SD.h>
// Use software SPI: CS, DI, DO, CLK
Adafruit_MAX31856 max = Adafruit_MAX31856(3, 5, 7, 8);
// use hardware SPI, just pass in the CS pin
//Adafruit_MAX31856 max = Adafruit_MAX31856(10);
RunningAverage myRA(10);
int samples = 10;
long count = 0;
LiquidCrystal lcd(4, 6, 10, 11, 12, 13);
int tempC, tempF;
const int Alarm = 9; //Alarm System is on 9
File myFile;
void setup() {
Serial.begin(115200);
Serial.println("MAX31856 thermocouple test");
pinMode(5, OUTPUT);
myRA.clear(); // explicitly start clean
lcd.begin(16, 2);
pinMode(Alarm, OUTPUT); // Set buzzer - pin 9 as an output
max.begin();
max.setThermocoupleType(MAX31856_TCTYPE_J);
Serial.print("Thermocouple type: ");
switch ( max.getThermocoupleType() ) {
case MAX31856_TCTYPE_B: Serial.println("B Type"); break;
case MAX31856_TCTYPE_E: Serial.println("E Type"); break;
case MAX31856_TCTYPE_J: Serial.println("J Type"); break;
case MAX31856_TCTYPE_K: Serial.println("K Type"); break;
case MAX31856_TCTYPE_N: Serial.println("N Type"); break;
case MAX31856_TCTYPE_R: Serial.println("R Type"); break;
case MAX31856_TCTYPE_S: Serial.println("S Type"); break;
case MAX31856_TCTYPE_T: Serial.println("T Type"); break;
case MAX31856_VMODE_G8: Serial.println("Voltage x8 Gain mode"); break;
case MAX31856_VMODE_G32: Serial.println("Voltage x8 Gain mode"); break;
default: Serial.println("Unknown"); break;
}
}
void loop()
{
{
tempC = myRA.getAverage();
tempF = (((myRA.getAverage() * 9) / 5 + 32));
lcd.setCursor(0, 0);
lcd.print(tempF); lcd.print(" "); lcd.print((char)223); lcd.print("F");
delay(500);
{
int value = myRA.getAverage(); // read the value from the sensor
lcd.setCursor(0, 1);
lcd.clear();
lcd.setCursor(0, 0);
lcd.print(myRA.getAverage());
lcd.print("C");
lcd.setCursor(0, 1);
lcd.print((myRA.getAverage() * 9) / 5 + 32); //turning the celsius into fahrehait
lcd.print("F");
delay(500);
}
}
{
Serial.print("Cold Junction Temp: "); Serial.println(max.readCJTemperature());
Serial.print("Thermocouple Temp: "); Serial.println(max.readThermocoupleTemperature());
// Check and print any faults
uint8_t fault = max.readFault();
if (fault) {
if (fault & MAX31856_FAULT_CJRANGE) Serial.println("Cold Junction Range Fault");
if (fault & MAX31856_FAULT_TCRANGE) Serial.println("Thermocouple Range Fault");
if (fault & MAX31856_FAULT_CJHIGH) Serial.println("Cold Junction High Fault");
if (fault & MAX31856_FAULT_CJLOW) Serial.println("Cold Junction Low Fault");
if (fault & MAX31856_FAULT_TCHIGH) Serial.println("Thermocouple High Fault");
if (fault & MAX31856_FAULT_TCLOW) Serial.println("Thermocouple Low Fault");
if (fault & MAX31856_FAULT_OVUV) Serial.println("Over/Under Voltage Fault");
if (fault & MAX31856_FAULT_OPEN) Serial.println("Thermocouple Open Fault");
}
delay(500);
{
myRA.addValue(max.readThermocoupleTemperature());
samples++;
Serial.print(" Running Average: ");
Serial.println(myRA.getAverage(), 3);
if (samples == 10)
{
samples = 10;
myRA.clear();
}
}
{
if (myRA.getAverage() > 26)
{
digitalWrite (Alarm, HIGH); // turn the Alarm on (HIGH is the voltage level)
delay(1000); // wait for a second
digitalWrite(Alarm, LOW); // turn the Alarm off by making the voltage LOW
delay(500); // wait for a second
}
else
{
digitalWrite(Alarm, LOW);
}
}
}
}
What the display looks like is attached, all you have to do is type in the temp you want, then press start, then when the alarms go off you press stop. (Ignore the over run part)
Sorry if this is to big of a question, I just need help getting started so anything will be helpful.
Thank you!!

