Skip to content

Instantly share code, notes, and snippets.

@fxprime
Last active January 18, 2020 15:18
Show Gist options
  • Select an option

  • Save fxprime/0a09e6cd781369001885cce2ce59577c to your computer and use it in GitHub Desktop.

Select an option

Save fxprime/0a09e6cd781369001885cce2ce59577c to your computer and use it in GitHub Desktop.
/***************************************************************************************************/
/*
Example for 12-bit MAX6675 K-Thermocouple to Digital Converter with Cold Junction Compensation
written by : enjoyneering79
sourse code: https://github.com/enjoyneering/MAX6675
- MAX31855 maximum power supply voltage is 3.6v
- K-type thermocouples have an absolute accuracy of around ±2°C..±6°C.
- Measurement tempereture range -200°C..+700°C ±2°C or -270°C..+1372°C ±6°C
with 0.25°C resolution/increment.
- Cold junction compensation range -40°C..+125° ±3°C with 0.062°C resolution/increment.
Optimal performance of cold junction compensation happends when the thermocouple cold junction
& the MAX31855 are at the same temperature. Avoid placing heat-generating devices or components
near the converter because this may produce an errors.
- It is strongly recommended to add a 10nF/0.01mF ceramic surface-mount capacitor, placed across
the T+ and T- pins, to filter noise on the thermocouple lines.
This sensor uses SPI bus to communicate, specials pins are required to interface
Board: MOSI MISO SCLK SS, don't use for CS Level
Uno, Mini, Pro, ATmega168, ATmega328..... 11 12 13 10 5v
Mega, Mega2560, ATmega1280, ATmega2560... 51 50 52 53 5v
Due, SAM3X8E............................. ICSP4 ICSP1 ICSP3 x 3.3v
Leonardo, ProMicro, ATmega32U4........... 16 14 15 x 5v
Blue Pill, STM32F103xxxx boards.......... PA17 PA6 PA5 PA4 3v
NodeMCU 1.0, WeMos D1 Mini............... GPIO13/D7 GPIO12/D6 GPIO14/D5 GPIO15/D8* 3v/5v
ESP32.................................... GPIO23/D23 GPIO19/D19 GPIO18/D18 x 3v
*if GPIO2/D4 or GPIO0/D3 is used for for CS, apply an external
25kOhm pullup-down resistor otherwise reset & reset button
may not work
Frameworks & Libraries:
ATtiny Core - https://github.com/SpenceKonde/ATTinyCore
ESP32 Core - https://github.com/espressif/arduino-esp32
ESP8266 Core - https://github.com/esp8266/Arduino
STM32 Core - https://github.com/rogerclarkmelbourne/Arduino_STM32
GNU GPL license, all text above must be included in any redistribution,
see link for details - https://www.gnu.org/licenses/licenses.html
*/
/***************************************************************************************************/
#include <MAX31855.h>
int32_t rawData = 0;
/*
MAX31855(cs)
cs - chip select
*/
MAX31855 myMAX31855(10);
void setup()
{
Serial.begin(115200);
/* start MAX31855 */
myMAX31855.begin();
while (myMAX31855.getChipID() != MAX31855_ID)
{
Serial.println(F("MAX6675 error")); //(F()) saves string to flash & keeps dynamic memory free
delay(5000);
}
Serial.println(F("MAX6675 OK"));
}
void loop()
{
while (myMAX31855.detectThermocouple() != MAX31855_THERMOCOUPLE_OK)
{
switch (myMAX31855.detectThermocouple())
{
case MAX31855_THERMOCOUPLE_SHORT_TO_VCC:
Serial.println(F("Thermocouple short to VCC"));
break;
case MAX31855_THERMOCOUPLE_SHORT_TO_GND:
Serial.println(F("Thermocouple short to GND"));
break;
case MAX31855_THERMOCOUPLE_NOT_CONNECTED:
Serial.println(F("Thermocouple not connected"));
break;
case MAX31855_THERMOCOUPLE_UNKNOWN:
Serial.println(F("Thermocouple unknown error, check spi cable"));
break;
}
delay(100);
}
rawData = myMAX31855.readRawData();
Serial.print(F("Thermocouple: "));
Serial.println(myMAX31855.getTemperature(rawData));
delay(100);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment