In this short tutorial I'm going to show to you how to implement , in the Arduino UNO environment, the basic functionalities to work with the TCN75.
Materials needed for this tutorial.
- 1 Arduino UNO board (naturally)
- Arduino IDE (naturally)
- 1 TCN75 (naturally I'll use my own board, see related posts)
- 4 jumper cables
Our tcn75 board is described here:
- Working with the RTCC MCP 79410 RTCC (Real Time Clock with Calendar)
- How to use the i2c bus with PIC12f1840 (a simple library)
- Temperature sensor and real time clock for Arduino
- A PIC 12f1840 developer board with mcp79410 RTC and tcn75 temperature sensor.
Ok let's start
The TCN75 works trough the i2c bus, so what is the i2c bus?
I2C is an acronym for “Inter-Integrated Circuit”. In the late 1970s, Philips’ semiconductor division (now NXP) saw the need for simplifying and standardising the data lines that travel between various integrated circuits in their products. Their solution was the I2C bus. This reduced the number of wires to two (SDA – data, and SCL – clock). Here is a nice introductory video from NXP
From a hardware perspective, the wiring is very easy. Those of you with an Arduino Duemilanove, Uno or 100% compatible board, you will be using pins A4 for SDA (data) and A5 for SCL (clock).
If you are using an Arduino Mega, SDA is pin 20 and SCL is 21, so note that shields with I2C need to be specifically for the Mega. If you have another type of board, check your data sheet or try the Arduino team’s hardware website. And finally, if you are using a bare DIP ATmega328-PU microcontroller, you will use pins 27 for SDA and 28 for SCL.
Connecting Arduino to the TCN75 board
In the following table you'll find all the connections between Arduino and the TCN75 board
That's all, now you only need to connect the USB plug to Arduino and to your PC. You should see the red led on the TCN75 lightned
First of all we need a function to convert temperature (TCN75 format) to Celsius (float).
float tcn75_convertTemp(byte aa, byte bb);
This function returns the temperature value expressed in Celsius starting from the two bytes representation of the TCN75.
To use the i2c bus Arduino needs to initialize the Wire library, so in the setup function we will put this initialization:
And to debug our code we will put also the following initialization:
Then we need to read the temperature:
In pseudo code the tcn75_getTemperature will look like the following
Here you are a simple working sample.
The TCN75 provides a lot of other complex functions such as a setpoint, alarm, goto the links at the beginning of the article to see all its functionalities