![]() |
Can Opener - ME 507
|
Class that reads temperature over I2C from the MCP9808 temperature sensor. More...
#include <TempSensor.h>
Public Member Functions | |
| TempSensor (uint8_t scl, uint8_t sda, uint8_t add) | |
| Constructor for the TempSensor class. More... | |
| float | getTempC () |
| Gets the temperature in Celsius from the sensor. More... | |
| float | getTempF () |
| Returns the temperature in Fahrenheit. More... | |
| uint16_t | getManuCode () |
| Returns the manufacturer code from the MCP9808. More... | |
Protected Attributes | |
| uint8_t | scl_pin |
| SCL pin. | |
| uint8_t | sda_pin |
| SDA Pin. | |
| uint8_t | address |
| I2C address. | |
| const uint8_t | temp = 0x05 |
| Temp Value Register address. | |
| const uint8_t | manu = 0x06 |
| Manufacturer Value register address. | |
Class that reads temperature over I2C from the MCP9808 temperature sensor.
This class contains the functions to read the temperature from the different registers on the sensors. This class cannot use all the functions of the MCP9808, like temperature alerts and such, but it does have core funtionality
| TempSensor::TempSensor | ( | uint8_t | scl, |
| uint8_t | sda, | ||
| uint8_t | addr | ||
| ) |
Constructor for the TempSensor class.
This constructor takes in the address, scl, and sda pins for connecting to the MCP9808 sensor. The address is set with the address pins, and off of the base address of the MCP 9808. This base address is 0x18, but can be changed from 0x18 to 0x1F depending on the address pins. Look at the datasheet for more info - https://cdn-shop.adafruit.com/datasheets/MCP9808.pdf
| scl | The SCL pin for I2C communication |
| sda | The SDA pin for I2C communication |
| addr | The address of the MCP9808 sensor |
| uint16_t TempSensor::getManuCode | ( | ) |
Returns the manufacturer code from the MCP9808.
This function is used to ensure proper connection to the MCP9808 sensor. This function, if the sensor is connected correctly, should return 0x54
| float TempSensor::getTempC | ( | ) |
Gets the temperature in Celsius from the sensor.
The algorithm for getting the temperature in C is found in the datasheet. Reading from the I2C bus would not have been possible without the people here: https://forum.arduino.cc/t/how-to-read-a-register-value-using-the-wire-library/206123
| float TempSensor::getTempF | ( | ) |
Returns the temperature in Fahrenheit.
This function just calls TempSensor::getTempC() and then converts to Fahrenheit