Read MAX6675 with ESP8266

Place code snippets and demo code here
mezjoc
Posts: 24
Joined: Tue Mar 09, 2021 4:26 pm
Location: Fót / Hungary
Has thanked: 16 times
Been thanked: 8 times

Read MAX6675 with ESP8266

Post by mezjoc »

Hi there.
I bought from Ebay:
MAX6675 K-TypThermoelement Cable Temperature sensor Fühler Arduino Raspberry Pi.
The central IC is MAX6675. He works with SPI communication. How can I read the sensor temperature in basic language using NodeMCU?
Thank you: mezjoc
mezjoc
Posts: 24
Joined: Tue Mar 09, 2021 4:26 pm
Location: Fót / Hungary
Has thanked: 16 times
Been thanked: 8 times

Re: Read MAX6675 with ESP8266

Post by mezjoc »

Wiring Diagram.
Is it appropriate?
You do not have the required permissions to view the files attached to this post.
Last edited by mezjoc on Sat May 22, 2021 4:50 pm, edited 2 times in total.
mezjoc
Posts: 24
Joined: Tue Mar 09, 2021 4:26 pm
Location: Fót / Hungary
Has thanked: 16 times
Been thanked: 8 times

Re: Read MAX6675 with ESP8266

Post by mezjoc »

This is the corresponding wiring diagram.
Image
You do not have the required permissions to view the files attached to this post.
mezjoc
Posts: 24
Joined: Tue Mar 09, 2021 4:26 pm
Location: Fót / Hungary
Has thanked: 16 times
Been thanked: 8 times

Re: Read MAX6675 with ESP8266

Post by mezjoc »

Code: [Local Link Removed for Guests]

'/program/spi_max6675.bas
spi.setup 1000000,1,1    'b/s, data_mode(0-1-2-3), lsb_first(0)-msb_first(1)

'MAX6675/SO-->GPIO12/D6
'MAX6675/CS-->GPIO16/D0
'MAX6675/SCK-->GPIO14/D5
'POWER-->+3V3-GND

pin.mode 16, output ' CS-->GPIO16
timer0 1000,mytimer
wait

mytimer:
i=i+1
pin(16) = 0    'CS=LOW
wlog i;".",spi.byte(0)      'spi.byte(0)=0...4095
pin(16) = 1    'CS=HIGH
return
User avatar
Electroguard
Posts: 836
Joined: Mon Feb 08, 2021 6:22 pm
Has thanked: 268 times
Been thanked: 317 times

Re: Read MAX6675 with ESP8266

Post by Electroguard »

Well done... and you made it look easy in the end.
mezjoc
Posts: 24
Joined: Tue Mar 09, 2021 4:26 pm
Location: Fót / Hungary
Has thanked: 16 times
Been thanked: 8 times

Re: Read MAX6675 with ESP8266

Post by mezjoc »

Unfortunately, the program is not perfect.
At room temperature (+ 25 ° C) -> decimal 100 should be obtained. The result is decimal 6 !!! WELLER soldering iron (Num = 7) -> decimal 34. This is few.
I need help. Where is the mistake? :(
AndyGadget
Posts: 222
Joined: Mon Feb 15, 2021 1:44 pm
Has thanked: 120 times
Been thanked: 132 times

Re: Read MAX6675 with ESP8266

Post by AndyGadget »

Just a wild guess - Haven't had time to look at the code . . .
Is the device returning the result in the form you expect - BigEndian vs LittleEndian?
User avatar
Electroguard
Posts: 836
Joined: Mon Feb 08, 2021 6:22 pm
Has thanked: 268 times
Been thanked: 317 times

Re: Read MAX6675 with ESP8266

Post by Electroguard »

I'm afraid you're the thermocouple expert here, pal!
But here's my thoughts, for what it's worth...

The only thing I can be sure about claimed specifications for Chinese manufactured components is that they are always massively exaggerated, and I consider myself fortunate if the item actually functions in a half-usable manner (I have bought a lot of junki.
I don't know what the working range of your item is supposed to be, but all devices can expect to be less accurate and non-linear towards the extremes of their range.

I have many different types of temperature sensors, but many give readings which are more than a degree out with the others.
Some sensors are so far out that I add or subtract an offset to make it read the same as the 'consensus', but this often drifts out with changing temperature ... eg: the offset might be correct at room temperatures, but gets progressively inaccurate as the temperature drops.

Back to your situation - If the sensor readings are incorrect, then either the readings are wrong, or they are being interpreted wrong.
Either way, assuming that the readings are reasonably linear it should be possible to adjust them to suit (eg: like converting between fahrenheit and centigrade) by applying an offset and multiplication factor.
And as it happens, there is an Annex function which might just help do the trick...

CONVERT.MAP
(number, fromLow, fromHigh, toLow, toHigh)
Re-maps a number from one range to another. That is, a value of fromLow would get mapped to toLow, a value of fromHigh to toHigh, values in-between to values in-between, etc.

Let me know if it works so I can send you my sensors for calibration!
User avatar
Electroguard
Posts: 836
Joined: Mon Feb 08, 2021 6:22 pm
Has thanked: 268 times
Been thanked: 317 times

Re: Read MAX6675 with ESP8266

Post by Electroguard »

I could not get CONVERT.MAP to work on Annex 1.43.3, so I used some equivalent code.
In my case I was simply converting an esp32 ADC value from 0-4096 into an 8 bit result from 0-255, so I was using 0 instead of any offsets, whereas you'll need to adjust to suit the low temperature discrepancy.

fromMin=0: fromMax=4096: toMin=0: toMax=255
value = adc(34) 'my measured value I wish to normalise
result = ((value - fromMin) / (fromMax - fromMin) * (toMax - toMin)) + toMin
User avatar
cicciocb
Site Admin
Posts: 1899
Joined: Mon Feb 03, 2020 1:15 pm
Location: Toulouse
Has thanked: 407 times
Been thanked: 1269 times
Contact:

Re: Read MAX6675 with ESP8266

Post by cicciocb »

Hi,
looking at the arduino code of the adafruit library,
it looks very easy to interface :

Code: [Local Link Removed for Guests]

/**************************************************************************/
/*!
    @brief  Read the Celsius temperature
    @returns Temperature in C or NAN on failure!
*/
/**************************************************************************/
float MAX6675::readCelsius(void) {

  uint16_t v;

  digitalWrite(cs, LOW);
  delayMicroseconds(10);

  v = spiread();
  v <<= 8;
  v |= spiread();

  digitalWrite(cs, HIGH);

  if (v & 0x4) {
    // uh oh, no thermocouple attached!
    return NAN;
    // return -100;
  }

  v >>= 3;

  return v * 0.25;
}
So, this simple code converted to annex gives :

Code: [Local Link Removed for Guests]

'/program/spi_max6675.bas
spi.setup 1000000,1,1    'b/s, data_mode(0-1-2-3), lsb_first(0)-msb_first(1)

'MAX6675/SO-->GPIO12/D6
'MAX6675/CS-->GPIO16/D0
'MAX6675/SCK-->GPIO14/D5
'POWER-->+3V3-GND

pin.mode 16, output ' CS-->GPIO16
timer0 1000,mytimer
wait

mytimer:
i=i+1
pin(16) = 0    'CS=LOW
v = spi.byte(0)
v = v << 8
v = v or spi.byte(0)
pin(16) = 1    'CS=HIGH
if (v and &h4) then
  wlog "no thermocouple attached!"
else
  v = v >> 3
  wlog "Temperature "; v * 0.25 ; "°C"
end if
return
Obviously I did not tested this code but it should work.

cicciocb
Post Reply