Skip to content

Commit

Permalink
add setTypeTC() and more
Browse files Browse the repository at this point in the history
  • Loading branch information
RobTillaart committed Jan 23, 2023
1 parent f750950 commit 43e153b
Show file tree
Hide file tree
Showing 11 changed files with 193 additions and 118 deletions.
13 changes: 11 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,18 +1,27 @@
# Change Log MAX44009
# Change Log MAX31850

All notable changes to this project will be documented in this file.

The format is based on [Keep a Changelog](http://keepachangelog.com/)
and this project adheres to [Semantic Versioning](http://semver.org/).


## [0.1.2] - 2023-01-23
- update GitHub actions
- update license 2023
- add setTypeTC() + getTypeTC()
- update keywords.txt
- update readme.md
- add retries parameter to **begin()**
- minor edits.


## [0.1.1] - 2022-11-16
- add RP2040 in build-CI
- add changelog.md
- major rewrite based on reread of datasheet.
- initial release(?)


## [0.1.0] - 2021-06-03
- initial version (not released)

2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
MIT License

Copyright (c) 2021-2021 Rob Tillaart
Copyright (c) 2021-2023 Rob Tillaart

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand Down
68 changes: 34 additions & 34 deletions MAX31850.cpp
Original file line number Diff line number Diff line change
@@ -1,20 +1,18 @@
//
// FILE: MAX31850.cpp
// AUTHOR: Rob.Tillaart@gmail.com
// VERSION: 0.1.1
// VERSION: 0.1.2
// DATE: 2021-06-03
// PUPROSE: Arduino library for the MAX31850 thermocouple temperature sensor.
//
// HISTORY: see changelog.md


#include "MAX31850.h"


// OneWire commands
#define STARTCONVO 0x44
#define READSCRATCH 0xBE
#define WRITESCRATCH 0x4E
#define STARTCONVO 0x44
#define READSCRATCH 0xBE
#define WRITESCRATCH 0x4E


// SCRATCHPAD registers
Expand All @@ -27,7 +25,7 @@
#define INTERN_TEMP_MSB 3

// 4 address bits 0..15
#define CONFIGURATION 4
#define CONFIGURATION 4
#define RESERVED_1 5
#define RESERVED_2 6
#define RESERVED_3 7
Expand All @@ -42,6 +40,7 @@ MAX31850::MAX31850(OneWire* oneWire)
{
_oneWire = oneWire;
_addresFound = false;
_typeTC = 'K'; // most used.
_TCTemp = 0;
_internalTemp = 0;
_errorBits = 0;
Expand All @@ -50,10 +49,10 @@ MAX31850::MAX31850(OneWire* oneWire)
}


bool MAX31850::begin(void)
bool MAX31850::begin(uint8_t retries)
{
_addresFound = false;
for (uint8_t retries = 3; (retries > 0) && (_addresFound == false); retries--)
for (uint8_t r = retries; (r > 0) && (_addresFound == false); r--)
{
_oneWire->reset();
_oneWire->reset_search();
Expand Down Expand Up @@ -139,31 +138,30 @@ uint8_t MAX31850::getAddressPins()
};


// bool MAX31850::setType(char typeTC)
// {
// switch(typeTC)
// {
// case 'E':
// case 'J':
// case 'K':
// case 'N':
// case 'R':
// case 'S':
// case 'T':
// _typeTC = typeTC;
// return true;
// }
// return false;
// }
//
//
// char MAX31850::getType()
// {
// return _typeTC;
// }



bool MAX31850::setTypeTC(char typeTC)
{
switch(toupper(typeTC))
{
case 'E':
case 'J':
case 'K':
case 'N':
case 'R':
case 'S':
case 'T':
_typeTC = toupper(typeTC);
return true;
}
return false;
}


char MAX31850::getTypeTC()
{
return _typeTC;
}


/////////////////////////////////////////////////////////////////////////////
//
// PROTECTED
Expand Down Expand Up @@ -191,4 +189,6 @@ MAX31851::MAX31851(OneWire * onewire) : MAX31850(onewire)
{
}


// -- END OF FILE --

13 changes: 8 additions & 5 deletions MAX31850.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,12 @@
//
// FILE: MAX31850.h
// AUTHOR: Rob.Tillaart@gmail.com
// VERSION: 0.1.1
// VERSION: 0.1.2
// DATE: 2021-06-03
// PUPROSE: Arduino library for the MAX31850 thermocouple temperature sensor.
//


#define MAX31850_LIB_VERSION (F("0.1.1"))
#define MAX31850_LIB_VERSION (F("0.1.2"))

#include "Arduino.h"
#include "OneWire.h"
Expand All @@ -30,8 +29,8 @@ class MAX31850
{
public:
explicit MAX31850(OneWire * oneWire);
bool begin(void);
bool getAddress(uint8_t* buffer);
bool begin(uint8_t retries = 3);
bool getAddress(uint8_t * buffer);

void requestTemperatures(void);
bool isConversionComplete(void);
Expand All @@ -46,6 +45,10 @@ class MAX31850
// TODO
uint8_t getAddressPins();

// type is a char from E J K N R S T (lowercase will be converted)
bool setTypeTC(char typeTC = 'K'); // K is most used
char getTypeTC();


protected:
void readScratchPad(uint8_t *, uint8_t);
Expand Down
118 changes: 74 additions & 44 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,12 @@
[![License: MIT](https://img.shields.io/badge/license-MIT-green.svg)](/~https://github.com/RobTillaart/MAX31850/blob/master/LICENSE)
[![GitHub release](https://img.shields.io/github/release/RobTillaart/MAX31850.svg?maxAge=3600)](/~https://github.com/RobTillaart/MAX31850/releases)


# MAX31850

Arduino library for the MAX31850 / MAX31851 thermocouple sensor.


## Description

**WARNING EXPERIMENTAL** needs more testing (no hardware yet).
Expand All @@ -23,13 +25,15 @@ The MAX31850/1 supports K-, J-, N-, T-, S-, R-, and E-type thermocouples. (to be
The library supports both the MAX31850 and MAX31851 but is limited to one sensor per pin.
The only feature the class supports is the asynchronous reading of the temperature.

This allowed the class to be both minimal in size and non-blocking.
In fact the class has no support for a synchronous read in one call.
This allowed the class to be both minimal in size and non-blocking.
In fact the class has no support for a synchronous read in one call.
This choice will teach people how to work in a non-blocking way from the start.

Finally this library will probably make it easier to use a MAX31850 with processing
Finally this library will probably make it easier to use a MAX31850 with processing
boards or IC's with small memory footprint.

The MAX31851 is (for now) functional identical to MAX31850.


## Hardware connection

Expand All @@ -45,68 +49,81 @@ boards or IC's with small memory footprint.
// 4 address pins.
```

This library supports only one MAX31850 per Arduino/ MCU pin.
This library supports only one MAX31850 per Arduino/ MCU IO pin.


### Pull up resistor
#### Pull up resistor

Connect a pull-up resistor 4.7 KOhm between pin3 and pin2.
When the wires are longer this resistor needs to be smaller.
Connect a pull-up resistor 4.7 KOhm between DATA (pin 3) and VCC (pin 2).
When the wires are longer this resistor needs to be smaller.

An **indicative** table for pull up resistors, (E12 series), to get started.

Note: thicker wires require smaller resistors (typically 1 step in E12 series)
Note: thicker wires require smaller resistors (typically 1 step in E12 series)

| Length | - 5.0 Volt | - 3.3 Volt |
|--------------:|------------:|----------:|
| 10cm (4") | 10K0 | 6K8 |
| 20cm (8") | 8K2 | 4K7 |
| 50cm (20") | 4K7 | 3K3 |
| 100cm (3'4") | 3K3 | 2K2 |
| 200cm (6'8") | 2K2 | 1K0 |
| 500cm (16'8") | 1K0 | \* |
| longer | * | \* |
| Length | 5.0 Volt | 3.3 Volt |
|----------------:|-----------:|-----------:|
| 10cm (4") | 10K0 | 6K8 |
| 20cm (8") | 8K2 | 4K7 |
| 50cm (20") | 4K7 | 3K3 |
| 100cm (3'4") | 3K3 | 2K2 |
| 200cm (6'8") | 2K2 | 1K0 |
| 500cm (16'8") | 1K0 | \* |
| longer | \* | \* |

\* = no info, smaller
\* = no info, smaller


## Interface

```cpp
#include "MAX31850.h"
```


#### Constructor

- **explicit MAX31850(OneWire \* oneWire)** constructor.
- **bool begin(void)** initialize the library.
- **bool begin(uint8_t retries = 3)** initialize the library.
Returns true if addresses are found.
Nr of retries can be adjusted if needed, default 3.
- **bool getAddress(uint8_t \* buffer)** get the address if found.


#### Read the sensor
- **void requestTemperatures(void)** idem.
- **bool isConversionComplete(void)** idem.

- **void requestTemperatures(void)** Asynchronous request to start conversion.
- **bool isConversionComplete(void)** CHeck if requested conversion is done.
- **float read(void)** read the data from the sensor.
Returns the temperature of the thermoCouple as this is most often needed.
- **float getTempTC(void)** returns temperature of the ThermoCouple.
One must call **read()** to get new measurements.
- **float getTempInternal(void)** returns internal temperature.
- **float getTempTC(void)** returns temperature of the ThermoCouple from cache.
One must call **read()** again to get new measurements.
- **float getTempInternal(void)** returns internal temperature from cache.
One must call **read()** again to get new measurements.

#### other
- **uint8_t getAddressPins()** ??
- **uint8_t getErrorCode()**

#### Other

- **uint8_t getAddressPins()** binary form of the 4 address bits. 0x00..0x0F.
- **uint8_t getErrorCode()** get the internal error code. See below.
- **bool setTypeTC(char typeTC)** typeTC is one char from E J K N R S T
- **uint8_t getTypeTC()** returns the current TC type.


## Types of thermocouples

The MAX31850 comes in MAX31850E.. MAX31850T types reflecting the version of TC to use.


| Sensor type | SC in µV/°C | Temp Range in °C | Material | notes |
|:-----------:|:------------|:-----------------|:--------------------------|:-----------|
| E_TC | 76.373 | -270 to +1000 | Constantan Chromel |
| J_TC | 57.953 | -210 to +1200 | Constantan Iron |
| K_TC | 41.276 | -270 to +1372 | Alumel Chromel | most used |
| N_TC | 36.256 | -270 to +1300 | Nisil Nicrosil |
| R_TC | 10.506 | -50 to +1768 | Platinum Platinum/Rhodium |
| S_TC | 9.587 | +50 to +1768 | Platinum Platinum/Rhodium |
| T_TC | 52.18 | -270 to +400 | Constantan Copper |
| Sensor type | SC in µV/°C | Temp Range in °C | Material | notes |
|:-------------:|:--------------|:-------------------|:----------------------------|:------------|
| E_TC | 76.373 | -270 to +1000 | Constantan Chromel |
| J_TC | 57.953 | -210 to +1200 | Constantan Iron |
| K_TC | 41.276 | -270 to +1372 | Alumel Chromel | most used |
| N_TC | 36.256 | -270 to +1300 | Nisil Nicrosil |
| R_TC | 10.506 | -50 to +1768 | Platinum Platinum/Rhodium |
| S_TC | 9.587 | +50 to +1768 | Platinum Platinum/Rhodium |
| T_TC | 52.18 | -270 to +400 | Constantan Copper |

(MAX31851 idem)

Expand All @@ -115,27 +132,40 @@ The MAX31850 comes in MAX31850E.. MAX31850T types reflecting the version of TC t

| name | value |
|:--------------------------|:-------:|
| MAX31850_OK | 0 |
| MAX31850_ERR_SHORT_OPEN | 1 |
| MAX31850_ERR_SHORT_GND | 2 |
| MAX31850_ERR_SHORT_VDD | 4 |
| MAX31850_OK | 0 |
| MAX31850_ERR_SHORT_OPEN | 1 |
| MAX31850_ERR_SHORT_GND | 2 |
| MAX31850_ERR_SHORT_VDD | 4 |


## Future

#### must
#### Must

- improve documentation
- get hardware to test (sponsors welcome)
- test on different platforms


#### should
- investigate different thermocouples
#### Should

- investigate different thermocouples
- test with different platforms
- has the 31851 special features to implement?


#### could
- expand to multi sensor per pin.

- extend error handling
- expand to multi sensor per pin.
- first get one sensor working
- investigate range checking on type TC
- need setType() and more.
- need lower upper range = int16_t will do.
- add CRC check
- + error code


#### Wont


Loading

0 comments on commit 43e153b

Please sign in to comment.