Skip to content

Commit a64bac8

Browse files
authored
Merge pull request #2 from RobTillaart/develop
update documentation, add examples
2 parents 9dc57f8 + 9a82200 commit a64bac8

File tree

7 files changed

+198
-44
lines changed

7 files changed

+198
-44
lines changed

MAX6675.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,15 @@
11
//
22
// FILE: MAX6675.cpp
33
// AUTHOR: Rob Tillaart
4-
// VERSION: 0.1.0
4+
// VERSION: 0.1.1
55
// PURPOSE: Arduino library for MAX6675 chip for K type thermocouple
66
// DATE: 2022-01-11
77
// URL: https://github.com/RobTillaart/MAX6675
88
//
99
// HISTORY:
1010
// 0.1.0 2022-01-11 initial version.
11-
//
11+
// 0.1.1 2022-04-20 updated documentation after tests with UNO.
12+
// added examples.
1213

1314

1415
#include "MAX6675.h"

MAX6675.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
//
33
// FILE: MAX6675.h
44
// AUTHOR: Rob Tillaart
5-
// VERSION: 0.1.0
5+
// VERSION: 0.1.1
66
// PURPOSE: Arduino library for MAX6675 chip for K type thermocouple
77
// DATE: 2022-01-12
88
// URL: https://github.com/RobTillaart/MAX6675
@@ -23,7 +23,7 @@
2323
#include "SPI.h"
2424

2525

26-
#define MAX6675_LIB_VERSION (F("0.1.0"))
26+
#define MAX6675_LIB_VERSION (F("0.1.1"))
2727

2828
#define MAX6675_NO_TEMPERATURE -999
2929

@@ -55,9 +55,9 @@ class MAX6675
5555

5656
// returns state - bit field: 0 = STATUS_OK
5757
uint8_t read();
58-
float getTemperature(void) { return _temperature + _offset; };
58+
float getTemperature(void) { return _temperature + _offset; };
5959

60-
uint8_t getStatus(void) const { return _status; };
60+
uint8_t getStatus(void) const { return _status; };
6161

6262
// use offset to calibrate the TC.
6363
void setOffset(const float t) { _offset = t; };

README.md

Lines changed: 58 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -8,50 +8,79 @@
88

99
# MAX6675
1010

11-
Arduino library for MAX6675 chip for K type thermocouple.
11+
Max6675 is an Arduino library for MAX6675 chip with a K type thermocouple.
1212

1313
The library is based upon (stripped and adapted version of) the https://github.com/RobTillaart/MAX31855_RT library.
1414

15-
Experimental as not tested with hardware yet.
15+
Currently the library is experimental, so use with care.
16+
17+
Hardware has finally arrived (April 2022) and I had time to do my first round of tests with an UNO @ 16 MHz. The library works and it reads temperatures well, both with HW SPI and SW SPI.
18+
1619

1720
## Description
1821

19-
The MAX6675 is a chip to convert the reading of a K-type thermocouple to a temperature. The MAX6675 only supports positive degrees Celsius.
22+
The MAX6675 is a chip to convert the reading of a K-type thermocouple to a temperature.
23+
The MAX6675 only supports positive degrees Celsius.
24+
25+
The values are read with an precision of **0.25°C.**
26+
Typical noise seen during usage are **± 0.5°C**, so using a low pass filter on the temperature might be a good idea.
2027

2128
The working of thermocouples (TC) is based upon Seebeck effect.
22-
Different TC's have a different Seebeck Coefficient (SC) expressed in µV/°C.
29+
Different TC's have a different Seebeck Coefficient (SC) expressed in µV/°C.
2330
See http://www.analog.com/library/analogDialogue/archives/44-10/thermocouple.html
2431

25-
Library tested with breakout board -
2632

27-
```
28-
TODO
33+
### Breakout
34+
35+
The library is tested with a breakout board with following pins:
2936

37+
```
38+
+---------------------+
39+
| signal out | --> MISO
40+
| - chip select | <-- SELECT
41+
TC here | clock | <-- CLOCK processor side
42+
| + VCC | --- VCC
43+
| GND | --- GND
44+
+---------------------+
3045
```
3146

3247

3348
## Hardware SPI vs software SPI
3449

50+
51+
### Pins
52+
3553
Default pin connections. ESP32 can overrule with **setGPIOpins()**.
3654

3755
| HW SPI | UNO | ESP32 VSPI | ESP32 HSPI | Notes
3856
|:---------|:-----:|:-----------:|:-----------:|:----------|
39-
| CLOCKPIN | 13 | 18 | 14 |
40-
| MISO | 12 | 19 | 12 |
41-
| MOSI | 11 | 23 | 13 | *not used...*
57+
| CLOCK | 13 | 18 | 14 |
58+
| MISO | 12 | 19 | 12 |
59+
| MOSI | 11 | 23 | 13 | *not used...*
4260
| SELECT | eg. 4 | 5 | 15 | *can be others too.*
4361

4462

45-
Performance read() function, timing in us. (TODO ESP32 @240MHz)
63+
### Performance
64+
65+
Performance read() function, timing in us.
66+
- UNO @ 16 MHz
67+
- TODO ESP32 @ 240 MHz
4668

47-
| mode | clock | timing UNO | timing ESP32 | Notes
69+
| mode | clock | timing UNO | timing ESP32 | Notes
4870
|:-------|---------:|-----------:|-------------:|:----------|
49-
| HW SPI | 4000000 | ~32 | | highest supported.
50-
| HW SPI | 2000000 | ~36 | |
51-
| HW SPI | 1000000 | ~44 | |
52-
| HW SPI | 500000 | ~60 | |
53-
| SW SPI | bit bang | ~276 | |
71+
| HW SPI | 4000000 | 36 | | highest supported.
72+
| HW SPI | 3500000 | 40 | |
73+
| HW SPI | 3000000 | 40 | |
74+
| HW SPI | 2500000 | 40 | |
75+
| HW SPI | 2000000 | 40-44 | |
76+
| HW SPI | 1500000 | 48 | |
77+
| HW SPI | 1000000 | 48-52 | |
78+
| HW SPI | 500000 | 64-68 | |
79+
| SW SPI | bit bang | 276 | |
5480

81+
Note the UNO micros() has a 4 us precision, but it is clear that
82+
4 Mb is not even twice the speed of 0.5 Mb.
83+
Tested with **MAX6675_test_HWSPI.ino**
5584

5685

5786
## Interface
@@ -61,7 +90,8 @@ Performance read() function, timing in us. (TODO ESP32 @240MHz)
6190

6291
- **MAX6675()** create object.
6392
- **void begin(const uint8_t select)** set select pin => hardware SPI
64-
- **void begin(const uint8_t sclk, const uint8_t select, const uint8_t miso)** set clock, select and miso pin => software SPI
93+
- **void begin(const uint8_t sclk, const uint8_t select, const uint8_t miso)**
94+
set CLOCK, SELECT and MISO pin => software SPI
6595

6696

6797
### Hardware SPI
@@ -70,7 +100,8 @@ To be used only if one needs a specific speed.
70100

71101
- **void setSPIspeed(uint32_t speed)** set SPI transfer rate.
72102
- **uint32_t getSPIspeed()** returns SPI transfer rate.
73-
- **void setSWSPIdelay(uint16_t del = 0)** for tuning SW SPI signal quality. Del is the time in micros added per bit. Even numbers keep the duty cycle of the clock around 50%.
103+
- **void setSWSPIdelay(uint16_t del = 0)** for tuning SW SPI signal quality.
104+
Del is the time in micros added per bit. Even numbers keep the duty cycle of the clock around 50%.
74105
- **uint16_t getSWSPIdelay()** get set value in micros.
75106

76107

@@ -91,29 +122,17 @@ The function **getStatus()** returns the same status value.
91122

92123
Table: values returned from **uint8_t read()** and **uint8_t getStatus()**
93124

125+
Note: this list is a subset of MAX31855 errors.
126+
94127
| value | Description | Action |
95128
|:-----:|:--------------------------|:-------------|
96129
| 0 | OK | |
97-
| 1 | Thermocouple open circuit | check wiring |
98-
| 2 | Thermocouple short to GND | check wiring |
99130
| 4 | Thermocouple short to VCC | check wiring |
100-
| 7 | Generic error | |
101131
| 128 | No read done yet | check wiring |
102132
| 129 | No communication | check wiring |
103133

104-
There are six functions to check the individual error conditions mentioned above.
105-
These make it easier to check them.
106-
107-
- **bool openCircuit()**
108-
- **bool shortToGND()**
109-
- **bool shortToVCC()**
110-
- **bool genericError()**
111-
- **bool noRead()**
112-
- **bool noCommunication()**
113134

114-
After a **uint8_t read()** you can get the temperature with **float getTemperature()**
115-
and **float getInternal()** for the internal temperature of the chip / board itself.
116-
Normally these are (almost) equal.
135+
After a **uint8_t read()** you can get the temperature with **float getTemperature()**.
117136

118137
Repeated calls to **getTemperature()** will give the same value until a new **read()**.
119138
The latter fetches a new value from the sensor. Note that if the **read()** fails
@@ -127,7 +146,10 @@ The library supports a fixed offset to calibrate the thermocouple.
127146
For this the functions **float getOffset()** and **void setOffset(float offset)** are available.
128147
This offset is "added" in the **getTemperature()** function.
129148

130-
Note the offset used is a float, so decimals can be used.
149+
Notes
150+
- the offset used is a float, so decimals can be used.
151+
A typical usage is to call **setOffset(273.15)** to get ° Kelvin.
152+
- the offset can cause negative temperatures.
131153

132154

133155
### Delta analysis
@@ -188,7 +210,7 @@ This allows one to compact the measurement e.g. for storage or sending over a ne
188210

189211
To have proper working of the MAX6675 board, you need to add a pull-up resistor
190212
(e.g. 4K7 - 1K depending on wire length) between the MISO pin (from constructor call) and the
191-
VCC (5Volt). This improves the signal quality and will allow you to detect if there is
213+
VCC (5 Volt). This improves the signal quality and will allow you to detect if there is
192214
proper communication with the board. Without pull-up one might get random noise that could
193215
look like real data.
194216

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
//
2+
// FILE: MAX6675_test_HWSPI.ino
3+
// AUTHOR: Rob Tillaart
4+
// PURPOSE: demo
5+
// DATE: 2022-01-12
6+
// URL: https://github.com/RobTillaart/MAX6675
7+
8+
9+
#include "MAX6675.h"
10+
11+
const int selectPin = 5;
12+
13+
MAX6675 thermoCouple;
14+
15+
uint32_t start, stop;
16+
17+
18+
void setup()
19+
{
20+
Serial.begin(115200);
21+
Serial.println(__FILE__);
22+
Serial.println(MAX6675_LIB_VERSION);
23+
Serial.println();
24+
25+
thermoCouple.begin(selectPin); // HW SPI
26+
27+
28+
}
29+
30+
31+
void loop()
32+
{
33+
for (uint32_t s = 500; s < 4500; s += 500)
34+
{
35+
testPerformance(s * 1000);
36+
delay(500);
37+
}
38+
Serial.println();
39+
}
40+
41+
42+
void testPerformance(uint32_t speed)
43+
{
44+
thermoCouple.setSPIspeed(speed);
45+
46+
start = micros();
47+
int status = thermoCouple.read();
48+
stop = micros();
49+
float temp = thermoCouple.getTemperature();
50+
51+
Serial.print(millis());
52+
Serial.print("\tspeed: ");
53+
Serial.print(speed / 1000);
54+
Serial.print("\tstatus: ");
55+
Serial.print(status);
56+
Serial.print("\ttemp: ");
57+
Serial.print(temp);
58+
Serial.print("\tus: ");
59+
Serial.println(stop - start);
60+
delay(100);
61+
}
62+
63+
64+
65+
66+
67+
// -- END OF FILE --
Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
//
2+
// FILE: MAX6675_test_plotter.ino
3+
// AUTHOR: Rob Tillaart
4+
// PURPOSE: demo
5+
// DATE: 2022-04-20
6+
// URL: https://github.com/RobTillaart/MAX6675
7+
8+
9+
#include "MAX6675.h"
10+
11+
// note: pins are slightly different than other examples!
12+
const int dataPin = 7;
13+
const int clockPin = 6;
14+
const int selectPin = 5;
15+
16+
17+
MAX6675 thermoCouple;
18+
19+
uint32_t start, stop;
20+
21+
float temp = 0;
22+
23+
void setup()
24+
{
25+
Serial.begin(115200);
26+
// Serial.println(__FILE__);
27+
// Serial.println(MAX6675_LIB_VERSION);
28+
// Serial.println();
29+
30+
// thermoCouple.begin(clockPin, selectPin, dataPin);
31+
thermoCouple.begin(selectPin); // HW SPI
32+
33+
thermoCouple.setSPIspeed(4000000);
34+
thermoCouple.setOffset(273);
35+
36+
int status = thermoCouple.read();
37+
temp = thermoCouple.getTemperature();
38+
}
39+
40+
41+
void loop()
42+
{
43+
delay(100);
44+
start = micros();
45+
int status = thermoCouple.read();
46+
stop = micros();
47+
48+
float newValue = thermoCouple.getTemperature();
49+
// 0.2 is low pass filter
50+
temp += 0.2 * (newValue - temp);
51+
// temp = newValue;
52+
53+
Serial.print(status);
54+
Serial.print("\t");
55+
Serial.print(temp);
56+
// Serial.print("\t");
57+
// Serial.print(stop - start);
58+
Serial.println();
59+
60+
delay(100);
61+
}
62+
63+
64+
// -- END OF FILE --

library.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
"type": "git",
1616
"url": "https://github.com/RobTillaart/MAX6675"
1717
},
18-
"version": "0.1.0",
18+
"version": "0.1.1",
1919
"license": "MIT",
2020
"frameworks": "arduino",
2121
"platforms": "*",

library.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
name=MAX6675
2-
version=0.1.0
2+
version=0.1.1
33
author=Rob Tillaart <rob.tillaart@gmail.com>
44
maintainer=Rob Tillaart <rob.tillaart@gmail.com>
55
sentence=Arduino library for MAX6675 chip for K type thermocouple.

0 commit comments

Comments
 (0)