7 static const char *
const TAG =
"mcp9600";
9 static const uint8_t MCP9600_REGISTER_HOT_JUNCTION = 0x00;
11 static const uint8_t MCP9600_REGISTER_COLD_JUNTION = 0x02;
13 static const uint8_t MCP9600_REGISTER_STATUS = 0x04;
14 static const uint8_t MCP9600_REGISTER_SENSOR_CONFIG = 0x05;
15 static const uint8_t MCP9600_REGISTER_CONFIG = 0x06;
16 static const uint8_t MCP9600_REGISTER_ALERT1_CONFIG = 0x08;
17 static const uint8_t MCP9600_REGISTER_ALERT2_CONFIG = 0x09;
18 static const uint8_t MCP9600_REGISTER_ALERT3_CONFIG = 0x0A;
19 static const uint8_t MCP9600_REGISTER_ALERT4_CONFIG = 0x0B;
20 static const uint8_t MCP9600_REGISTER_ALERT1_HYSTERESIS = 0x0C;
21 static const uint8_t MCP9600_REGISTER_ALERT2_HYSTERESIS = 0x0D;
22 static const uint8_t MCP9600_REGISTER_ALERT3_HYSTERESIS = 0x0E;
23 static const uint8_t MCP9600_REGISTER_ALERT4_HYSTERESIS = 0x0F;
24 static const uint8_t MCP9600_REGISTER_ALERT1_LIMIT = 0x10;
25 static const uint8_t MCP9600_REGISTER_ALERT2_LIMIT = 0x11;
26 static const uint8_t MCP9600_REGISTER_ALERT3_LIMIT = 0x12;
27 static const uint8_t MCP9600_REGISTER_ALERT4_LIMIT = 0x13;
28 static const uint8_t MCP9600_REGISTER_DEVICE_ID = 0x20;
31 ESP_LOGCONFIG(TAG,
"Setting up MCP9600...");
44 bool success = this->
write_byte(MCP9600_REGISTER_STATUS, 0x00);
46 success |= this->
write_byte(MCP9600_REGISTER_CONFIG, 0x00);
47 success |= this->
write_byte(MCP9600_REGISTER_ALERT1_CONFIG, 0x00);
48 success |= this->
write_byte(MCP9600_REGISTER_ALERT2_CONFIG, 0x00);
49 success |= this->
write_byte(MCP9600_REGISTER_ALERT3_CONFIG, 0x00);
50 success |= this->
write_byte(MCP9600_REGISTER_ALERT4_CONFIG, 0x00);
51 success |= this->
write_byte(MCP9600_REGISTER_ALERT1_HYSTERESIS, 0x00);
52 success |= this->
write_byte(MCP9600_REGISTER_ALERT2_HYSTERESIS, 0x00);
53 success |= this->
write_byte(MCP9600_REGISTER_ALERT3_HYSTERESIS, 0x00);
54 success |= this->
write_byte(MCP9600_REGISTER_ALERT4_HYSTERESIS, 0x00);
55 success |= this->
write_byte_16(MCP9600_REGISTER_ALERT1_LIMIT, 0x0000);
56 success |= this->
write_byte_16(MCP9600_REGISTER_ALERT2_LIMIT, 0x0000);
57 success |= this->
write_byte_16(MCP9600_REGISTER_ALERT3_LIMIT, 0x0000);
58 success |= this->
write_byte_16(MCP9600_REGISTER_ALERT4_LIMIT, 0x0000);
68 ESP_LOGCONFIG(TAG,
"MCP9600:");
70 LOG_UPDATE_INTERVAL(
this);
72 ESP_LOGCONFIG(TAG,
" Device ID: 0x%x", this->
device_id_);
77 switch (this->error_code_) {
79 ESP_LOGE(TAG,
"Connected device does not match a known MCP9600 or MCP901 sensor");
82 ESP_LOGE(TAG,
"Failed to update device configuration");
92 uint16_t raw_hot_junction_temperature;
93 if (!this->
read_byte_16(MCP9600_REGISTER_HOT_JUNCTION, &raw_hot_junction_temperature)) {
97 float hot_junction_temperature = int16_t(raw_hot_junction_temperature) * 0.0625;
102 uint16_t raw_cold_junction_temperature;
103 if (!this->
read_byte_16(MCP9600_REGISTER_COLD_JUNTION, &raw_cold_junction_temperature)) {
107 float cold_junction_temperature = int16_t(raw_cold_junction_temperature) * 0.0625;
bool read_byte_16(uint8_t a_register, uint16_t *data)
sensor::Sensor * cold_junction_sensor_
void status_set_warning(const char *message="unspecified")
void dump_config() override
enum esphome::mcp9600::MCP9600Component::ErrorCode NONE
MCP9600ThermocoupleType thermocouple_type_
void status_clear_warning()
void publish_state(float state)
Publish a new state to the front-end.
bool write_byte(uint8_t a_register, uint8_t data, bool stop=true)
virtual void mark_failed()
Mark this component as failed.
Implementation of SPI Controller mode.
bool write_byte_16(uint8_t a_register, uint16_t data)
sensor::Sensor * hot_junction_sensor_