Wrong temps

Hi there,

First time posting here, so hi everyone!

Hope someone could help me on a code please.

I´m making an temperature gauge with an oled display and its working fine until it gets to 650 degrees.

More than that it shows negative values…

#include “U8glib.h”
#include <SPI.h>
#include <Wire.h>
#include “Adafruit_MAX31855.h”
//#include “max6675.h”
#define OLED_MOSI 9
#define OLED_CLK 10
#define OLED_DC 11
#define OLED_CS 12
#define OLED_RESET 13
U8GLIB_SSD1306_128X64 u8g(10, 9, 12, 11);

const int buzzer = 13; // pin that the LED is attached to
//const int ledpin = 8;

int currentTemp = 0;
String thisTemp = “”;
int maxTemp = 0; // maximum temperature reached
int minTemp = 0; // minimum temperature reached
int pad = 0;
int thermoDO = 5;
int thermoCS = 4;
int thermoCLK = 3;
Adafruit_MAX31855 thermocouple(thermoCLK, thermoCS, thermoDO);

//MAX6675 thermocouple(thermoCLK, thermoCS, thermoDO);
//int vccPin = 3;
// int gndPin = 2;
void draw(void) {
u8g.setFont(u8g_font_profont29);
u8g.drawStr(1, 25, “EGT”);
u8g.setFont(u8g_font_10x20);
// show max temp reached
u8g.drawStr(50, 15, “Max”);
if (maxTemp <= currentTemp) {
maxTemp = currentTemp;
}
thisTemp = String(maxTemp);
thisTemp = thisTemp + “\260C”;
const char* maxTempC = (const char*) thisTemp.c_str();
u8g.drawStr(90, 15, maxTempC);
// show the min temp reached
//u8g.drawStr(50, 30, “Min”);
if (minTemp >= currentTemp) {
minTemp = currentTemp;
}
thisTemp = String(minTemp);
thisTemp = thisTemp + “\260C”;
const char* minTempC = (const char*) thisTemp.c_str();
//u8g.drawStr(90, 30, minTempC);
u8g.setFont(u8g_font_profont29);
if (currentTemp > 99) {
pad = 2;
}
if (currentTemp > 9 && currentTemp < 100) {
pad = 10;
}
if (currentTemp < 10) {
pad = 18;
}
thisTemp = String(currentTemp);
thisTemp = thisTemp + “\260C”;
const char* newDispC = (const char*) thisTemp.c_str();
u8g.drawStr(pad, 58, newDispC);
}
void setup(void) {
// initialize the LED pin as an output:
pinMode(buzzer, OUTPUT);
// pinMode(ledpin, OUTPUT);
Serial.begin(9600);
Wire.begin();
// u8g.setRot90();
delay(500); // wait for MAX chip to stabilise

currentTemp = (thermocouple.readCelsius());
minTemp = int(thermocouple.readCelsius());
maxTemp = int(thermocouple.readCelsius());
}
void loop(void) {
if (thermocouple.readCelsius()>110) {

// digitalWrite(ledpin, HIGH);
tone(buzzer,50);
delay(200);
noTone(buzzer);
delay(100);
tone(buzzer,50);
delay(200);
noTone(buzzer);
delay(100);
tone(buzzer,2000);
delay(200);
noTone(buzzer);
delay(100);
tone(buzzer,2000);
delay(200);
noTone(buzzer);
delay(100);
tone(buzzer,2000);
delay(200);
noTone(buzzer);
delay(100);
tone(buzzer,2000);
delay(200);
noTone(buzzer);
delay(100);
tone(buzzer,2000);
delay(200);
noTone(buzzer);
delay(100);
tone(buzzer,2000);
delay(200);
noTone(buzzer);
delay(100);

} else {
noTone(buzzer);
//digitalWrite(ledpin, LOW);

}
currentTemp = 0;
for (int f = 0; f < 50; f++) {
currentTemp = thermocouple.readCelsius() + currentTemp;
}
currentTemp = currentTemp / 50; // averages out 50 readings
// picture loop
u8g.firstPage();
do {
draw();
} while ( u8g.nextPage() );
// rebuild the picture after some delay
delay(250);
}

int currentTemp = 0;You sum fifty readings into that.

  • Please use code tags
  • Please use CTRL-T to autoformat code
  • Please use empty lines to split the code in "logical paragraphs"

All this will improve readability

Thank you