Another MAX6675 question

Hello, I have been trying to use my Arduino UNO R3 to read three MAX6675 K type thermocouples and write the temperature reading on a ILI9341 controlled LCD screen. The thermocouple temp is reading 32° even when I do not have MAX6675 chip plugged into my breadboard. Code will compile. Here is my code.

#include <SPI.h>
#include <Adafruit_GFX.h>
#include <Adafruit_ILI9341.h>
#include "max6675.h"

// Define TFT pins
#define TFT_CS 10
#define TFT_DC 9
#define TFT_RST 8

// Define MAX6675 pins
#define MAX6675_CS1 4
#define MAX6675_CS2 5
#define MAX6675_CS3 6
#define MAX6675_SCK 13
#define MAX6675_MISO 12

Adafruit_ILI9341 tft = Adafruit_ILI9341(TFT_CS, TFT_DC, TFT_RST);

// Initialize MAX6675 objects
MAX6675 thermocouple1(MAX6675_SCK, MAX6675_CS1, MAX6675_MISO);
MAX6675 thermocouple2(MAX6675_SCK, MAX6675_CS2, MAX6675_MISO);
MAX6675 thermocouple3(MAX6675_SCK, MAX6675_CS3, MAX6675_MISO);

void setup() {
  SPI.begin();
  Serial.begin(9600);
  tft.begin();
  tft.setRotation(3);

  tft.fillScreen(ILI9341_BLACK);
  tft.setTextColor(ILI9341_WHITE);
  tft.setTextSize(2);

  delay(500);
}

void loop() {

  // Display temperatures
  tft.setCursor(10, 40);
  tft.print("Front Cylinder: ");
  tft.print(thermocouple1.readFahrenheit());
  tft.println(" F ");

  tft.setCursor(10, 110);
  tft.print("Rear Cylinder: ");
  tft.print(thermocouple2.readFahrenheit());
  tft.println(" F ");

  tft.setCursor(10, 180);
  tft.print("Crankcase: ");
  tft.print(thermocouple3.readFahrenheit());
  tft.println(" F ");

  // Delay between readings
  delay(2000);
}

Any suggestions on what I have done incorrectly would be appreciated.

Well, ask yourself this: what temperature would you expect to be reported without the MAX6675 connected?

As long as it works properly when the module is plugged in, you have nothing to worry about.

The library is probably receiving 0, interpreting it as Celsius and converting that to Fahrenheit.

1 Like

Hello cedarlakeinstruments, even if I have the MAX6675 chip plugged into my breadboard and a lighter held to the thermocouple it outputs the temp as 32°. The keyword (readFahrenheit) is what is listed in the library as the call for temp output in degress Fahrenheit. I think I have it in the correct places but I could be completely wrong.

Well, start with one thermocouple and debug from there.

Breadboards are notorious for poor connections. Try using alligator jumpers or simiar to connect the thermocouples to the MCU.

If you are using the Adafruit MAX6675 library, try using different pins for MAX6675 SCK and MISO. That library uses software SPI and if hardware SPI is in use it may interfere.

1 Like

Thank you for the information. I will make the connections better.

Thanks for the suggestion, I will try this out.

I was skeptical of that until I looked at the GitHub. I thought they would have at least included an option for Hardware SPI. I've seen much better driver code from Adafruit.

1 Like

I made changed my Sck pin and MISO pins as jim-p suggested now on the serial monitor I receive correct data from the MAX6675 chips but now my TFT display only shows a white screen. I have added lines of code to determine if the TFT is initializing and it reports it is. Anyone have any suggestions on how to get my TFT back to displaying the data?

I think I have narrowed down the problem but I do not know how to solve it. Using the code like this

#include <SPI.h>
#include <Adafruit_GFX.h>
#include <Adafruit_ILI9341.h>
#include "max6675.h"

const int spi_miso_pin = 12;
const int spi_sck_pin = 13;
const byte max6675_num = 3;
const int max6675_cs_pins[max6675_num] = {6, 5, 4};

MAX6675 max6675s[max6675_num] = {
  MAX6675(spi_sck_pin, max6675_cs_pins[0], spi_miso_pin),
  MAX6675(spi_sck_pin, max6675_cs_pins[1], spi_miso_pin),
  MAX6675(spi_sck_pin, max6675_cs_pins[2], spi_miso_pin)
};

// Define TFT pins
#define TFT_CS 10
#define TFT_DC 9
#define TFT_RST 8

Adafruit_ILI9341 tft = Adafruit_ILI9341(TFT_CS, TFT_DC, TFT_RST);

void setup() {
  SPI.begin();
  Serial.begin(9600);

  tft.begin(); // Initialize TFT
  tft.setRotation(3);
  tft.fillScreen(ILI9341_BLACK);
  tft.setTextColor(ILI9341_WHITE);
  tft.setTextSize(2);

  delay(2000);

  // Print initial debug information
  Serial.println("MAX6675 Test");
  for (int i = 0; i < max6675_num; i++) {
    Serial.print("Sensor ");
    Serial.print(i);
    Serial.print(" CS Pin: ");
    Serial.println(max6675_cs_pins[i]);
  }
}

void loop() {
  // Read temperatures
  double temp1 = max6675s[0].readFahrenheit();
  double temp2 = max6675s[1].readFahrenheit();
  double temp3 = max6675s[2].readFahrenheit();

  // Debug print temperatures
  Serial.print("Temp1: ");
  Serial.print(temp1);
  Serial.print(" F, Temp2: ");
  Serial.print(temp2);
  Serial.print(" F, Temp3: ");
  Serial.println(temp3);
  Serial.print(" F");

  // Check for errors
  for (int i = 0; i < max6675_num; i++) {
    if (isnan(max6675s[i].readFahrenheit())) {
      Serial.print("Error reading sensor ");
      Serial.println(i);
    }
  }

  tft.fillScreen(ILI9341_BLACK); // Clear the screen before drawing new data

  tft.setCursor(10, 40);
  tft.print("Front Cylinder: ");
  tft.print(temp1);
  tft.print(" F");

  tft.setCursor(10, 110);
  tft.print("Rear Cylinder: ");
  tft.print(temp2);
  tft.print(" F");

  tft.setCursor(10, 180);
  tft.print("Crankcase: ");
  tft.print(temp3);
  tft.print(" F");

  // Delay between readings
  delay(2000);
}

I receive no data from max6675 chips. If I switch my SCK pin to 3 and MISO pin to 2 I get serial data from the max6675 chips but my TFT goes white. Any ideas on how to fix this?

I would take 20 minutes and rewrite Adafruit's MAX6675 library to use hardware SPI. I know some people treat libraries as Holy Writ and never to be altered by mere users; I'm not one of them. Even with lots of interruptions, it's only a 20 minute job. :slight_smile:

You could try my MAX6675 library - GitHub - RobTillaart/MAX6675: Arduino library for MAX6675 chip for K type thermocouple

You should reorder the pins in the constructor as it is different

MAX6675(uint8_t select, uint8_t miso, uint8_t clock)

And after the call to read() you can check with getStatus() thw quality of the connection, and get the temperature in Celsius by getTemperature(). Conversion to Fahrenheit is not in my library.

Return values of getStatus()

value Description Action
0 OK
4 Thermocouple short to VCC check wiring
128 No read done yet check wiring
129 No communication check wiring

update: adding getFahrenheit() in next release.

1 Like

I guess I was not clear about using different pins.
Your display will use the following pins for SPI
SCK (13)
MISO (12)
MOSI (11)
TFT_CS (10)

So for the MAX6675 you cannot use 10,11,12,or 13 since the display uses those pins.
Using pins 3 and 2 for SCK and MISO for the MAX6675, is fine and what you should do.

Does you display work with any of the Adafruit examples?

Thank you for the suggestion, I did not even think about the library needing tweaked.

I will give this a try, thanks!

I did initially have the display wired like this, did i need to define SCK and MISO for the TFT?

No the library will use the default SPI pins.

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.