In this article, we are exploring the possibility of using SmartWave to capture temperature measurements using the MCP9808 Digital Temperature Sensor from Microchip. We will use I2C protocol to access the registers of the sensor and read out the measured ambient temperature.
Configuring the Temperature Sensor
The MCP9808 includes three address select pins, A0, A1, and A2. While the default I2C address is 0x18, it's essential to allocate distinct I2C addresses for each sensor when using multiple of them in an application. These address pins determine the last three bits of the I2C address and are read on power up. Therefore, changing the I2C address requires power cycling the module. For this demonstration, as we're using a single module, we'll retain the default address.
To obtain the ambient temperature using the MCP9808 sensor, direct access to the Ta register is required. This 16-bit register holds the 13-bit temperature data (<12:0>) in two’s complement format, while bits (<15:13>) indicate the state of the Alert pin. For detailed information, please refer to the manufacturer’s datasheet.
How to use SmartWave
Setting up I2C communication with SmartWave for any type of sensor is very straightforward, thanks to our user-friendly WebGUI. The WebGUI offers a simple interface for easy navigation between different driver settings, whether it's SPI or I2C.
In the driver settings, users can configure the I2C communication speed and define the device's address. Select the desired pins for SCL and SDA from the 16 configurable GPIOs on the SmartWave. Using the Pin layout in the bottom right corner of the WebGUI, users can easily choose which pins to use for I2C. All that's left to do is to connect all the lines from the SmartWave to the target device and initiate the communication process through the WebGUI. To achieve this, let's specify the data we intend to send. In the Data/Controller Write section, we can define the data we wish to transmit.
As we know, to initiate an I2C protocol, we first send a Start bit by pulling the SDA line low. This is followed by the 7-bit address, R/W bit, and ACK/NACK bit. After sending the address frame, data can be transmitted. Once all the data frames have been sent, the controller will generate a stop condition. The typical timing diagram for accessing one of the MCP9808's registers is illustrated below.
From this, it can be seen that initially, a write command is sent, succeeded by the Ta register’s address. Afterward, the content of the register can be read. Since it is a 16-bit register, we need to read two bytes: the MSB data first and then the LSB data.
We have put together a demo setup that can be easily replicated. By loading the “MCP9808_I2C_CONFIG.json” file from our GitHub repository, you will have all the necessary configurations to read the content of the Ta (ambient temperature) register.
With a simple calculation, we can convert the bits read from the register into decimal format, enabling us to determine the ambient temperature in degrees Celsius. The datasheet also includes sample code for reference.
This article provided a brief introduction to using SmartWave for interfacing with the MCP9808 temperature sensor via I2C. The demonstration aimed to showcase the simplicity of employing SmartWave for such tasks. However, there is much more to explore, and we encourage readers to delve into further possibilities.
If you found this article interesting, stay tuned for more exciting updates from semify! We're dedicated to meeting our customers' evolving needs, and we're currently developing a Python API to enhance user experience. This API will offer programmatically controlled measurements and seamless data aggregation directly in Python, providing users with greater flexibility in integrating SmartWave into their projects and workflows.
For those eager to take advantage of SmartWave's capabilities in their projects, we recommend contacting semify via email (email@example.com) for more information, product demonstrations, or to discuss specific project requirements. Additionally, you can explore other intriguing articles and demos showcasing SmartWave through the provided links.