#include <max6675.h>
#include <Wire.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>
// Broches MAX6675
int thermoSO = 12;
int thermoCS = 10;
int thermoSCK = 13;
MAX6675 thermocouple(thermoSCK, thermoCS, thermoSO);
// OLED 0.96" 128x64
#define SCREEN_WIDTH 128
#define SCREEN_HEIGHT 64
#define OLED_RESET -1
Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, OLED_RESET);
void setup() {
Serial.begin(9600);
delay(500);
// Initialisation de l'OLED
if(!display.begin(SSD1306_SWITCHCAPVCC, 0x3C)) {
Serial.println(F("Erreur de l'OLED !"));
while(1);
}
display.clearDisplay();
display.setTextSize(1);
display.setTextColor(SSD1306_WHITE);
display.setCursor(0,0);
display.println("MAX6675 Thermocouple");
display.display();
delay(1000);
}
void loop() {
float temperature = thermocouple.readCelsius();
// Affichage sur le moniteur série
if (isnan(temperature)) {
Serial.println("Erreur de lecture du thermocouple !");
} else {
Serial.print("Temperature : ");
Serial.print(temperature);
Serial.println(" °C");
}
// Affichage sur l'OLED
display.clearDisplay();
// Titre
display.setTextSize(1);
display.setCursor(0,0);
display.println("Temperature:");
// Valeur principale en grand
display.setTextSize(3);
display.setCursor(0,20);
if (isnan(temperature)) {
display.println("--.- C");
} else {
display.print(temperature, 1); // 1 chiffre après la virgule
display.println(" C");
}
display.display();
delay(1000);
}