Using the MCP9808 Temperature Sensor In Flowcode
Updated: Apr 17
MCP9808 digital temperature sensor converts temperatures between -20°C and +125°C.The MCP9808 comes with user-programmable registers that provide flexibility for temperature sensing applications. The registers allow user-selectable settings such as Shutdown or Low-Power modes and the specification of temperature Alert window limits and critical output limits. When the temperature changes beyond the specified boundary limits, the MCP9808
outputs an Alert signal. The user has the option of setting the Alert output signal polarity as an active-low or active high comparator output for thermostat operation, or as a temperature Alert interrupt output for microprocessor based systems. The Alert output can also be configured as a critical temperature output only.
Flowcode supports the device with various macro calls the Source code is available for users that want to refine the the macro call or adjust it to their specific needs.
The MCP9808 Component is available in the FlowcodeXchange Shop.
Using the Flowcode MCP9808 Component.
The Component Support all the adjustable and Configurations that are possible with the device the Following Macro as available.
The user needs to call the Initialize macro as a first to initialize the I2C Communication.
To Configure the MCP9808 the user needs to call the SetConfigMcp9808, the user needs to build a byte variable containing the bits as needed from the datasheet.To form the value that needs to be send to the MCP9808.The value of 0x00 is the default configuration.
The Macro's SetTempUpperlimit,SetTempLowlimit and SetTempCritical are use to set the Temperature Threshold for the Windowed operation and Alert Trigger Pin as per datasheet.Take care these are Two Compliments values.
The Read Macro's Read all the above Register back the user can use it to determine the settings of the register
There are various Flag bits that are set or cleared as the Temperature moves around the Thresholds set ,the getFlags macro return a byte value and the user should use a mask to mask out the Flag of Interest for his application.
The SetResolution sets the Temperature Reslution to 0.5,0.125.0.25 or 0.0635.
The getTemperature macro returns the Temperature capture from the MCP9808.
Example of Calling the Macrco's
The Component does not support Panel Simulation however it supports the SCADA simulation which makes it possible to communicate with the device by SCADA and have the real world value in your system simulations,
Place a I2C Injector and the Component for your SCADA device on the front Panel do the configurations/ Setting the Propeties of the Injector and SCADA device Run your Simulation and read the results as shown below.
Note: The user only needs to enter the I2C Address (7 bit number) not including the Read or Write bit ,the Macros automatically add the Read or Write bit as needed
Hardware Test Arduino UNO R3 and PIC16F18855
Flowcode Project with Graphical Interface for Monitoring and Test of the MCP9808
The download package below contains a Flowcode Project for Arduino UNO R3 and a Graphical interface which can be used to test or log temperature data from the MCP. The Flowcode project serves the purpose to show the user how to send the data over serial to the GUI this can be included in any user project this the GUI can be used in the users own projects.The important macro in the Flowcode Project is the SerialTx macro.
Save the usb_seria_gui Folder on your computer and open the folder select the PL/Icon named Usb_Serial_MCP9808 double click it (this is an executable ) the main page will open.
Before you can use the GUI you need to configure the COM Port that your VCP is using
in the right top corner is an icon of a screwdriver click this icon and the Comms configuration will open.
You have to double click on the ($CR1) interface and the following page will open,
then set your comport number and your baud rate and click OK
do the same with the second interface )$(CS2) then you have to close the GUI and reopen it the new Comport settings will be active and your micro can communicate with the GUI.
The GUI is now ready and if your micro is sending data out it will be displayed in the GUI.
The GUI show the following information.
Temperature ,can also be logged in the plotter and be saved to disk or a folder
The Upper,lower and Critical settings with the corresponding Flags.
The 3 Flags are indicated by the 3 LED's which will be ON or OFF depending on the temperature and your settings(See the MCP9808 datasheet) .
In the case below the Temperature is bigger than the set Upper Limit and also higher as the Temperature Critical Setting and both the Flags are ON.
In the case below the Temperature is smaller as the set lower limit and the Ta < Tlower LED is ON.
The GUI is a very handy tool to help to configure the MCP9808 and to monitor it operation.