Hi Everyone,
This is my first project so I am sure there is something simple I don't understand. Any thoughts or suggestions will be greatly appreciated. Thanks
I am working on creating a PID temp controller. I am using a MAX31856 with a J type T/C as the temp sensor. I am using two push buttons. (yes, I am using the internal pull up resistors) One to increase and one to decrease the set point. All printing out to the standard 16x2 LCD. Before I added the code to read actual temperature using the MAX31856, the response of buttons was instantaneous. As fast as I can press the buttons the display would keep up. I added the code and got the sensor to output and display the actual ambient temp just fine, but once I added the code for the MAX31856 the buttons only change the set point at a rate of about 1/sec.
I have commented out the code for the sensor and the sensor still wired and the buttons response returns to normal. As soon as I uncomment the code the buttons response time returns. I removed wiring and hardware and left the code in and I got the same results. I looked through the src and header files for the MAX31856 library, I don't see any obvious causes.
The MAX31856 uses 4 wire SPI to connect to the Arduino uno I am using. I am using pins (10, 11, 12, 13)
Below is my code followed. Attached is the MAX31856 library I got from the library manager.
#include <Adafruit_Sensor.h>
#include <Adafruit_MAX31856.h>
#include <LiquidCrystal.h>
// Constants
const int decreaseButtonPin = 7; // the # of the decrease push button pin
const int increaseButtonPin = 8; // the # of the increase push button pin
// Non-Const Global
int decreaseButtonState; // the current state of the decrease push button
int increaseButtonState; // the current state of the increase push button pin
int dLastButtonState = LOW; // the previous reading of decrease push button pin
int iLastButtonState = LOW; // the previous reading of increase push button pin
int tempSetPoint = 32; // the # of times button was pressed since last reset
int setPointLowLimit = 32; // the low limit for the temp setpoint
int setPointHighLimit = 250; // the high limit for the temp setpoint
// long is used because time in millisecs with grow quickly
unsigned long lastDebounceTime = 50; // the last time the output pin was toogled
unsigned long debounceDelay = 0; // the debounce time in millisecs increase if the output flickers
//Intialize the library with the numbers of the interface pins
LiquidCrystal lcd(9, 6, 5, 4, 3, 2);
Adafruit_MAX31856 maxthermo = Adafruit_MAX31856(10, 11, 12, 13);
void setup() {
// Setup for MAX31586
Serial.begin(115200); // set the baud rate and intialized serial comms
maxthermo.begin(); // creates an MAX31586 object
maxthermo.setThermocoupleType(MAX31856_TCTYPE_J); // Configures for J Type T/C
// Configures the Push Buttons
pinMode(increaseButtonPin, INPUT_PULLUP); // Pin #8
pinMode(decreaseButtonPin, INPUT_PULLUP); // Pin #7
// Initialize the LCD Display
// set up the LCD's number of columns and rows:
lcd.begin(16, 2); // set up the LCD's number of columns and rows
lcd.print("TEMP: "); // Prints header on first line
lcd.setCursor(0, 1); // Set Cursor on the new line
lcd.print("SETPOINT: "); // Prints header on second line
}
void loop() {
// Variables
int iButtonReading = digitalRead(increaseButtonPin); // read the state of increase button into iButtonReading
int dButtonReading = digitalRead(decreaseButtonPin); // read the state of the decrease button into dButtonReading
int actualTemp = maxthermo.readThermocoupleTemperature(); // the actual temp read from the sensor
/******
* check to see if either button was just pressed
* (i.e. the input went from LOW to HIGH), and you've waited long enough
* since the last press to ignore any noise:
******/
// If either of the button states changed, due to noise or pressing:
if (iButtonReading != iLastButtonState || dButtonReading != dLastButtonState) {
// lastDebounceTime = millis(); // Then reset the decouncing timer
}
// If the reading has been there for longer than the debounce
if ((millis() - lastDebounceTime) > debounceDelay) {
// Then delay, so take it as the actual current state
//If the increase button state has changed
if (iButtonReading != increaseButtonState) {
increaseButtonState = iButtonReading; // Then take the new state
// If the increase button state is HIGH & the setpoint is less than the setpoint high limit
if (increaseButtonState == LOW && setPointHighLimit > tempSetPoint) {
tempSetPoint = tempSetPoint + 1; // Then increase the setPoint by 1
}
}
// If the decrease button state has changed
if (dButtonReading != decreaseButtonState) {
decreaseButtonState = dButtonReading; // Then take the new state
// If decreaseed button state is HIGH & the setpoint is greater than the setpoint low limit
if (decreaseButtonState == LOW && tempSetPoint > setPointLowLimit) {
// Then decrease the setpoint by 1
tempSetPoint = tempSetPoint - 1;
}
}
}
/********
* Print current setpoint and actual temp to the LCD
********/
lcd.setCursor(6, 0); // Sets the cursor after the "Temp: " header
int actualTempInF = (actualTemp / (5/9.0) + 32); // Removes the decimal from the display
lcd.print(actualTempInF); // Prints actual temp in degrees F
lcd.print((char)223); // Degree symbol
lcd.print("F");
lcd.setCursor(10, 1);
lcd.print(tempSetPoint);
lcd.print((char)223); // Degree symbol
lcd.print("F");
// save the reading. Next time trough the loop, it'll be the lastButtonState
iLastButtonState = iButtonReading;
dLastButtonState = dButtonReading;
}
Adafruit_MAX31856.cpp (10 KB)
Adafruit_MAX31856.h (5.13 KB)