Skip to content
This repository was archived by the owner on Mar 25, 2021. It is now read-only.

Wrapper for TempProbe #11

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Gemfile
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
source 'https://rubygems.org'
gem 'arduino_ci', git: 'https://github.com/Arduino-CI/arduino_ci.git', branch: 'master'
gem 'arduino_ci'
4 changes: 4 additions & 0 deletions scripts/install_libraries.sh
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@ export SHALLOW='--depth 1 --branch master --single-branch '
# use this if you started with SHALLOW and now want the full repository with history
# git fetch --unshallow

# ensure we have `arduino_ci`
bundle config --local path vendor/bundle
bundle install

# set up directories
bundle exec ensure_arduino_installation.rb
cd $(bundle exec arduino_library_location.rb)
Expand Down
26 changes: 26 additions & 0 deletions src/Devices/TempProbe_TC.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
#include "Devices/TempProbe_TC.h"

// class instance variables
/**
* static variable for singleton
*/
TempProbe_TC* TempProbe_TC::_instance = nullptr;

// class methods
/**
* static member function to return singleton
*/
TempProbe_TC* TempProbe_TC::instance() {
if (!_instance) {
_instance = new TempProbe_TC();
}
return _instance;
}

// instance methods
/**
* constructor (private so clients use the singleton)
*/
TempProbe_TC::TempProbe_TC() {
thermo.begin(MAX31865_3WIRE); // Start pt100 temperature probe with 3 wire configuration
}
118 changes: 118 additions & 0 deletions src/Devices/TempProbe_TC.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,118 @@
/**
* Adafruit MAX31865
* The Adafruit MAX31865 is an external device that connects to a thermocouple (temperature
* sensor), and has pins that can be used to read a resistance, temperature, or fault. The
* associated library has a simple API as described below.
*
* Device I/O:
* This device has 5 pins: Vin (3V or 5V powersupply, the same as the
* microcontroler), GND (Ground), CLK (Clock), SDO (MOSI: Master Out Slave In),
* SDI (MISO: Master In Slave Out), and CS (Slave Select).
*
* Connection with the thermocouple:
* The Adafruit MAX31865 can connect to three different types of thermocouples,
* two wire, three wire, or four wire. You'll need to look at the sensor's
* documentation to find the wiring requirments. The board has four pins used
* for connection with the thermocouple, they are labeled on the board: RTD+
* (Resistance Positive), RTD- (Resistance Negative), F+ (Fault Plus), and F-
* (Fault Negative).
*
* Using Adafruit MAX31865
* There are 5 functions needed to use Adafruit MAX31865: the constructor,
* begin(), readRTD() (Read Resistance), temperature(), readFault(), and
* clearFault().
*
* Here is a description of those functions:
*
* Constructor:
* To use the constructor you will have to set which pins you want to use, the
* functions are labled below. Adafruit_MAX31865 thermo = Adafruit_MAX31865(CS
* (Slave Select), DI (MOSI), DO (MISO), CLK (Clock));
*
* Begin:
* Call this after calling the constructor and before anything else. Returns
* true if successful. Default is a 2 wire thermocouple but you can specify 2,3,
* and 4 wire by passing in MAX31865_2WIRE, MAX31865_3WIRE, and MAX31865_4WIRE.
* bool successful = thermo.begin(max31865_numwires_t x = MAX31865_2WIRE);
*
* Read Resistance:
* Returns the resitance of the device.
* uint16_t rtd = thermo.readRTD();
*
* Get Temperature:
* To get the temperature you will need to know the Nominal Resistance, and the
* Resistor Reference of your temperature sensor. This must be set according to
* your thermocouple. Read your thermocouple
* manual to find these values.
* float temp = thermo.temperature(float RTDnominal, float refResistor)
*
* Read Fault:
* Returns a fault number in hex. You can compare with returned fault with the
* defualt fault values given below uint8_t fault = thermo.readFault();
*
* Faults:
* MAX31865_FAULT_HIGHTHRESH (RTD High Threshold)
* MAX31865_FAULT_LOWTHRESH (RTD Low Threshold)
* MAX31865_FAULT_REFINLOW (REFIN- > 0.85 x Bias)
* MAX31865_FAULT_REFINHIGH (REFIN- < 0.85 x Bias - FORCE- open)
* MAX31865_FAULT_RTDINLOW (RTDIN- < 0.85 x Bias - FORCE- open)
* MAX31865_FAULT_OVUV (Under/Over Voltage)
*
* Clear Fault:
* Once Fault is read clear fault so that it returns to its default state of 0
* wich is no fault. thermo.clearFault();
*
* How to use the Device:
* To use the device you must call the constructor, call begin, and then you can
* either call readRTD(), or temperature(). Once you have read either, or both
* you can check for a fault, use the data accordingly, and then clear the fault
* before reading again.
*
* How to use this TempProbe_TC class:
* Call the constructor TempProbe_TC tempProbe = TempProbe_TC();
* Since this class is build for Tank Controller class, it will automatically
* set the device to a three wire thermocouple, set the pins that the tank
* controller has delegated for it, and it has values for RTDnominal, and the
* refResistore. This class is pretty straightforward and you can the functions
* and how to call them below.
*/

#pragma once
#include "Arduino.h"

#ifdef MOCK_PINS_COUNT
#include <Adafruit_MAX31865_CI.h>
#else
#include <Adafruit_MAX31865.h>
#endif

class TempProbe_TC {
public:
static TempProbe_TC* instance();

uint16_t getResistance() {
return thermo.readRTD();
}

float getTemperature() {
return thermo.temperature(RTDnominal, refResistor);
}

uint8_t readFault() {
return thermo.readFault();
}

void clearFault() {
thermo.clearFault();
}

private:
// Class variables
static TempProbe_TC* _instance;
const int RTDnominal = 100;
const int refResistor = 430;
Adafruit_MAX31865 thermo = Adafruit_MAX31865(45, 43, 41, 39);

// Methods
TempProbe_TC();
};
28 changes: 28 additions & 0 deletions test/TempProbe_TC_Test.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
#include <TempProbe_TC.h>

#include "Arduino.h"
#include "ArduinoUnitTests.h"

unittest(TempProbe_Test) {
// Instance
TempProbe_TC* tempProbe = TempProbe_TC::instance();

// Test getResistance()
uint16_t testRTD = tempProbe->getResistance();
assertEqual(0, testRTD);

// Test getTemperature()
float testTemp = tempProbe->getTemperature();
assertEqual(-242, (int)testTemp);

// Test readFault()
uint8_t testFault = tempProbe->readFault();
assertEqual(0, testFault);

// Test clearFault()
tempProbe->clearFault();
testFault = tempProbe->readFault();
assertEqual(0, testFault);
}

unittest_main()