Skip to content

Commit

Permalink
Added MCO9600 Support and fixed a bug with ADS1115
Browse files Browse the repository at this point in the history
  • Loading branch information
Manuel-Sensate committed Feb 20, 2022
1 parent 7ec0c3f commit 950e242
Show file tree
Hide file tree
Showing 7 changed files with 312 additions and 5 deletions.
1 change: 1 addition & 0 deletions platformio.ini
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ lib_deps_external =
adafruit/DHT sensor [email protected]
adafruit/Adafruit ST7735 and ST7789 Library@^1.7.5
paulstoffregen/OneWire @ 2.3.6
sparkfun/SparkFun MCP9600 Thermocouple Library @ ^1.0.4

[env:NodeMCU-4M]
platform = [email protected]
Expand Down
3 changes: 2 additions & 1 deletion src/SensatioFirmware.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
SOURCE: https://github.com/sensatio/firmware-platformIO.git
@section HISTORY
v47 - Added Support for MCP9600 thermocouple sensors and fixed a bug that caused a crash if multiple ADS1115 were configured
v46 - Merge of ESP8266 and ESP32 Firmware into PlatformIO project
v45 - Fixed Pressure Measurement for BME280 Sensors
v44 - More Memory Improvements
Expand All @@ -35,7 +36,7 @@
VisualisationHelper *vHelper;
Display *display = NULL;

int currentVersion = 46;
int currentVersion = 47;
boolean printMemory = false;

#ifdef ESP8266_Generic
Expand Down
7 changes: 6 additions & 1 deletion src/controller/Bridge.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/**************************************************************************/
/*
/*!
@file Bridge.cpp
@author M. Fegerl (Sensate Digital Solutions GmbH)
@license GPL (see LICENSE file)
Expand Down Expand Up @@ -973,6 +973,11 @@ void configureExpansionPort(int portNumber, JsonObject& portConfig) {
{
addSensor(new SensorSI1145(portConfig["id"], portConfig["c"], portConfig["sn"], portConfig["n"], portConfig["ec1"], portConfig["ec2"], refreshInterval, postDataInterval, portConfig["s"]["svt"], calc));
}
else if (portConfig["et"] == "MCP9600")
{
addSensor(new SensorMCP9600(portConfig["id"], portConfig["c"], portConfig["sn"], portConfig["n"], portConfig["ec1"], portConfig["ec2"], refreshInterval, postDataInterval, portConfig["s"]["svt"], calc));
}


}

Expand Down
1 change: 1 addition & 0 deletions src/controller/Bridge.h
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@
#include "output/display/DisplayOLED128.h"
#include "output/display/DisplayST7735.h"
#include "output/VisualisationHelper.h"
#include "../input/i2c/SensorMCP9600.h"

#ifdef ESP8266_BOARD
void initSSL();
Expand Down
11 changes: 8 additions & 3 deletions src/input/i2c/Ads1x15.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
SOURCE: https://github.com/sensatio/firmware-platformIO.git
@section HISTORY
v47 - Fixed a bug that caused a crash if multiple ADS1115 were configured
v46 - Merge of ESP8266 and ESP32 Firmware into PlatformIO project
v34 - First Public Release (Feature parity with ESP8266 Release v34)
*/
Expand Down Expand Up @@ -39,6 +40,7 @@ Ads1x15::Ads1x15 (long id, String category, String shortName, String name, Strin
if ((addressString == NULL) || (addressString == "") || (addressString == "0x48")) {
if (!init48)
{
Serial.println("I48");
init48 = true;

if(type == "ADS1115")
Expand All @@ -54,10 +56,11 @@ if ((addressString == NULL) || (addressString == "") || (addressString == "0x48"
else if (addressString == "0x49") {
if (!init49)
{
Serial.println("I49");
init49 = true;

if(type == "ADS1115")
ads1x15_48 = new Adafruit_ADS1115(0x49);
ads1x15_49 = new Adafruit_ADS1115(0x49);
else
ads1x15_49 = new Adafruit_ADS1015(0x49);

Expand All @@ -70,10 +73,11 @@ if ((addressString == NULL) || (addressString == "") || (addressString == "0x48"
else if (addressString == "0x4A") {
if (!init4A)
{
Serial.println("I4A");
init4A = true;

if(type == "ADS1115")
ads1x15_48 = new Adafruit_ADS1115(0x4A);
ads1x15_4A = new Adafruit_ADS1115(0x4A);
else
ads1x15_4A = new Adafruit_ADS1015(0x4A);

Expand All @@ -85,10 +89,11 @@ if ((addressString == NULL) || (addressString == "") || (addressString == "0x48"
else if (addressString == "0x4B") {
if (!init4B)
{
Serial.println("I4B");
init4B = true;

if(type == "ADS1115")
ads1x15_48 = new Adafruit_ADS1115(0x4B);
ads1x15_4B = new Adafruit_ADS1115(0x4B);
else
ads1x15_4B = new Adafruit_ADS1015(0x4B);

Expand Down
251 changes: 251 additions & 0 deletions src/input/i2c/SensorMCP9600.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,251 @@
/**************************************************************************/
/*!
@file SensorMCP9600.h
@author M. Fegerl (Sensate Digital Solutions GmbH)
@license GPL (see LICENSE file)
The Sensatio firmware is used to connect ESP8266 and ESP32 based hardware
with the Sensatio Cloud and the Sensatio apps.
----> https://www.sensatio.io
SOURCE: https://github.com/sensatio/firmware-platformIO.git
@section HISTORY
v47 - Added Support for MCP9600 thermocouple sensors
*/
/**************************************************************************/

#include "SensorMCP9600.h"
#include "Wire.h"
#include "Adafruit_MCP9600.h"

extern boolean isResetting;
extern int powerMode;

MCP9600* SensorMCP9600::mcp9600_60;
MCP9600* SensorMCP9600::mcp9600_66;
MCP9600* SensorMCP9600::mcp9600_67;

SensorMCP9600::SensorMCP9600 (long id, String category, String shortName, String name, String i2cAdress, String sensorType, int refreshInterval, int postDataInterval, float smartValueThreshold, SensorCalculation* calculation) : Sensor (id, category, shortName, name, refreshInterval, postDataInterval, smartValueThreshold, calculation, false) {

int i=0;
failedInit = false;

Wire.setClock(100000);

if(i2cAdress=="0x67")
{
if(mcp9600_67 == NULL)
{
mcp9600_67 = new MCP9600();

mcp9600_67->begin(0x67);

while(!mcp9600_67->isConnected())
{
mcp9600_67->begin(0x67, Wire);
Serial.println("Trying to find MCP9600 sensor at address 0x67!");
delay(500);

if(i==5)
{
Serial.println("Could not find a valid MCP9600 sensor at address 0x67, check wiring!");
failedInit=true;
return;
}
i++;
}

if(sensorType=="K") {
mcp9600_67->setThermocoupleType(TYPE_K);
}
else if(sensorType=="J") {
mcp9600_67->setThermocoupleType(TYPE_J);
}
else if(sensorType=="T") {
mcp9600_67->setThermocoupleType(TYPE_T);
}
else if(sensorType=="N") {
mcp9600_67->setThermocoupleType(TYPE_N);
}
else if(sensorType=="S") {
mcp9600_67->setThermocoupleType(TYPE_S);
}
else if(sensorType=="E") {
mcp9600_67->setThermocoupleType(TYPE_E);
}
else if(sensorType=="B") {
mcp9600_67->setThermocoupleType(TYPE_B);
}
else if(sensorType=="R") {
mcp9600_67->setThermocoupleType(TYPE_R);
}

mcp9600_67->setShutdownMode(NORMAL);

}
mcp = mcp9600_67;
}
else if(i2cAdress=="0x66")
{
if(mcp9600_66 == NULL)
{
mcp9600_66 = new MCP9600();

mcp9600_66->begin(0x66);

while(!mcp9600_66->isConnected())
{
mcp9600_67->begin(0x66, Wire);
Serial.println("Trying to find MCP9600 sensor at address 0x66!");
delay(500);

if(i==5)
{
Serial.println("Could not find a valid MCP9600 sensor at address 0x66, check wiring!");
failedInit=true;
return;
}
i++;
}

if(sensorType=="K") {
mcp9600_66->setThermocoupleType(TYPE_K);
}
else if(sensorType=="J") {
mcp9600_66->setThermocoupleType(TYPE_J);
}
else if(sensorType=="T") {
mcp9600_66->setThermocoupleType(TYPE_T);
}
else if(sensorType=="N") {
mcp9600_66->setThermocoupleType(TYPE_N);
}
else if(sensorType=="S") {
mcp9600_66->setThermocoupleType(TYPE_S);
}
else if(sensorType=="E") {
mcp9600_66->setThermocoupleType(TYPE_E);
}
else if(sensorType=="B") {
mcp9600_66->setThermocoupleType(TYPE_B);
}
else if(sensorType=="R") {
mcp9600_66->setThermocoupleType(TYPE_R);
}

mcp9600_66->setShutdownMode(NORMAL);

}
mcp = mcp9600_66;
}
else
{
if(mcp9600_60 == NULL)
{
mcp9600_60 = new MCP9600();

mcp9600_60->begin();

while(!mcp9600_60->isConnected())
{
mcp9600_60->begin(0x60, Wire);
Serial.println("Trying to find MCP9600 sensor at address 0x60!");
delay(500);

if(i==5)
{
Serial.println("Could not find a valid MCP9600 sensor at address 0x60, check wiring!");
failedInit=true;
return;
}
i++;
}

if(sensorType=="K") {
mcp9600_60->setThermocoupleType(TYPE_K);
}
else if(sensorType=="J") {
mcp9600_60->setThermocoupleType(TYPE_J);
}
else if(sensorType=="T") {
mcp9600_60->setThermocoupleType(TYPE_T);
}
else if(sensorType=="N") {
mcp9600_60->setThermocoupleType(TYPE_N);
}
else if(sensorType=="S") {
mcp9600_60->setThermocoupleType(TYPE_S);
}
else if(sensorType=="E") {
mcp9600_60->setThermocoupleType(TYPE_E);
}
else if(sensorType=="B") {
mcp9600_60->setThermocoupleType(TYPE_B);
}
else if(sensorType=="R") {
mcp9600_60->setThermocoupleType(TYPE_R);
}

mcp9600_60->setShutdownMode(NORMAL);
}
mcp = mcp9600_60;
}

}

void SensorMCP9600::preCycle(int cycleId)
{
}

Data* SensorMCP9600::read(bool shouldPostData)
{
if(!isResetting && !failedInit)
{
if(_calculation->getValueUnit()=="°C")
{
float tempHotJunction = mcp->getThermocoupleTemp();
shouldPostData = smartSensorCheck(tempHotJunction, _smartValueThreshold, shouldPostData);
return _calculation->calculate(this, tempHotJunction, shouldPostData);
}
else if(_calculation->getValueUnit()=="K")
{
float delta = mcp->getTempDelta();
shouldPostData = smartSensorCheck(delta, _smartValueThreshold, shouldPostData);
return _calculation->calculate(this, delta, shouldPostData);
}
else if(_calculation->getValueType()=="pressure")
{
float tempColdJunction = mcp->getAmbientTemp();
shouldPostData = smartSensorCheck(tempColdJunction, _smartValueThreshold, shouldPostData);
return _calculation->calculate(this, tempColdJunction, shouldPostData);
}

}
return NULL;
}

boolean SensorMCP9600::smartSensorCheck(float currentRawValue, float threshhold, boolean shouldPostData)
{
if(powerMode == 3)
{
if(!shouldPostData)
{
if(!isnan(lastPostedValue))
{
if(lastPostedValue-currentRawValue>threshhold || lastPostedValue-currentRawValue<-threshhold)
{
shouldPostData = true;
}
}
}

if(shouldPostData)
lastPostedValue = currentRawValue;
}

return shouldPostData;

}


Loading

0 comments on commit 950e242

Please sign in to comment.