První commit
This commit is contained in:
14
mqtt_discovery_ha.txt
Normal file
14
mqtt_discovery_ha.txt
Normal file
@@ -0,0 +1,14 @@
|
|||||||
|
mosquitto_pub -h IP -u USER -P PASSWD \
|
||||||
|
-t homeassistant/sensor/nano-pt100-pt100/config \
|
||||||
|
-m '{"name":"Nano PT100 Temperature","state_topic":"sensors/nano-pt100/pt100","unique_id":"nano_pt100_temperature","unit_of_measurement":"°C","device_class":"temperature","value_template":"{{ value|float }}","expire_after":60,"device":{"identifiers":["nano-pt100"],"name":"Nano PT100 Sensor","manufacturer":"Arduino","model":"Nano PT100"}}' \
|
||||||
|
-r
|
||||||
|
|
||||||
|
mosquitto_pub -h IP -u USER -P PASSWD \
|
||||||
|
-t homeassistant/sensor/nano-pt100-distance/config \
|
||||||
|
-m '{"name":"Nano PT100 Distance","state_topic":"sensors/nano-pt100/distance","unique_id":"nano_pt100_distance","unit_of_measurement":"cm","device_class":"distance","value_template":"{{ value|float }}","expire_after":60,"device":{"identifiers":["nano-pt100"],"name":"Nano PT100 Sensor","manufacturer":"Arduino","model":"Nano PT100"}}' \
|
||||||
|
-r
|
||||||
|
|
||||||
|
mosquitto_pub -h IP -u USER -P PASSWD \
|
||||||
|
-t homeassistant/sensor/nano-pt100-distance-map/config \
|
||||||
|
-m '{"name":"Nano PT100 Level %","state_topic":"sensors/nano-pt100/distance_map","unique_id":"nano_pt100_distance_map","unit_of_measurement":"%","device_class":"humidity","value_template":"{{ value|float }}","expire_after":60,"device":{"identifiers":["nano-pt100"],"name":"Nano PT100 Sensor","manufacturer":"Arduino","model":"Nano PT100"}}' \
|
||||||
|
-r
|
||||||
128
nano-pt100.ino
Normal file
128
nano-pt100.ino
Normal file
@@ -0,0 +1,128 @@
|
|||||||
|
/*
|
||||||
|
Použité knihovny:
|
||||||
|
- MQTT PubSub: https://github.com/knolleary/pubsubclient
|
||||||
|
- UIPEthernet pro ENC28J60: https://github.com/UIPEthernet/UIPEthernet
|
||||||
|
- Interval (časovače): https://git.xpablo.cz/pablo2048/Interval
|
||||||
|
|
||||||
|
Použitý hardware:
|
||||||
|
- Arduino Nano
|
||||||
|
- Ethernet shield ENC28J60
|
||||||
|
- Terminal shield pro snadné připojení vodičů
|
||||||
|
|
||||||
|
Odkazy na hardware:
|
||||||
|
https://dratek.cz/arduino-platforma/1164-arduino-nano-v3.0-atmega328-16m-5v-ch340g-klon.html
|
||||||
|
https://dratek.cz/arduino-platforma/936-ethernet-shield-pro-arduino-nano.html
|
||||||
|
https://dratek.cz/arduino-platforma/1196-terminal-shield-pro-arduino-nano.html
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <UIPEthernet.h>
|
||||||
|
#include <PubSubClient.h>
|
||||||
|
#include "src/Adafruit_MAX31865_library/Adafruit_MAX31865.h"
|
||||||
|
#include "src/SharpIR/SharpIR.h"
|
||||||
|
#include "src/Interval/src/interval.h"
|
||||||
|
|
||||||
|
// MQTT identifikace a připojení
|
||||||
|
#define CLIENT_ID "nano-pt100"
|
||||||
|
#define MQTT_SERVER "IP"
|
||||||
|
#define MQTT_PORT "PORT"
|
||||||
|
#define MQTT_USER "USER"
|
||||||
|
#define MQTT_PASSWD "PASSWORD"
|
||||||
|
|
||||||
|
// Konfigurace MAX31865
|
||||||
|
#define RREF 430.0 // Referenční odpor pro MAX31865 (PT100)
|
||||||
|
|
||||||
|
// SharpIR senzor
|
||||||
|
#define ir A0 // Pin SharpIR
|
||||||
|
#define model 1080 // Model senzoru SharpIR
|
||||||
|
|
||||||
|
// Časové intervaly
|
||||||
|
const long sendDataInterval = 1000 * 20; // Interval 20 vteřin
|
||||||
|
const long resetnanoInterval = 1000L * 60 * 60 * 5; // Interval 5 hodin
|
||||||
|
|
||||||
|
// MAC adresa pro ENC28J60
|
||||||
|
uint8_t mac[6] = { 0x5C, 0xC0, 0xC3, 0x21, 0x6A, 0xE6 };
|
||||||
|
|
||||||
|
int dis = 0;
|
||||||
|
|
||||||
|
EthernetClient ethClient;
|
||||||
|
PubSubClient mqttClient;
|
||||||
|
Interval sender;
|
||||||
|
Interval reseter;
|
||||||
|
|
||||||
|
// Čip PT100 – MAX31865
|
||||||
|
Adafruit_MAX31865 max = Adafruit_MAX31865(3, 4, 5, 6);
|
||||||
|
|
||||||
|
// Optický senzor vzdálenosti
|
||||||
|
SharpIR SharpIR(ir, model);
|
||||||
|
|
||||||
|
void setup() {
|
||||||
|
reseter.set(resetnanoInterval); // Nastavení intervalu pro restart
|
||||||
|
|
||||||
|
// Start ethernetu
|
||||||
|
if (Ethernet.begin(mac) == 0) {
|
||||||
|
// Pokud selže inicializace, zůstane zde
|
||||||
|
for (;;)
|
||||||
|
;
|
||||||
|
}
|
||||||
|
|
||||||
|
// MQTT nastavení
|
||||||
|
mqttClient.setClient(ethClient);
|
||||||
|
mqttClient.setServer(MQTT_SERVER, MQTT_PORT);
|
||||||
|
|
||||||
|
// Inicializace MAX31865 (PT100)
|
||||||
|
max.begin(MAX31865_2WIRE); // Lze změnit na 4WIRE dle zapojení
|
||||||
|
}
|
||||||
|
|
||||||
|
void loop() {
|
||||||
|
// Odesílání dat po vypršení intervalu
|
||||||
|
if (sender.expired()) {
|
||||||
|
sender.set(sendDataInterval);
|
||||||
|
sendData();
|
||||||
|
read_sharpIr();
|
||||||
|
}
|
||||||
|
|
||||||
|
mqttClient.loop();
|
||||||
|
|
||||||
|
// Restart Arduino po vypršení intervalu
|
||||||
|
if (reseter.expired()) {
|
||||||
|
delay(sendDataInterval); // Malé zpoždění před resetem
|
||||||
|
reseter.set(resetnanoInterval);
|
||||||
|
arduinoReset();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Odeslání dat z MAX31865 (PT100)
|
||||||
|
void sendData() {
|
||||||
|
char szNumber[10];
|
||||||
|
|
||||||
|
if (mqttClient.connect(CLIENT_ID, MQTT_USER, MQTT_PASSWD)) {
|
||||||
|
mqttClient.publish("sensors/" CLIENT_ID "/pt100", itoa(int(max.temperature(100, RREF)), szNumber, 10));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Čtení dat ze SharpIR a jejich odeslání
|
||||||
|
void read_sharpIr() {
|
||||||
|
if (mqttClient.connect(CLIENT_ID, MQTT_USER, MQTT_PASSWD)) {
|
||||||
|
char send_dist[10];
|
||||||
|
|
||||||
|
dis = SharpIR.distance();
|
||||||
|
|
||||||
|
if (dis > 1 && dis < 80) {
|
||||||
|
// Poslání surové vzdálenosti
|
||||||
|
mqttClient.publish("sensors/" CLIENT_ID "/distance", itoa(int(dis), send_dist, 10));
|
||||||
|
|
||||||
|
// Přemapování vzdálenosti (např. pro procenta)
|
||||||
|
dis = map(dis, 5, 70, 100, 0);
|
||||||
|
mqttClient.publish("sensors/" CLIENT_ID "/distance_map", itoa(int(dis), send_dist, 10));
|
||||||
|
} else {
|
||||||
|
// Mimo rozsah – hláška o chybě
|
||||||
|
mqttClient.publish("sensors/" CLIENT_ID "/chyba", itoa(int(dis), send_dist, 10));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Restart Arduino (nutné kvůli občasnému zamrznutí)
|
||||||
|
// Používá skok na adresu 0 v paměti – reset MCU
|
||||||
|
void arduinoReset() {
|
||||||
|
asm volatile("jmp 0");
|
||||||
|
}
|
||||||
261
src/Adafruit_MAX31865_library/Adafruit_MAX31865.cpp
Normal file
261
src/Adafruit_MAX31865_library/Adafruit_MAX31865.cpp
Normal file
@@ -0,0 +1,261 @@
|
|||||||
|
/***************************************************
|
||||||
|
This is a library for the Adafruit PT100/P1000 RTD Sensor w/MAX31865
|
||||||
|
|
||||||
|
Designed specifically to work with the Adafruit RTD Sensor
|
||||||
|
----> https://www.adafruit.com/products/3328
|
||||||
|
|
||||||
|
This sensor uses SPI to communicate, 4 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
|
||||||
|
****************************************************/
|
||||||
|
|
||||||
|
#include "Adafruit_MAX31865.h"
|
||||||
|
#ifdef __AVR
|
||||||
|
#include <avr/pgmspace.h>
|
||||||
|
#elif defined(ESP8266)
|
||||||
|
#include <pgmspace.h>
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <SPI.h>
|
||||||
|
|
||||||
|
static SPISettings max31865_spisettings = SPISettings(500000, MSBFIRST, SPI_MODE1);
|
||||||
|
|
||||||
|
|
||||||
|
// Software (bitbang) SPI
|
||||||
|
Adafruit_MAX31865::Adafruit_MAX31865(int8_t spi_cs, int8_t spi_mosi, int8_t spi_miso, int8_t spi_clk) {
|
||||||
|
_sclk = spi_clk;
|
||||||
|
_cs = spi_cs;
|
||||||
|
_miso = spi_miso;
|
||||||
|
_mosi = spi_mosi;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
// Hardware SPI init
|
||||||
|
Adafruit_MAX31865::Adafruit_MAX31865(int8_t spi_cs) {
|
||||||
|
_cs = spi_cs;
|
||||||
|
_sclk = _miso = _mosi = -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
boolean Adafruit_MAX31865::begin(max31865_numwires_t wires) {
|
||||||
|
pinMode(_cs, OUTPUT);
|
||||||
|
digitalWrite(_cs, HIGH);
|
||||||
|
|
||||||
|
if (_sclk != -1) {
|
||||||
|
//define pin modes
|
||||||
|
pinMode(_sclk, OUTPUT);
|
||||||
|
digitalWrite(_sclk, LOW);
|
||||||
|
pinMode(_mosi, OUTPUT);
|
||||||
|
pinMode(_miso, INPUT);
|
||||||
|
} else {
|
||||||
|
//start and configure hardware SPI
|
||||||
|
SPI.begin();
|
||||||
|
}
|
||||||
|
|
||||||
|
for (uint8_t i=0; i<16; i++) {
|
||||||
|
// readRegister8(i);
|
||||||
|
}
|
||||||
|
|
||||||
|
setWires(wires);
|
||||||
|
enableBias(false);
|
||||||
|
autoConvert(false);
|
||||||
|
clearFault();
|
||||||
|
|
||||||
|
//Serial.print("config: "); Serial.println(readRegister8(MAX31856_CONFIG_REG), HEX);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
uint8_t Adafruit_MAX31865::readFault(void) {
|
||||||
|
return readRegister8(MAX31856_FAULTSTAT_REG);
|
||||||
|
}
|
||||||
|
|
||||||
|
void Adafruit_MAX31865::clearFault(void) {
|
||||||
|
uint8_t t = readRegister8(MAX31856_CONFIG_REG);
|
||||||
|
t &= ~0x2C;
|
||||||
|
t |= MAX31856_CONFIG_FAULTSTAT;
|
||||||
|
writeRegister8(MAX31856_CONFIG_REG, t);
|
||||||
|
}
|
||||||
|
|
||||||
|
void Adafruit_MAX31865::enableBias(boolean b) {
|
||||||
|
uint8_t t = readRegister8(MAX31856_CONFIG_REG);
|
||||||
|
if (b) {
|
||||||
|
t |= MAX31856_CONFIG_BIAS; // enable bias
|
||||||
|
} else {
|
||||||
|
t &= ~MAX31856_CONFIG_BIAS; // disable bias
|
||||||
|
}
|
||||||
|
writeRegister8(MAX31856_CONFIG_REG, t);
|
||||||
|
}
|
||||||
|
|
||||||
|
void Adafruit_MAX31865::autoConvert(boolean b) {
|
||||||
|
uint8_t t = readRegister8(MAX31856_CONFIG_REG);
|
||||||
|
if (b) {
|
||||||
|
t |= MAX31856_CONFIG_MODEAUTO; // enable autoconvert
|
||||||
|
} else {
|
||||||
|
t &= ~MAX31856_CONFIG_MODEAUTO; // disable autoconvert
|
||||||
|
}
|
||||||
|
writeRegister8(MAX31856_CONFIG_REG, t);
|
||||||
|
}
|
||||||
|
|
||||||
|
void Adafruit_MAX31865::setWires(max31865_numwires_t wires ) {
|
||||||
|
uint8_t t = readRegister8(MAX31856_CONFIG_REG);
|
||||||
|
if (wires == MAX31865_3WIRE) {
|
||||||
|
t |= MAX31856_CONFIG_3WIRE;
|
||||||
|
} else {
|
||||||
|
// 2 or 4 wire
|
||||||
|
t &= ~MAX31856_CONFIG_3WIRE;
|
||||||
|
}
|
||||||
|
writeRegister8(MAX31856_CONFIG_REG, t);
|
||||||
|
}
|
||||||
|
|
||||||
|
float Adafruit_MAX31865::temperature(float RTDnominal, float refResistor) {
|
||||||
|
// http://www.analog.com/media/en/technical-documentation/application-notes/AN709_0.pdf
|
||||||
|
|
||||||
|
float Z1, Z2, Z3, Z4, Rt, temp;
|
||||||
|
|
||||||
|
Rt = readRTD();
|
||||||
|
Rt /= 32768;
|
||||||
|
Rt *= refResistor;
|
||||||
|
|
||||||
|
// Serial.print("\nResistance: "); Serial.println(Rt, 8);
|
||||||
|
|
||||||
|
Z1 = -RTD_A;
|
||||||
|
Z2 = RTD_A * RTD_A - (4 * RTD_B);
|
||||||
|
Z3 = (4 * RTD_B) / RTDnominal;
|
||||||
|
Z4 = 2 * RTD_B;
|
||||||
|
|
||||||
|
temp = Z2 + (Z3 * Rt);
|
||||||
|
temp = (sqrt(temp) + Z1) / Z4;
|
||||||
|
|
||||||
|
if (temp >= 0) return temp;
|
||||||
|
|
||||||
|
// ugh.
|
||||||
|
Rt /= RTDnominal;
|
||||||
|
Rt *= 100; // normalize to 100 ohm
|
||||||
|
|
||||||
|
float rpoly = Rt;
|
||||||
|
|
||||||
|
temp = -242.02;
|
||||||
|
temp += 2.2228 * rpoly;
|
||||||
|
rpoly *= Rt; // square
|
||||||
|
temp += 2.5859e-3 * rpoly;
|
||||||
|
rpoly *= Rt; // ^3
|
||||||
|
temp -= 4.8260e-6 * rpoly;
|
||||||
|
rpoly *= Rt; // ^4
|
||||||
|
temp -= 2.8183e-8 * rpoly;
|
||||||
|
rpoly *= Rt; // ^5
|
||||||
|
temp += 1.5243e-10 * rpoly;
|
||||||
|
|
||||||
|
return temp;
|
||||||
|
}
|
||||||
|
|
||||||
|
uint16_t Adafruit_MAX31865::readRTD (void) {
|
||||||
|
clearFault();
|
||||||
|
enableBias(true);
|
||||||
|
delay(10);
|
||||||
|
uint8_t t = readRegister8(MAX31856_CONFIG_REG);
|
||||||
|
t |= MAX31856_CONFIG_1SHOT;
|
||||||
|
writeRegister8(MAX31856_CONFIG_REG, t);
|
||||||
|
delay(65);
|
||||||
|
|
||||||
|
uint16_t rtd = readRegister16(MAX31856_RTDMSB_REG);
|
||||||
|
|
||||||
|
// remove fault
|
||||||
|
rtd >>= 1;
|
||||||
|
|
||||||
|
return rtd;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**********************************************/
|
||||||
|
|
||||||
|
uint8_t Adafruit_MAX31865::readRegister8(uint8_t addr) {
|
||||||
|
uint8_t ret = 0;
|
||||||
|
readRegisterN(addr, &ret, 1);
|
||||||
|
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
uint16_t Adafruit_MAX31865::readRegister16(uint8_t addr) {
|
||||||
|
uint8_t buffer[2] = {0, 0};
|
||||||
|
readRegisterN(addr, buffer, 2);
|
||||||
|
|
||||||
|
uint16_t ret = buffer[0];
|
||||||
|
ret <<= 8;
|
||||||
|
ret |= buffer[1];
|
||||||
|
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void Adafruit_MAX31865::readRegisterN(uint8_t addr, uint8_t buffer[], uint8_t n) {
|
||||||
|
addr &= 0x7F; // make sure top bit is not set
|
||||||
|
|
||||||
|
if (_sclk == -1)
|
||||||
|
SPI.beginTransaction(max31865_spisettings);
|
||||||
|
else
|
||||||
|
digitalWrite(_sclk, LOW);
|
||||||
|
|
||||||
|
digitalWrite(_cs, LOW);
|
||||||
|
|
||||||
|
spixfer(addr);
|
||||||
|
|
||||||
|
//Serial.print("$"); Serial.print(addr, HEX); Serial.print(": ");
|
||||||
|
while (n--) {
|
||||||
|
buffer[0] = spixfer(0xFF);
|
||||||
|
//Serial.print(" 0x"); Serial.print(buffer[0], HEX);
|
||||||
|
buffer++;
|
||||||
|
}
|
||||||
|
//Serial.println();
|
||||||
|
|
||||||
|
if (_sclk == -1)
|
||||||
|
SPI.endTransaction();
|
||||||
|
|
||||||
|
digitalWrite(_cs, HIGH);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void Adafruit_MAX31865::writeRegister8(uint8_t addr, uint8_t data) {
|
||||||
|
if (_sclk == -1)
|
||||||
|
SPI.beginTransaction(max31865_spisettings);
|
||||||
|
else
|
||||||
|
digitalWrite(_sclk, LOW);
|
||||||
|
|
||||||
|
digitalWrite(_cs, LOW);
|
||||||
|
|
||||||
|
spixfer(addr | 0x80); // make sure top bit is set
|
||||||
|
spixfer(data);
|
||||||
|
|
||||||
|
//Serial.print("$"); Serial.print(addr, HEX); Serial.print(" = 0x"); Serial.println(data, HEX);
|
||||||
|
|
||||||
|
if (_sclk == -1)
|
||||||
|
SPI.endTransaction();
|
||||||
|
|
||||||
|
digitalWrite(_cs, HIGH);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
uint8_t Adafruit_MAX31865::spixfer(uint8_t x) {
|
||||||
|
if (_sclk == -1)
|
||||||
|
return SPI.transfer(x);
|
||||||
|
|
||||||
|
// software spi
|
||||||
|
//Serial.println("Software SPI");
|
||||||
|
uint8_t reply = 0;
|
||||||
|
|
||||||
|
for (int i=7; i>=0; i--) {
|
||||||
|
reply <<= 1;
|
||||||
|
digitalWrite(_sclk, HIGH);
|
||||||
|
digitalWrite(_mosi, x & (1<<i));
|
||||||
|
digitalWrite(_sclk, LOW);
|
||||||
|
if (digitalRead(_miso))
|
||||||
|
reply |= 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
return reply;
|
||||||
|
}
|
||||||
95
src/Adafruit_MAX31865_library/Adafruit_MAX31865.h
Normal file
95
src/Adafruit_MAX31865_library/Adafruit_MAX31865.h
Normal file
@@ -0,0 +1,95 @@
|
|||||||
|
/***************************************************
|
||||||
|
This is a library for the Adafruit PT100/P1000 RTD Sensor w/MAX31865
|
||||||
|
|
||||||
|
Designed specifically to work with the Adafruit RTD Sensor
|
||||||
|
----> https://www.adafruit.com/products/3328
|
||||||
|
|
||||||
|
This sensor uses SPI to communicate, 4 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
|
||||||
|
****************************************************/
|
||||||
|
|
||||||
|
#ifndef ADAFRUIT_MAX31865_H
|
||||||
|
#define ADAFRUIT_MAX31865_H
|
||||||
|
|
||||||
|
#define MAX31856_CONFIG_REG 0x00
|
||||||
|
#define MAX31856_CONFIG_BIAS 0x80
|
||||||
|
#define MAX31856_CONFIG_MODEAUTO 0x40
|
||||||
|
#define MAX31856_CONFIG_MODEOFF 0x00
|
||||||
|
#define MAX31856_CONFIG_1SHOT 0x20
|
||||||
|
#define MAX31856_CONFIG_3WIRE 0x10
|
||||||
|
#define MAX31856_CONFIG_24WIRE 0x00
|
||||||
|
#define MAX31856_CONFIG_FAULTSTAT 0x02
|
||||||
|
#define MAX31856_CONFIG_FILT50HZ 0x01
|
||||||
|
#define MAX31856_CONFIG_FILT60HZ 0x00
|
||||||
|
|
||||||
|
#define MAX31856_RTDMSB_REG 0x01
|
||||||
|
#define MAX31856_RTDLSB_REG 0x02
|
||||||
|
#define MAX31856_HFAULTMSB_REG 0x03
|
||||||
|
#define MAX31856_HFAULTLSB_REG 0x04
|
||||||
|
#define MAX31856_LFAULTMSB_REG 0x05
|
||||||
|
#define MAX31856_LFAULTLSB_REG 0x06
|
||||||
|
#define MAX31856_FAULTSTAT_REG 0x07
|
||||||
|
|
||||||
|
|
||||||
|
#define MAX31865_FAULT_HIGHTHRESH 0x80
|
||||||
|
#define MAX31865_FAULT_LOWTHRESH 0x40
|
||||||
|
#define MAX31865_FAULT_REFINLOW 0x20
|
||||||
|
#define MAX31865_FAULT_REFINHIGH 0x10
|
||||||
|
#define MAX31865_FAULT_RTDINLOW 0x08
|
||||||
|
#define MAX31865_FAULT_OVUV 0x04
|
||||||
|
|
||||||
|
|
||||||
|
#define RTD_A 3.9083e-3
|
||||||
|
#define RTD_B -5.775e-7
|
||||||
|
|
||||||
|
#if (ARDUINO >= 100)
|
||||||
|
#include "Arduino.h"
|
||||||
|
#else
|
||||||
|
#include "WProgram.h"
|
||||||
|
#endif
|
||||||
|
|
||||||
|
typedef enum max31865_numwires {
|
||||||
|
MAX31865_2WIRE = 0,
|
||||||
|
MAX31865_3WIRE = 1,
|
||||||
|
MAX31865_4WIRE = 0
|
||||||
|
} max31865_numwires_t;
|
||||||
|
|
||||||
|
|
||||||
|
class Adafruit_MAX31865 {
|
||||||
|
public:
|
||||||
|
Adafruit_MAX31865(int8_t spi_cs, int8_t spi_mosi, int8_t spi_miso, int8_t spi_clk);
|
||||||
|
Adafruit_MAX31865(int8_t spi_cs);
|
||||||
|
|
||||||
|
boolean begin(max31865_numwires_t x = MAX31865_2WIRE);
|
||||||
|
|
||||||
|
uint8_t readFault(void);
|
||||||
|
void clearFault(void);
|
||||||
|
uint16_t readRTD();
|
||||||
|
|
||||||
|
|
||||||
|
void setWires(max31865_numwires_t wires);
|
||||||
|
void autoConvert(boolean b);
|
||||||
|
void enableBias(boolean b);
|
||||||
|
|
||||||
|
float temperature(float RTDnominal, float refResistor);
|
||||||
|
|
||||||
|
private:
|
||||||
|
int8_t _sclk, _miso, _mosi, _cs;
|
||||||
|
|
||||||
|
void readRegisterN(uint8_t addr, uint8_t buffer[], uint8_t n);
|
||||||
|
|
||||||
|
uint8_t readRegister8(uint8_t addr);
|
||||||
|
uint16_t readRegister16(uint8_t addr);
|
||||||
|
|
||||||
|
void writeRegister8(uint8_t addr, uint8_t reg);
|
||||||
|
uint8_t spixfer(uint8_t addr);
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
#endif
|
||||||
19
src/Adafruit_MAX31865_library/README.md
Normal file
19
src/Adafruit_MAX31865_library/README.md
Normal file
@@ -0,0 +1,19 @@
|
|||||||
|
# Adafruit MAX31865 [](https://travis-ci.com/adafruit/Adafruit_MAX31865)
|
||||||
|
|
||||||
|
This is the Adafruit MAX31856 Arduino Library
|
||||||
|
|
||||||
|
<a href="https://www.adafruit.com/products/3328"><img src="assets/image.jpg" height="300"/></a>
|
||||||
|
|
||||||
|
Tested and works great with the Adafruit Thermocouple Breakout w/MAX31856
|
||||||
|
* http://www.adafruit.com/products/3328
|
||||||
|
|
||||||
|
These sensors use SPI to communicate, 4 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, check license.txt for more information
|
||||||
|
All text above must be included in any redistribution
|
||||||
BIN
src/Adafruit_MAX31865_library/assets/image.jpg
Normal file
BIN
src/Adafruit_MAX31865_library/assets/image.jpg
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 309 KiB |
74
src/Adafruit_MAX31865_library/examples/max31865/max31865.ino
Normal file
74
src/Adafruit_MAX31865_library/examples/max31865/max31865.ino
Normal file
@@ -0,0 +1,74 @@
|
|||||||
|
/***************************************************
|
||||||
|
This is a library for the Adafruit PT100/P1000 RTD Sensor w/MAX31865
|
||||||
|
|
||||||
|
Designed specifically to work with the Adafruit RTD Sensor
|
||||||
|
----> https://www.adafruit.com/products/3328
|
||||||
|
|
||||||
|
This sensor uses SPI to communicate, 4 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
|
||||||
|
****************************************************/
|
||||||
|
|
||||||
|
#include <Adafruit_MAX31865.h>
|
||||||
|
|
||||||
|
// Use software SPI: CS, DI, DO, CLK
|
||||||
|
Adafruit_MAX31865 max = Adafruit_MAX31865(10, 11, 12, 13);
|
||||||
|
// use hardware SPI, just pass in the CS pin
|
||||||
|
//Adafruit_MAX31865 max = Adafruit_MAX31865(10);
|
||||||
|
|
||||||
|
// The value of the Rref resistor. Use 430.0 for PT100 and 4300.0 for PT1000
|
||||||
|
#define RREF 430.0
|
||||||
|
// The 'nominal' 0-degrees-C resistance of the sensor
|
||||||
|
// 100.0 for PT100, 1000.0 for PT1000
|
||||||
|
#define RNOMINAL 100.0
|
||||||
|
|
||||||
|
void setup() {
|
||||||
|
Serial.begin(115200);
|
||||||
|
Serial.println("Adafruit MAX31865 PT100 Sensor Test!");
|
||||||
|
|
||||||
|
max.begin(MAX31865_3WIRE); // set to 2WIRE or 4WIRE as necessary
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void loop() {
|
||||||
|
uint16_t rtd = max.readRTD();
|
||||||
|
|
||||||
|
Serial.print("RTD value: "); Serial.println(rtd);
|
||||||
|
float ratio = rtd;
|
||||||
|
ratio /= 32768;
|
||||||
|
Serial.print("Ratio = "); Serial.println(ratio,8);
|
||||||
|
Serial.print("Resistance = "); Serial.println(RREF*ratio,8);
|
||||||
|
Serial.print("Temperature = "); Serial.println(max.temperature(RNOMINAL, RREF));
|
||||||
|
|
||||||
|
// Check and print any faults
|
||||||
|
uint8_t fault = max.readFault();
|
||||||
|
if (fault) {
|
||||||
|
Serial.print("Fault 0x"); Serial.println(fault, HEX);
|
||||||
|
if (fault & MAX31865_FAULT_HIGHTHRESH) {
|
||||||
|
Serial.println("RTD High Threshold");
|
||||||
|
}
|
||||||
|
if (fault & MAX31865_FAULT_LOWTHRESH) {
|
||||||
|
Serial.println("RTD Low Threshold");
|
||||||
|
}
|
||||||
|
if (fault & MAX31865_FAULT_REFINLOW) {
|
||||||
|
Serial.println("REFIN- > 0.85 x Bias");
|
||||||
|
}
|
||||||
|
if (fault & MAX31865_FAULT_REFINHIGH) {
|
||||||
|
Serial.println("REFIN- < 0.85 x Bias - FORCE- open");
|
||||||
|
}
|
||||||
|
if (fault & MAX31865_FAULT_RTDINLOW) {
|
||||||
|
Serial.println("RTDIN- < 0.85 x Bias - FORCE- open");
|
||||||
|
}
|
||||||
|
if (fault & MAX31865_FAULT_OVUV) {
|
||||||
|
Serial.println("Under/Over voltage");
|
||||||
|
}
|
||||||
|
max.clearFault();
|
||||||
|
}
|
||||||
|
Serial.println();
|
||||||
|
delay(1000);
|
||||||
|
}
|
||||||
9
src/Adafruit_MAX31865_library/library.properties
Normal file
9
src/Adafruit_MAX31865_library/library.properties
Normal file
@@ -0,0 +1,9 @@
|
|||||||
|
name=Adafruit MAX31865 library
|
||||||
|
version=1.0.2
|
||||||
|
author=Adafruit
|
||||||
|
maintainer=Adafruit <info@adafruit.com>
|
||||||
|
sentence=Library for the Adafruit RTD Amplifier breakout with MAX31865
|
||||||
|
paragraph=Library for the Adafruit RTD Amplifier breakout with MAX31865
|
||||||
|
category=Sensors
|
||||||
|
url=https://github.com/adafruit/Adafruit_MAX31865
|
||||||
|
architectures=*
|
||||||
1
src/Interval
Submodule
1
src/Interval
Submodule
Submodule src/Interval added at 15be6b4674
1
src/SharpIR
Submodule
1
src/SharpIR
Submodule
Submodule src/SharpIR added at ef4ed01819
Reference in New Issue
Block a user