MAX6675 custom SPI pins

Hi everyone!
I'm try to use a MAX6675 module on ESP32. Because of PCB design, I have to use custom SPI pins. I guess that's why I got only 0.00 (zero) values at readings. Yes, I know it's a common problem, but I could not find a solution on the forum.
Measured Vcc is 3.26 V
I tried tu use MAX6675 library, and define a new SPI instance, but it doesn't help.
The module is works, because the basic example of library shows right values.
Here is my code:

#define MAX6675_SCK 25
#define MAX6675_CS 23
#define MAX6675_SO 32

unsigned long timeToShowTemp = 0;

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

void loop() {
  if ( millis() > timeToShowTemp ) {
    timeToShowTemp = millis() + 10000;      //every 10 seconds
    Serial.println(readThermocouple());
  }
}

double readThermocouple() {

  uint16_t v;
  pinMode(MAX6675_CS, OUTPUT);
  pinMode(MAX6675_SO, INPUT);
  pinMode(MAX6675_SCK, OUTPUT);
  
  digitalWrite(MAX6675_CS, LOW);
  delay(1);

  // Read in 16 bits,
  //  15    = 0 always
  //  14..2 = 0.25 degree counts MSB First
  //  2     = 1 if thermocouple is open circuit  
  //  1..0  = uninteresting status
  
  v = shiftIn(MAX6675_SO, MAX6675_SCK, MSBFIRST);
  v <<= 8;
  v |= shiftIn(MAX6675_SO, MAX6675_SCK, MSBFIRST);
  
  digitalWrite(MAX6675_CS, HIGH);
  if (v & 0x4) 
  {    
    // Bit 2 indicates if the thermocouple is disconnected
    return NAN;     
  }

  // The lower three bits (0,1,2) are discarded status bits
  v >>= 3;

  // The remaining bits are the number of 0.25 degree (C) counts
  return v*0.25;
}

Can someone help me?

I'm not sure I understand this. If the library works, then why not use it?

The library uses hardware SPI pins, but I have to use other pins.
Edit:
To be quite precise, I ran the example program on an ESP8266

You may [find this link to be useful (K-Type Thermocouple MAX6675 Amplifier with ESP32)l. This assumes your WSP32 looks like the link. The link is built around an ESP 32.

Assuming this is your board?

Note the text on the bottom of the image.

This is the code:

#include "max6675.h" 

int SO = 23;
int CS = 5;
int sck = 18;
MAX6675 module(sck, CS, SO);

void setup() {   
  Serial.begin(115200);
}

void loop() {
  float temperature = module.readCelsius(); 
  Serial.print("Temperature: ");
  Serial.print(temperature);
  Serial.println(F("°C "));   
  delay(1000);
}

Start with that basic setup which should work.

Ron

Temperature: 0.00°C 

So it looks like doesn't work on hardware SPI pins too. But on ESP8266 works well.
Should I try to adjust the clock frequency?

What I see:

  • the millis handling in loop() will break (after 49 days) due to an overflow
  • pin initialization should be moved from readThermocouple() to setup()
  • don't know the pin level after a reset. Might be wrong for CS

Nothing too breaking. Should be working on the second read.

Please provide

  • a wiring diagram
  • some good photos of your actual wiring

Ok, I think i found what's wrong. I got an incorrectly labeled esp32 module.
Red arrow shows the incorrect G23 port, and green arrow marks the correct G23 port.

Thanks for everyone!

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