Skip to content

Commit c3c0f31

Browse files
committed
0.3.3 MAX6675
1 parent 7d9b1db commit c3c0f31

File tree

14 files changed

+100
-53
lines changed

14 files changed

+100
-53
lines changed

libraries/MAX6675/CHANGELOG.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,15 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/)
66
and this project adheres to [Semantic Versioning](http://semver.org/).
77

88

9+
## [0.3.3] - 2025-03-17
10+
- add getCelsius() to replace getTemperature() in long term.
11+
- add getFahrenheit() convenience wrapper.
12+
- update examples
13+
- update readme.md
14+
- update unit test
15+
- update keywords
16+
17+
918
## [0.3.2] - 2024-06-03
1019
- add support for ARDUINO_ARCH_MBED
1120

libraries/MAX6675/LICENSE

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
MIT License
22

3-
Copyright (c) 2022-2024 Rob Tillaart
3+
Copyright (c) 2022-2025 Rob Tillaart
44

55
Permission is hereby granted, free of charge, to any person obtaining a copy
66
of this software and associated documentation files (the "Software"), to deal

libraries/MAX6675/MAX6675.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
//
22
// FILE: MAX6675.cpp
33
// AUTHOR: Rob Tillaart
4-
// VERSION: 0.3.2
4+
// VERSION: 0.3.3
55
// PURPOSE: Arduino library for MAX6675 chip for K type thermocouple
66
// DATE: 2022-01-11
77
// URL: https://github.com/RobTillaart/MAX6675

libraries/MAX6675/MAX6675.h

Lines changed: 7 additions & 3 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.3.2
5+
// VERSION: 0.3.3
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.3.2"))
26+
#define MAX6675_LIB_VERSION (F("0.3.3"))
2727

2828

2929
#ifndef __SPI_CLASS__
@@ -67,11 +67,13 @@ class MAX6675
6767

6868
// returns state - bit field: 0 = STATUS_OK
6969
uint8_t read();
70-
float getTemperature(void) { return _temperature + _offset; };
70+
float getCelsius(void) { return _temperature + _offset; };
71+
float getFahrenheit(void) { return getCelsius() * 1.8 + 32; };
7172

7273
uint8_t getStatus(void) const { return _status; };
7374

7475
// use offset to calibrate the TC.
76+
// offset is in degrees Celsius.
7577
void setOffset(const float t) { _offset = t; };
7678
float getOffset() const { return _offset; };
7779

@@ -84,6 +86,8 @@ class MAX6675
8486
void setSWSPIdelay(uint16_t del = 0) { _swSPIdelay = del; };
8587
uint16_t getSWSPIdelay() { return _swSPIdelay; };
8688

89+
// obsolete in future.
90+
float getTemperature(void) { return _temperature + _offset; };
8791

8892
private:
8993
uint32_t _read();

libraries/MAX6675/README.md

Lines changed: 48 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ The library is based upon (stripped and adapted version of) the https://github.c
1717

1818
Currently the library is experimental, so use with care.
1919

20-
Hardware has finally arrived (April 2022) and I had time to do my first round of tests with an UNO @ 16 MHz.
20+
Hardware has finally arrived (April 2022) and I had time to do my first round of tests with an UNO at 16 MHz.
2121
The library works and it reads temperatures well, both with HW SPI and SW SPI.
2222

2323

@@ -34,7 +34,7 @@ Different TC's have a different Seebeck Coefficient (SC) expressed in µV/°C.
3434
See http://www.analog.com/library/analogDialogue/archives/44-10/thermocouple.html
3535

3636

37-
#### Breakout
37+
### Breakout
3838

3939
The library is tested with a breakout board with following pins:
4040

@@ -49,14 +49,14 @@ The library is tested with a breakout board with following pins:
4949
```
5050

5151

52-
#### 0.3.0 Breaking change
52+
### 0.3.0 Breaking change
5353

5454
Version 0.3.0 introduced a breaking change to improve handling the SPI dependency.
5555
The user has to call **SPI.begin()** or equivalent before calling **AD.begin()**.
5656
Optionally the user can provide parameters to the **SPI.begin(...)**
5757

5858

59-
#### 0.2.0 Breaking change
59+
### 0.2.0 Breaking change
6060

6161
The version 0.2.0 has breaking changes in the interface.
6262
The essence is removal of ESP32 specific code from the library.
@@ -66,17 +66,18 @@ Also it makes the library a bit simpler to maintain.
6666
Note the order of the parameters of the software SPI constructor has changed in 0.2.0.
6767

6868

69-
#### Related
69+
### Related
7070

71-
- https://github.com/RobTillaart/MAX6675
71+
- https://github.com/RobTillaart/MAX6675
7272
- https://github.com/RobTillaart/MAX31850
7373
- https://github.com/RobTillaart/MAX31855_RT
74+
- https://github.com/RobTillaart/Temperature conversion to (exotic) temperature scales.
7475

7576

7677
## Hardware SPI vs software SPI
7778

7879

79-
#### Pins
80+
### Pins
8081

8182
Default pin connections.
8283

@@ -88,7 +89,7 @@ Default pin connections.
8889
| SELECT | eg. 4 | 5 | 15 | *can be others too.*
8990

9091

91-
#### Performance
92+
### Performance
9293

9394
Performance read() function, timing in us.
9495
- UNO @ 16 MHz
@@ -117,15 +118,15 @@ Tested with **MAX6675_test_HWSPI.ino**
117118
#include "MAX6675.h"
118119
```
119120

120-
#### Constructor
121+
### Constructor
121122

122123
- **MAX6675(uint8_t select, SPIClassRP2040 \* mySPI)** hardware SPI R2040
123124
- **MAX6675(uint8_t select, SPIClass \* mySPI)** hardware SPI other
124125
- **MAX6675(uint8_t select, uint8_t miso, uint8_t clock)** software SPI
125126
- **void begin()** initialize internals
126127

127128

128-
#### Hardware SPI
129+
### Hardware SPI
129130

130131
To be used only if one needs a specific speed.
131132

@@ -136,63 +137,73 @@ Del is the time in micros added per bit. Even numbers keep the duty cycle of the
136137
- **uint16_t getSWSPIdelay()** get set value in micros.
137138

138139

139-
#### Reading
140+
### Measurements
141+
142+
- **uint8_t read()** makes a temperature measurement.
143+
It returns the status of the read (0, 4 or 129)
144+
- **uint8_t getStatus()** returns the last status value of read().
145+
Will stay the same until a new **read()** call.
146+
- **float getTemperature()** returns last temperature in Celsius. (will be obsolete in future).
147+
- **float getCelsius()** returns last temperature in Celsius. (more explicit scale).
148+
Will stay the same until a new **read()** call.
149+
- **float getFahrenheit()** wrapper around getCelsius(). Returns last temperature in Fahrenheit.
150+
Will stay the same until a new **read()** call.
140151

141-
To make a temperature reading call **read()**.
142-
It returns the status of the read which is a value between 0..7
143-
The function **getStatus()** returns the same status value.
144152

145153
Table: values returned from **uint8_t read()** and **uint8_t getStatus()**
146154

147155
Note: this list is a subset of MAX31855 errors.
148156

149-
| value | Description | Action |
150-
|:-----:|:--------------------------|:-------------|
151-
| 0 | OK | |
152-
| 4 | Thermocouple short to VCC | check wiring |
153-
| 128 | No read done yet | check wiring |
154-
| 129 | No communication | check wiring |
157+
| Define | value | Description | Action | Notes |
158+
|:--------------------------|:-------:|:----------------------------|:---------------|:--------|
159+
| STATUS_OK | 0 | OK | |
160+
| STATUS_ERROR | 4 | Thermocouple short to VCC | check wiring |
161+
| STATUS_NOREAD | 128 | No read done yet | check wiring | only before first read()
162+
| STATUS_NO_COMMUNICATION | 129 | No communication | check wiring |
163+
155164

165+
After **uint8_t read()** returns **STATUS_OK** you can get the temperature with
166+
**getCelsius()** or **getFahrenheit()**.
156167

157-
After a **uint8_t read()** you can get the temperature with **float getTemperature()**.
168+
Repeated calls to **getCelsius()** or **getFahrenheit()** will give the same value until a new
169+
measurement is made by calling **read()**.
158170

159-
Repeated calls to **getTemperature()** will give the same value until a new **read()**.
160-
The latter fetches a new value from the sensor. Note that if the **read()** fails
161-
the value of **getTemperature()** can become incorrect. So it is important to check
162-
the return value of **read()**.
171+
Note: if the **read()** fails the value of **getCelsius()** can become incorrect.
172+
So it is important to check the return value of **read()**.
163173

164174

165-
#### Offset
175+
### Offset
166176

167177
The library supports a fixed offset to calibrate the thermocouple.
168178
For this the functions **float getOffset()** and **void setOffset(float offset)** are available.
169-
This offset is "added" in the **getTemperature()** function.
179+
This offset is "added" in the **getCelsius()** function.
170180

171-
Notes
172-
- the offset can be positive or negative.
181+
Note:
182+
- the offset is a constant in degrees Celsius (for Fahrenheit offset multiply by 1.8)
173183
- the offset used is a float, so decimals can be used.
174-
A typical usage is to call **setOffset(273.15)** to get ° Kelvin.
175-
- the offset can cause negative temperatures.
184+
A typical usage is to call **setOffset(273.15)** to get degrees ° Kelvin.
185+
- the offset can be positive or negative.
186+
- the offset can cause negative temperatures to pop up at the lower end.
176187

177188

178-
#### Delta analysis
189+
### Delta analysis
179190

180191
As the **tc** object holds its last known temperature it is easy to determine the delta
181192
with the last known temperature, e.g. for trend analysis.
182193

183194
```cpp
184-
float last = tc.getTemperature();
195+
float last = tc.getCelsius();
185196
int state = tc.read();
186197
if (state == STATUS_OK)
187198
{
188-
float new = tc.getTemperature();
199+
float new = tc.getCelsius();
189200
float delta = new - last;
190201
// process data
191202
}
192203
```
193204
194205
195-
#### Last time read
206+
### Last time read
196207
197208
The **tc** object keeps track of the last time **read()** is called in the function **uint32_t lastRead()**.
198209
The time is tracked in **millis()**. This makes it easy to read the sensor at certain intervals.
@@ -203,7 +214,7 @@ if (millis() - tc.lastRead() >= interval)
203214
int state = tc.read();
204215
if (state == STATUS_OK)
205216
{
206-
float new = tc.getTemperature();
217+
float new = tc.getCelsius();
207218
// process read value.
208219
}
209220
else
@@ -214,7 +225,7 @@ if (millis() - tc.lastRead() >= interval)
214225
```
215226

216227

217-
#### GetRawData
228+
### GetRawData
218229

219230
The function **uint32_t getRawData()** allows you to get all the 32 bits raw data from the board,
220231
after the standard **uint8_t tc.read()** call.

libraries/MAX6675/examples/Demo_getRawData/Demo_getRawData.ino

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ MAX6675 thermoCouple(selectPin, dataPin, clockPin);
1818

1919
void setup ()
2020
{
21+
// while(!Serial);
2122
Serial.begin(115200);
2223
Serial.println(__FILE__);
2324
Serial.print("MAX6675_LIB_VERSION: ");
@@ -43,8 +44,8 @@ void loop ()
4344
Serial.print("RAW:\t");
4445

4546
// Display the raw data value in BIN format
46-
uint32_t mask = 0x80000000;
47-
for (int i = 0; i < 32; i++)
47+
uint32_t mask = 0x80000000;
48+
for (int i = 0; i < 32; i++)
4849
{
4950
if ((i > 0) && (i % 4 == 0)) Serial.print("-");
5051
Serial.print((value & mask) ? 1 : 0);
@@ -53,7 +54,7 @@ void loop ()
5354
Serial.println();
5455

5556
Serial.print("TMP:\t");
56-
Serial.println(thermoCouple.getTemperature(), 3);
57+
Serial.println(thermoCouple.getCelsius(), 3);
5758

5859
delay(100);
5960
}

libraries/MAX6675/examples/MAX6675_array/MAX6675_array.ino

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ uint32_t start, stop;
2222

2323
void setup()
2424
{
25+
// while(!Serial);
2526
Serial.begin(115200);
2627
Serial.println(__FILE__);
2728
Serial.print("MAX6675_LIB_VERSION: ");
@@ -48,7 +49,7 @@ void loop()
4849
start = micros();
4950
int status = ThermoCouples[THCnumber].read();
5051
stop = micros();
51-
float temp = ThermoCouples[THCnumber].getTemperature();
52+
float temp = ThermoCouples[THCnumber].getCelsius();
5253

5354
Serial.print(millis());
5455
Serial.print("\tID: ");

libraries/MAX6675/examples/MAX6675_test/MAX6675_test.ino

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ uint32_t start, stop;
2020

2121
void setup()
2222
{
23+
// while(!Serial);
2324
Serial.begin(115200);
2425
Serial.println(__FILE__);
2526
Serial.print("MAX6675_LIB_VERSION: ");
@@ -40,13 +41,15 @@ void loop()
4041
start = micros();
4142
int status = thermoCouple.read();
4243
stop = micros();
43-
float temp = thermoCouple.getTemperature();
44+
float temp = thermoCouple.getCelsius();
4445

4546
Serial.print(millis());
4647
Serial.print("\tstatus: ");
4748
Serial.print(status);
4849
Serial.print("\ttemp: ");
4950
Serial.print(temp);
51+
Serial.print("\traw: ");
52+
Serial.print(thermoCouple.getRawData(), HEX);
5053
Serial.print("\tus: ");
5154
Serial.println(stop - start);
5255

libraries/MAX6675/examples/MAX6675_test_HWSPI/MAX6675_test_HWSPI.ino

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ uint32_t start, stop;
1717

1818
void setup()
1919
{
20+
// while(!Serial);
2021
Serial.begin(115200);
2122
Serial.println(__FILE__);
2223
Serial.print("MAX6675_LIB_VERSION: ");
@@ -48,7 +49,7 @@ void testPerformance(uint32_t speed)
4849
start = micros();
4950
int status = thermoCouple.read();
5051
stop = micros();
51-
float temp = thermoCouple.getTemperature();
52+
float temp = thermoCouple.getCelsius();
5253

5354
Serial.print(millis());
5455
Serial.print("\tspeed: ");

libraries/MAX6675/examples/MAX6675_test_plotter/MAX6675_test_plotter.ino

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ float temp = 0;
2222

2323
void setup()
2424
{
25+
// while(!Serial);
2526
Serial.begin(115200);
2627
// Serial.println(__FILE__);
2728
// Serial.print("MAX6675_LIB_VERSION: ");
@@ -38,7 +39,7 @@ void setup()
3839

3940
int status = thermoCouple.read();
4041
if (status != 0) Serial.println(status);
41-
temp = thermoCouple.getTemperature();
42+
temp = thermoCouple.getCelsius();
4243
}
4344

4445

@@ -49,7 +50,7 @@ void loop()
4950
int status = thermoCouple.read();
5051
stop = micros();
5152

52-
float newValue = thermoCouple.getTemperature();
53+
float newValue = thermoCouple.getCelsius();
5354
// 0.2 is low pass filter
5455
temp += 0.2 * (newValue - temp);
5556
// temp = newValue;

libraries/MAX6675/keywords.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,10 @@ MAX6675 KEYWORD1
88
# Methods and Functions (KEYWORD2)
99
begin KEYWORD2
1010
read KEYWORD2
11+
1112
getTemperature KEYWORD2
13+
getCelsius KEYWORD2
14+
getFahrenheit KEYWORD2
1215

1316
getStatus KEYWORD2
1417

0 commit comments

Comments
 (0)