mirror of
https://github.com/RobTillaart/Arduino.git
synced 2024-10-03 18:09:02 -04:00
+ initial version 0.1.00
+ two demo sketches + short readme.txt
This commit is contained in:
parent
94bb47b666
commit
d59d553eb2
87
libraries/MAX31855/MAX31855.cpp
Normal file
87
libraries/MAX31855/MAX31855.cpp
Normal file
@ -0,0 +1,87 @@
|
||||
//
|
||||
// FILE: MAX31855.cpp
|
||||
// AUTHOR: Rob Tillaart
|
||||
// VERSION: 0.1.00
|
||||
// PURPOSE: MAX31855 - Thermocouple
|
||||
// DATE: 2014-01-01
|
||||
// URL:
|
||||
//
|
||||
// Released to the public domain
|
||||
//
|
||||
|
||||
#include "MAX31855.h"
|
||||
|
||||
MAX31855::MAX31855(uint8_t sclk, uint8_t cs, uint8_t miso)
|
||||
{
|
||||
_sclk = sclk;
|
||||
_cs = cs;
|
||||
_miso = miso;
|
||||
}
|
||||
|
||||
void MAX31855::begin()
|
||||
{
|
||||
pinMode(_cs, OUTPUT);
|
||||
digitalWrite(_cs, HIGH);
|
||||
|
||||
pinMode(_sclk, OUTPUT);
|
||||
pinMode(_miso, INPUT);
|
||||
}
|
||||
|
||||
uint8_t MAX31855::read()
|
||||
{
|
||||
uint32_t value = _read();
|
||||
|
||||
// process status bit 0-2
|
||||
_status = value & 0x0007;
|
||||
value >>= 3;
|
||||
|
||||
// reserved bit 3
|
||||
value >>= 1;
|
||||
|
||||
// process internal bit 4-15
|
||||
_internal = (value & 0x07FF) * 0.0625;
|
||||
if (value & 0x0800) _internal *= -1;
|
||||
value >>= 12;
|
||||
|
||||
// Fault bit ignored as we have the 3 status bits
|
||||
// _fault = value & 0x01;
|
||||
value >>= 1;
|
||||
|
||||
// reserved bit 17
|
||||
value >>= 1;
|
||||
|
||||
// process temperature bit 18-31
|
||||
_temperature = (value & 0x1FFF) * 0.25;
|
||||
if (value & 0x2000) _temperature *= -1;
|
||||
|
||||
return _status;
|
||||
}
|
||||
|
||||
|
||||
uint32_t MAX31855::_read(void)
|
||||
{
|
||||
uint32_t value = 0;
|
||||
|
||||
digitalWrite(_sclk, LOW);
|
||||
delayMicroseconds(1000);
|
||||
digitalWrite(_cs, LOW);
|
||||
delayMicroseconds(1000);
|
||||
|
||||
for (int8_t i=31; i>=0; i--)
|
||||
{
|
||||
digitalWrite(_sclk, LOW);
|
||||
delayMicroseconds(1000);
|
||||
|
||||
value <<= 1;
|
||||
if (digitalRead(_miso) == HIGH) value += 1;
|
||||
|
||||
digitalWrite(_sclk, HIGH);
|
||||
delayMicroseconds(1000);
|
||||
}
|
||||
|
||||
digitalWrite(_cs, HIGH);
|
||||
|
||||
return value;
|
||||
}
|
||||
|
||||
// END OF FILE
|
49
libraries/MAX31855/MAX31855.h
Normal file
49
libraries/MAX31855/MAX31855.h
Normal file
@ -0,0 +1,49 @@
|
||||
#ifndef MAX31855_H
|
||||
#define MAX31855_H
|
||||
//
|
||||
// FILE: MAX31855.h
|
||||
// AUTHOR: Rob Tillaart
|
||||
// VERSION: 0.1.00
|
||||
// PURPOSE: MAX31855 - Thermocouple
|
||||
// DATE: 2014-01-01
|
||||
// URL:
|
||||
//
|
||||
// Released to the public domain
|
||||
//
|
||||
|
||||
#if (ARDUINO < 100)
|
||||
#include "WProgram.h"
|
||||
#else
|
||||
#include "Arduino.h"
|
||||
#endif
|
||||
|
||||
#define MAX31855_VERSION "0.1.00"
|
||||
|
||||
#define STATUS_OK 0x00
|
||||
#define STATUS_OPEN_CIRCUIT 0x01
|
||||
#define STATUS_SHORT_TO_GND 0x02
|
||||
#define STATUS_SHORT_TO_VCC 0x04
|
||||
|
||||
class MAX31855
|
||||
{
|
||||
public:
|
||||
MAX31855(uint8_t SCLK, uint8_t CS, uint8_t MISO);
|
||||
void begin();
|
||||
uint8_t read();
|
||||
float getInternal(void) { return _internal; };
|
||||
// Celsius
|
||||
float getTemperature(void) { return _temperature; } ;
|
||||
uint8_t getStatus(void) {return _status; } ;
|
||||
|
||||
private:
|
||||
uint32_t _read();
|
||||
float _internal;
|
||||
float _temperature;
|
||||
uint8_t _status;
|
||||
|
||||
uint8_t _sclk;
|
||||
uint8_t _miso;
|
||||
uint8_t _cs;
|
||||
};
|
||||
|
||||
#endif
|
@ -0,0 +1,46 @@
|
||||
//
|
||||
// FILE: max31855_demo.ino
|
||||
// AUTHOR: Rob Tillaart
|
||||
// VERSION: 0.1.01
|
||||
// PURPOSE: thermocouple lib demo application
|
||||
// DATE: 2014-01-01
|
||||
// URL:
|
||||
//
|
||||
// Released to the public domain
|
||||
//
|
||||
|
||||
#include "MAX31855.h"
|
||||
|
||||
const int doPin = 7;
|
||||
const int csPin = 6;
|
||||
const int clPin = 5;
|
||||
|
||||
MAX31855 tc(clPin, csPin, doPin);
|
||||
|
||||
void setup()
|
||||
{
|
||||
Serial.begin(115200);
|
||||
Serial.print("Start max31855_demo: ");
|
||||
Serial.println(MAX31855_VERSION);
|
||||
Serial.println();
|
||||
|
||||
tc.begin();
|
||||
}
|
||||
|
||||
void loop()
|
||||
{
|
||||
int status = tc.read();
|
||||
Serial.print("stat:\t\t");
|
||||
Serial.println(status);
|
||||
|
||||
float internal = tc.getInternal();
|
||||
Serial.print("internal:\t");
|
||||
Serial.println(internal);
|
||||
|
||||
float temp = tc.getTemperature();
|
||||
Serial.print("temperature:\t");
|
||||
Serial.println(temp);
|
||||
delay(1000);
|
||||
}
|
||||
|
||||
|
@ -0,0 +1,48 @@
|
||||
//
|
||||
// FILE: max31855_demo1.ino
|
||||
// AUTHOR: Rob Tillaart
|
||||
// VERSION: 0.1.01
|
||||
// PURPOSE: thermocouple lib demo application
|
||||
// DATE: 2014-01-02
|
||||
// URL:
|
||||
//
|
||||
// Released to the public domain
|
||||
//
|
||||
|
||||
#include "MAX31855.h"
|
||||
|
||||
const int doPin = 7;
|
||||
const int csPin = 6;
|
||||
const int clPin = 5;
|
||||
|
||||
MAX31855 tc(clPin, csPin, doPin);
|
||||
|
||||
void setup()
|
||||
{
|
||||
Serial.begin(115200);
|
||||
Serial.print("Start max31855_demo: ");
|
||||
Serial.println(MAX31855_VERSION);
|
||||
Serial.println();
|
||||
|
||||
tc.begin();
|
||||
}
|
||||
|
||||
void loop()
|
||||
{
|
||||
int status = tc.read();
|
||||
if (status != 0)
|
||||
{
|
||||
Serial.print("stat:\t\t");
|
||||
Serial.println(status);
|
||||
}
|
||||
|
||||
float temp = tc.getTemperature();
|
||||
int m = temp*10 - 200;
|
||||
Serial.print(temp);
|
||||
Serial.print('\t');
|
||||
for (int i=0; i< m; i++) Serial.write(']');
|
||||
Serial.println();
|
||||
}
|
||||
|
||||
|
||||
|
34
libraries/MAX31855/readme.txt
Normal file
34
libraries/MAX31855/readme.txt
Normal file
@ -0,0 +1,34 @@
|
||||
|
||||
Working is as follows:
|
||||
|
||||
first is to instantiate a constructor:
|
||||
|
||||
#include "MAX31855.h"
|
||||
|
||||
const int doPin = 7;
|
||||
const int csPin = 6;
|
||||
const int clPin = 5;
|
||||
|
||||
MAX31855 tc(clPin, csPin, doPin);
|
||||
|
||||
|
||||
To get a reading one must call tc.read()
|
||||
|
||||
This is the workhorse, it returns the status of the last read which is 0..7
|
||||
0 = OK
|
||||
bit 0 set = thermocouple open circuit
|
||||
bit 1 set = thermocouple short to GND
|
||||
bit 2 set = thermocouple short to VCC
|
||||
|
||||
|
||||
After a tc.read() you can do tc.getTemperature() and tc.getInternal().
|
||||
repeated getTemperature() will give the same value until a new tc.read();
|
||||
|
||||
The reason for this is that it allows the object holds its last known temperature.
|
||||
Now one can do:
|
||||
|
||||
float last = tc.getTemperature();
|
||||
tc.read();
|
||||
float new = tc.getTemperature();
|
||||
float delta = new - last;
|
||||
|
Loading…
Reference in New Issue
Block a user