MAX31855开发板使用
MAX31855
The MAX31855 is a sophisticated thermocouple-to-digital converter with a built-in 14-bit analog-to-digital converter
Drive CS low to output the first bit on the SO pin. A complete serial-interface read of the cold-junction compensated thermocouple temperature requires 14 clock cycles. Thirty-two clock cycles are required to read both the thermocouple and reference junction temperatures From above graphic, it can be seen MAX31855 SPI mode 0.
D13~D18 is thermal coupler hot point temperature.
MAX31855 | Arduino | Function |
---|---|---|
Vin | 5V | 5V |
GND | GND | GND |
DO | 12 | MISO |
CS | 10 or other | SS |
CLK | 13 | SCK |
代码
代码修改自此链接。
打开下面的实例文件,上传到开发板。
#include <SPI.h>
//Additionally, connect the MAX6675 as follows:
//MISO Arduino pin 12 //master in slave out
//SCK Arduino pin 13 //serial clock
const int CS = 10;
void setup() {
Serial.begin(9600);
pinMode(CS, OUTPUT);
digitalWrite(CS, HIGH);
SPI.begin(); //initialize SPI
delay(500);
}
void loop() {
unsigned int tcData;
float temp, avgTemp;
uint32_t d = 0;
digitalWrite(CS, LOW);
SPI.beginTransaction(SPISettings(4300000, MSBFIRST, SPI_MODE1));
tcData = SPI.transfer(0x00) << 8;
tcData |= SPI.transfer(0x00);
digitalWrite(CS, HIGH);
if (tcData & 0x0004) { //open thermocouple circuit
Serial.println("Thermal Coupler Open.");
}
else {
temp = (tcData >> 3) / 4.0;
Serial.print("C = ");
Serial.println(temp);
}
delay(1000);
}
MQTT
服务器 Mosquitto
MQTT messaging for Raspberry Pi
Arduino Client, PubSubClient