Giter VIP home page Giter VIP logo

adafruit-max31855-library's Introduction

Adafruit-MAX31855-library Build Status

Driver for the Adafruit MAX31855 Thermocouple Amplifier

Info

The MAX31855K does everything for you, and can be easily interfaced with any microcontroller, even one without an analog input. This breakout board has the chip itself, a 3.3V regulator with 10uF bypass capacitors and level shifting circuitry, all assembled and tested. For use with type K thermocouples

Adafruit invests time and resources providing this open source code, please support Adafruit and open-source hardware by purchasing products from Adafruit!

License

BSD license, all text above must be included in any redistribution.

adafruit-max31855-library's People

Contributors

andydoro avatar caternuson avatar driverblock avatar evaherrada avatar hoffmannjan avatar julianh2o avatar kurte avatar ladyada avatar tdicola avatar tyeth avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

adafruit-max31855-library's Issues

This library should allow the user to specify which SPI Device to use, like most of your libraries

Up on the PJRC Forum another member created a thread:
https://forum.pjrc.com/threads/66607-difference-between-teensy3-6-and-Teensy4-1-SPI-configuration

Where he is trying to use the pins associated with SPI1 with this device. My quick look through I did not see any locations in this library that allows the user to specify SPI1. In many of your libraries you either allow it on the constructor or on a begin method.

I suggested that maybe the user should try something like:
either add or modify a constructor in the header file, something like:

class Adafruit_MAX31855 {
public:
  Adafruit_MAX31855(int8_t _sclk, int8_t _cs, int8_t _miso);
  Adafruit_MAX31855(int8_t _cs, SPIClass *theSPI = &SPI);

Don't know if this would need to be conditional for some processors...
But assuming this would work, I would think the implementation would simply be:

Adafruit_MAX31855::Adafruit_MAX31855(int8_t _cs, SPIClass *theSPI) : spi_dev(_cs, 1000000, SPI_BITORDER_MSBFIRST, SPI_MODE0, theSPI) {}

Note: I typed on fly and did not try to build nor do I have devices to try it on. Also not sure if maybe the other constructor should also have the optional parameter as well...

Serial Display Sample Code (serialthermocouple) does not compile

Arduino: 1.6.6 (Windows 10), Board: "Arduino/Genuino Uno"

Build options changed, rebuilding all
serialthermocouple:28: error: redefinition of 'Adafruit_MAX31855 thermocouple'

Adafruit_MAX31855 thermocouple(CLK, CS, DO);

                           ^

serialthermocouple:28: error: 'Adafruit_MAX31855 thermocouple' previously declared here

Adafruit_MAX31855 thermocouple(CLK, CS, DO);

               ^

D:\Users\Danny\Documents\Arduino\libraries\Adafruit-MAX31855-library-master\examples\serialthermocouple\serialthermocouple.ino: In function 'void setup()':

serialthermocouple:35: error: redefinition of 'void setup()'

void setup() {

  ^

serialthermocouple:35: error: 'void setup()' previously defined here

void setup() {

  ^

D:\Users\Danny\Documents\Arduino\libraries\Adafruit-MAX31855-library-master\examples\serialthermocouple\serialthermocouple.ino: In function 'void loop()':

serialthermocouple:43: error: redefinition of 'void loop()'

void loop() {

  ^

serialthermocouple:43: error: 'void loop()' previously defined here

void loop() {

  ^

exit status 1
redefinition of 'Adafruit_MAX31855 thermocouple'

This report would have more information with
"Show verbose output during compilation"
enabled in File > Preferences.

Wrong SPI mode ?

In file Adafruit_MAX31855.cpp (row 145) you are using SPI mode 0, but on MAX31855 faq it states that the chip only supports Mode 1.

Which SPI mode does the MAX31855 use?
The MAX31855 implements a read-only Mode 1 SPI interface.

Are you sure that spi mode 0 is correct ? Using a chinese compatible board I have issues in both modes (probably I have a defective chip), but I just wanted to point it out.

Issue with Neg Number for internal Temperature (with FIX)

Code does not return correct value for negative internal temperature values -- here's a fix:

/***************************************************
This is a library for the Adafruit Thermocouple Sensor w/MAX31855K

Designed specifically to work with the Adafruit Thermocouple Sensor
----> https://www.adafruit.com/products/269

These displays use SPI to communicate, 3 pins are required to
interface
Adafruit invests time and resources providing this open source code,
please support Adafruit and open-source hardware by purchasing
products from Adafruit!

Written by Limor Fried/Ladyada for Adafruit Industries.
BSD license, all text above must be included in any redistribution

modified 03/21/2013 by cmay -- there was an error in the output
when the internal temperature was negative -- see Maxim's datasheet
tables 4 and 5 for sample data values

****************************************************/

include "Adafruit_MAX31855.h"

include <avr/pgmspace.h>

include <util/delay.h>

include <stdlib.h>

Adafruit_MAX31855::Adafruit_MAX31855(int8_t SCLK, int8_t CS, int8_t MISO) {
sclk = SCLK;
cs = CS;
miso = MISO;

//define pin modes
pinMode(cs, OUTPUT);
pinMode(sclk, OUTPUT);
pinMode(miso, INPUT);

digitalWrite(cs, HIGH);
}

double Adafruit_MAX31855::readInternal(void) {
uint32_t v;

v = spiread32();

// ignore bottom 4 bits - they're just thermocouple data
v >>= 4;

// pull the bottom 11 bits off
float internal = v & 0x7FF;
// internal = 0.0625; // LSB = 0.0625 degrees -- cmay 03/21/2013 MOVED below if statement
// check sign bit!
if (v & 0x800)
{
///////////////////////////////////////////////
//internal *= -1; //not quite cmay 03/21/2013
//try this instead:
int16_t tmp;
tmp = ~(v&0x7FF)+1; //2's complement
tmp= tmp & 0x07FF; //only using 11 bits
internal = tmp
-1;
///////////////////////////////////////////////
}
internal *= 0.0625;

//Serial.print("\tInternal Temp: "); Serial.println(internal);
return internal;
}

double Adafruit_MAX31855::readCelsius(void) {

int32_t v;

v = spiread32();

//Serial.print("0x"); Serial.println(v, HEX);

/*
float internal = (v >> 4) & 0x7FF;
internal *= 0.0625;
if ((v >> 4) & 0x800)
internal *= -1;
Serial.print("\tInternal Temp: "); Serial.println(internal);
*/

if (v & 0x7) {
// uh oh, a serious problem!
return NAN;
}

// get rid of internal temp data, and any fault bits
v >>= 18;
//Serial.println(v, HEX);

////////////////////////////////////////////////////////
/* the following lines DO NOTHING ... cmay 03/21/2013
// pull the bottom 13 bits off
int16_t temp = v & 0x3FFF;
// check sign bit
if (v & 0x2000)
temp |= 0xC000;
//Serial.println(temp);
*/
////////////////////////////////////////////////////////

double centigrade = v;
// LSB = 0.25 degrees C
centigrade *= 0.25;
return centigrade;
}

uint8_t Adafruit_MAX31855::readError() {
return spiread32() & 0x7;
}

double Adafruit_MAX31855::readFarenheit(void) {
float f = readCelsius();
f *= 9.0;
f /= 5.0;
f += 32;
return f;
}

uint32_t Adafruit_MAX31855::spiread32(void) {
int i;
uint32_t d = 0;

digitalWrite(sclk, LOW);
_delay_ms(1);
digitalWrite(cs, LOW);
_delay_ms(1);

for (i=31; i>=0; i--)
{
digitalWrite(sclk, LOW);
_delay_ms(1);
d <<= 1;
if (digitalRead(miso))
{
d |= 1;
}

digitalWrite(sclk, HIGH);
_delay_ms(1);

}

digitalWrite(cs, HIGH);
//Serial.println(d, HEX);

////////////////////////////////////////////////////////////////////
//cmay -- for test cases return values like
// tc AND internal
//0x3E806490 -- should be 1000 AND 100.5625 no Tcouple Errors
//0xf060ec00 -- should be -250 AND -20 with no Tcouple Errors
//0xFFFCFFF0 -- should be -0.25 AND -0.0625 with no Tcouple Errors
//0xF060C900 -- should be -250 AND -50 with no Tcouple Errors
////////////////////////////////////////////////////////////////////
//d = 0xF060C900; //0xfffcfff0; //0xf060ec00;
return d;
}

bit operation details

In the file Adafruit-MAX31855-library/Adafruit_MAX31855.cpp at line 98 :
v = 0xFFFFC000 | ((v >> 18) & 0x00003FFFF);

I think that 0x00003FFFF should be 0x00003FFF
But I also think that it changes nothing and ((v >> 18) & 0x00003FFFF); can be replaced by (v >> 18)

Needed 3.3v-5v level shifter.

I have a MAX31855 breakout board then I tried the Adafruit library but it didn't work right. 3.3 is the Vin and SPI pins are interfaced to 5V arduino. When I put level shifter, the library works smooth.

This library works very well. Just extra note on the level-shifter.

After tempeature goes above ~95C library stops returning temperatures.

Not sure exactly what is going on.

Tried it with multiple thermocouples (from two different sources) and both go to 0.00 once the temperature gets above around 95-100C.

Will experiment more (incl trying my other breakout to make sure its not a hardware issue) and provide further details hopefully by this weekend

With hardware SPI, failure check doesn't work

Hi,

On esp32 (1.0.4+ framework) with hardware SPI, if MAX31855 is disconnected (or failed), library will output 0.0 value - not NAN and failure. This is true for both, old release without Adafruit_SPIDevice and with it.

Just compile library on empty esp32 board and use hw SPI in serial example.
Output:

MAX31855 test
Internal Temp = 0.00
C = 0.00
Internal Temp = 0.00
C = 0.00
Internal Temp = 0.00
C = 0.00

And there should be an error reported like with software spi is.

bad data ?

Has anyone ever seen this before?
This is an ebay module, I have to see if I can reproduce on my adafruit module, maybe its a bad chip..

If my TC is less than CJ, I get this..
This is typically only during this condition, this is at around 28C
If TC is warmer than cj it stops..

Could be noise.., but its so consistantly reproducible which is odd..

debugs are uncommented from lib, error is mine, should be 24C getting -x.xx

[TC RAW]1100011000001101101100000
0x18C1B60
[TC RAW]11111111110110000001101101110000
0xFFD81B70
[ERROR] TC OUT OF RANGE, skipping -2.50
[TC RAW]1100100000001101101100000
0x1901B60
[TC RAW]1100011000001101101100000
0x18C1B60
[TC RAW]1100100000001101101100000
0x1901B60
[TC RAW]1100100000001101101100000
0x1901B60
[TC RAW]1100100000001101101100000
0x1901B60
[TC RAW]1100100000001101101100000
0x1901B60
[TC RAW]1100010000001101101100000
0x1881B60
[TC RAW]1100100000001101101100000
0x1901B60
[TC RAW]11111111011110000001101101100000
0xFF781B60
[ERROR] TC OUT OF RANGE, skipping -8.50
[TC RAW]1100100000001101101100000
0x1901B60
[TC RAW]1100100000001101101100000
0x1901B60
[TC RAW]1100100000001101101100000

warning: passing NULL to non-pointer argument

  • Arduino board: Arduino Uno or Teensy 3.2

  • Arduino IDE version (found in Arduino -> About Arduino menu): Arduino 1.8.13 or PlatformIO 2.1.0 (VSCode)

  • List the steps to reproduce the problem below (if possible attach a sketch or
    copy the sketch code in too):

Download latest BusIO. Compile any Adafruit_MAX31855 sample project with Arduino IDE and Verbose output turned on in Preferences to see the following warning:

[code]In file included from /var/folders/t2/6m0f3ybs5rsbsdbfl_gg77fw0000gp/T/arduino_build_583631/sketch/Adafruit_MAX31855.cpp:36:0:
/var/folders/t2/6m0f3ybs5rsbsdbfl_gg77fw0000gp/T/arduino_build_583631/sketch/Adafruit_MAX31855.h:49:32: warning: passing NULL to non-pointer argument 1 of 'Adafruit_SPIDevice::Adafruit_SPIDevice(int8_t, uint32_t, BitOrder, uint8_t, SPIClass*)' [-Wconversion-null]
Adafruit_SPIDevice spi_dev = NULL;[/code]

This is just a warning, but when using PlatformIO, you'll have to compile twice when touching any class using this. This is since VSCode will flag the warning in the "issues" tab. It disappears on the second compile, but users of other IDE's have also discovered this issue: https://forums.adafruit.com/viewtopic.php?f=25&t=162835

The problem is that "spi_dev" is initialized to "NULL". From what I've learned, you don't initialise a complex data type in a header file and "NULL" is apparently not a valid value. Could it be that this should have been a Pointer instead, so it's allowed to be empty?

Library code appears to process negative thermocouple values incorrectly

I posted a comment in the Adafruit forum on sensors regarding issues with the MAX31855 library code. The routine that reads the thermocouple value (not the internal value) does not properly convert negative values. The issue lies with the use of >> for negative numbers. Sign-extension by >> is compiler specific. The gcc-avr compiler, which I use, does NOT sign extend. I don't know if the Arduino compiler does.

Regardless, the sign bit is tested and only recorded in the variable temp, which is then not used again. The conversion of v (int) to centigrade (double) does not include sign info if >> does not sign-extend.

I have written my own version of these routines in ANSI C for use with the gcc-avr compiler. You can find them at: www.seanet.com/~karllunt. Please feel free to add them to github if you think that is appropriate.

Karl Lunt

Return of NAN to report problem getting value

My ESP8266 project reads a thermocouple and sends the value as JSON upon a HTTP request. This usually works fine but occasionally the returned JSON has "nan" in place of the temperature value. In the driver code I see that some error conditions cause a return of the constant NAN, but I can't find where this value is defined. My Arduino code that calls .readCelsius() expects a double. What is actually being returned, and how can I test for it?

Renaming the library to be more compatible with the Arduino IDE

The current incarnation of the Arduino IDE will not load a library that contains the hyphen character (-) in its name. Because of how common/easy it is to just git clone a library directly into this library folder, it would be nice to have it work immediately without being renamed.

Before implementing this change, it would be wise to consider any ramifications to existing clones.

SPI, the "new" way

After reading the issue template I am not sure if contributions are welcome, but I refactored the SPI related code to work the "new" way, with the SPI library, using SPISettings, SPIbeginTransaction and SPIendTransaction.

Let me know if this is something you are willing to merge and I will prepare a PR.

Excessive delays in software SPI mode

The default software SPI implementation uses delay(ms) during every loop iteration, causing a single read of both internal and t/c temperatures to take almost 120ms.

I've removed this delay call (and removed/changed a few others) at my end and the code still works, with a read now taking around 3ms (still slower than 125KHz SPI but not by much).

Is there a reason for these delay calls, or could they be removed to improve efficiency?

else 
{
  // software SPI
  digitalWrite(sclk, LOW);
  delayMicroseconds(10);

  for (i=31; i>=0; i--) 
  {
    digitalWrite(sclk, LOW);
    d <<= 1;
    if (digitalRead(miso)) 
    {
      d |= 1;
    }
    digitalWrite(sclk, HIGH);
  }
}

Max31855 not working on wemos/esp8266

I am using three or four Adafruit MAX31855 on UNO and MEGA boards and they work as advertised. However, when I try to use them on a esp8266-based WEMOS D1 R2 the program crashes in a lot of interesting ways when I try to read the temperature.

Is it at all possible to use this combination?

/ ------------------- Thermocouple board -------------------

#include "Adafruit_MAX31855.h"
int thermoCLK = 4;
int thermoCS = 5;
int thermoDO = 6;
Adafruit_MAX31855 thermocouple(thermoCLK, thermoCS, thermoDO);
...
void loop() {
double temperatuur;
temperatuur=thermocouple.readCelsius();
}

Would you mind how can i setoffset for Max31855

How can i set offset temperature on Max31855
so i also use Max6675K
that easy for setoffset on its
by

ts.setOffset(0);

but this is not can use for Max31855
้how can i setoffset for Max31855?
Thanks...

Negative value bit shift with bit mask to long

Hi there,
looking into work library I found a bug into the temperature computation, in particular when the temperature in negative.

if (v & 0x80000000) { // Negative value, drop the lower 18 bits and explicitly extend sign bits. v = 0xFFFFC000 | ((v >> 18) & 0x00003FFFF); }

The bug regards ((v >> 18) & 0x00003FFFF

Here you perform a bit shift of 18 position to maintain the 14 temperature bit, but if you use this mask
0x00003FFFF you maintain 18 bit.

The right operations is to get a negative temperature are:

if (v & 0x80000000) { // Negative value, drop the lower 18 bits and explicitly extend sign bits. v = 0xFFFFC000 | ((v >> 18) & 0x00003FFF); }

Thanks for you work Adafruit!

Best regards,
Federico

No Error If not connected

Ran my code on spare ESP32 Board that did not have MAX3185 sensor

But still got a valid reading

Could it be that some errors are missing

// STATE constants returned by read()
#define STATUS_OK 0x00
#define STATUS_OPEN_CIRCUIT 0x01
#define STATUS_SHORT_TO_GND 0x02
#define STATUS_SHORT_TO_VCC 0x04
#define STATUS_ERROR 0x07
#define STATUS_NOREAD 0x80
#define STATUS_NO_COMMUNICATION 0x81

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.