Skip to content

Instantly share code, notes, and snippets.

@memory
Created January 17, 2021 15:20
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save memory/64e5ec0f09fe729facbfe66612d34a68 to your computer and use it in GitHub Desktop.
Save memory/64e5ec0f09fe729facbfe66612d34a68 to your computer and use it in GitHub Desktop.
Sparkfun ESP32 Thing Plus + Sparkfun MCP9600 temperature sensor configuration for esphome
#include "esphome.h"
#include "SparkFun_MCP9600.h"
using namespace esphome;
class SFMCP9600 : public PollingComponent {
public:
MCP9600 myself;
Sensor *thermocouple_sensor = new Sensor();
Sensor *ambient_sensor = new Sensor();
// Update every 5s
SFMCP9600() : PollingComponent(5000) { }
void setup() override {
myself.begin();
delay(100);
myself.available();
}
void update() override {
float thermocoupleTemperature = myself.getThermocoupleTemp(false);
thermocouple_sensor->publish_state(thermocoupleTemperature);
float ambientTemperature = myself.getAmbientTemp(false);
ambient_sensor->publish_state(ambientTemperature);
}
};
esphome:
name: livingroom_radiator
platform: ESP32
board: esp32thing
libraries:
- "SparkFun MCP9600 Thermocouple Library"
includes:
- SparkFun_MCP9600.h # https://github.com/sparkfun/SparkFun_MCP9600_Arduino_Library/blob/master/src/SparkFun_MCP9600.h
- mcp9600.h
wifi:
ssid: "mywifinetwork"
password: "mywifipassphrase"
api:
reboot_timeout: 0s
# Enable logging
logger:
i2c:
sda: 23
scl: 22
scan: True
id: bus_a
sensor:
platform: custom
lambda: |-
auto mcp9600 = new SFMCP9600();
App.register_component(mcp9600);
return {mcp9600->thermocouple_sensor, mcp9600->ambient_sensor};
sensors:
- name: "Thermocouple Temperature"
unit_of_measurement: "°F"
accuracy_decimals: 2
- name: "Ambient Temperature"
unit_of_measurement: "°F"
accuracy_decimals: 2
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment