Max6675 issues

Hey guys I have a mega with max6675 connected to an ungrounded k type thermocouple. Using this code

but instead of pins 8,9,10 I’m using 50,53,52. I am constantly getting nan or erratic readings
I can’t get a consistent reading.
It was ages since last used and cant remember if I previously tested it. It is inbetween an hm10 and adxl345 which work fine. Would bad soldier joints or modules being to close cause an issue.

The MAX6675 is using SPI interfaces for communication. Some time the hardware SPI is not available or you want to use different pins, the solution is software (bit-bang) SPI.

The Mega, Mega2560, ATmega1280 or ATmega2560 has hardware SPI: MOSI-51, MISO-50, SCLK-52, SS/CS-53

If you want to use hardware SPI try this example from my library.
If you want to use software SPI try this example.

It is STRONGLY recommended to add a 10nF/0.01mF ceramic surface-mount capacitor, placed across the T+ and T- pins, to filter noise on the thermocouple lines.