Page 2 of 3

Re: Read MAX6675 with ESP8266

Posted: Tue May 25, 2021 1:41 pm
by cicciocb
HI mezjoc,
please let us know if this code was successful for you.

cicciocb

Re: Read MAX6675 with ESP8266

Posted: Tue May 25, 2021 3:21 pm
by mezjoc
Dear cicciocb!
The program works perfectly. I just do not understand how? I tested up to about 400 ° C. I couldn't measure the accuracy. Thank you very much for your help: mezjoc

Code: [Local Link Removed for Guests]

'/program/spi_max6675_2.bas
spi.setup 1000000,0,1    'bit/sec, 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 2000,mytimer
wait

mytimer:
i=i+1
pin(16) = 0    'CS=LOW
v0 = spi.byte(0)          '0000 0000 0011=3D
v1 = v0 << 8              '0011 0000 0000=768D
v2 = v1 or spi.byte(0)    '0011 0000 0011=771D ???
pin(16) = 1    'CS=HIGH

if (v2 and &h4) then    '
  wlog "no thermocouple attached!"
else
  v3 = v2 >> 3
  wlog i;".",v0,v1,v2,v3,"Temperature "; v3 * 0.25 ; "°C"
end if
return

Re: Read MAX6675 with ESP8266

Posted: Tue May 25, 2021 4:43 pm
by mezjoc
Dear cicciocb!
Here are the wlog values (at room temperature). I'm trying to decipher: mezjoc

Code: [Local Link Removed for Guests]

1.    3    768    784    98    Temperature 24.5°C
2.    3    768    776    97    Temperature 24.25°C
3.    3    768    768    96    Temperature 24°C
4.    3    768    792    99    Temperature 24.75°C
5.    2    512    760    95    Temperature 23.75°C
6.    3    768    776    97    Temperature 24.25°C
7.    3    768    768    96    Temperature 24°C
8.    3    768    776    97    Temperature 24.25°C
9.    3    768    784    98    Temperature 24.5°C
10.    3    768    776    97    Temperature 24.25°C
11.    3    768    776    97    Temperature 24.25°C
12.    3    768    768    96    Temperature 24°C
13.    3    768    792    99    Temperature 24.75°C
14.    3    768    792    99    Temperature 24.75°C
15.    2    512    760    95    Temperature 23.75°C
16.    3    768    776    97    Temperature 24.25°C
17.    3    768    776    97    Temperature 24.25°C
18.    2    512    760    95    Temperature 23.75°C
19.    3    768    768    96    Temperature 24°C
20.    3    768    776    97    Temperature 24.25°C
21.    3    768    784    98    Temperature 24.5°C
22.    3    768    784    98    Temperature 24.5°C
23.    3    768    768    96    Temperature 24°C
24.    3    768    776    97    Temperature 24.25°C
25.    3    768    768    96    Temperature 24°C
26.    3    768    784    98    Temperature 24.5°C
27.    3    768    776    97    Temperature 24.25°C
28.    3    768    776    97    Temperature 24.25°C
29.    3    768    768    96    Temperature 24°C
30.    3    768    776    97    Temperature 24.25°C

Re: Read MAX6675 with ESP8266

Posted: Tue May 25, 2021 4:55 pm
by cicciocb
What do you need to decipher ? :D

If you look at the datasheet https://datasheets.maximintegrated.com/ ... AX6675.pdf

In particular at the page containing the output format
image.png
You can see that the output contains 16 bits (2 bytes) and that the whole must be shifted right of 3 bits to obtain the 12 bits reading.

this code

Code: [Local Link Removed for Guests]

v0 = spi.byte(0)
v1 = v0 << 8  
v2 = v1 or spi.byte(0)  
simply read the 2 bytes shifting the first one of 8 bits to the left to compose a 16 bits number.

As the resolution is 0.25°C, the value is simply multiplied by 0.25

Re: Read MAX6675 with ESP8266

Posted: Wed May 26, 2021 7:57 am
by mezjoc
Dear CiccioCB!
I don't want to waste your time.
The value of spi.byte (0) is the same for both inputs (line 14, line 16). Value = 3D = 0000 0011B. Why does the value of v2 change? (768D ... 784D)?
Other!
Line 20 is never active.
Regards: mezjoc

Re: Read MAX6675 with ESP8266

Posted: Wed May 26, 2021 9:09 am
by bugs
Hi mezjoc,

Excuse me butting in but maybe this can help.
There are 16 bits sent by the device.
Line 16 reads the second 8 bits
v2 = v1 or spi.byte(0)
so spibyte(0) is a different value to v0

Re: Read MAX6675 with ESP8266

Posted: Wed May 26, 2021 10:46 am
by mezjoc
Which is accurate?
Heat blower vs ESP8266?
Image

Re: Read MAX6675 with ESP8266

Posted: Wed May 26, 2021 11:05 am
by Electroguard
Ha... 552.25

Be interesting to to see how 2 thermocouples might compare at the same time.

Re: Read MAX6675 with ESP8266

Posted: Wed May 26, 2021 11:33 am
by cicciocb
The datasheet says that the accuracy is 8LSB (that is 8*0.25 = 2°C)
image.png

Re: Read MAX6675 with ESP8266

Posted: Thu May 27, 2021 8:45 am
by mezjoc
I AM 70 YEARS OLD. I am very glad to be a member of the forum.
Mezei József (mezjoc) / Hungary. :D