{"id":141,"date":"2013-08-19T13:34:36","date_gmt":"2013-08-19T13:34:36","guid":{"rendered":"http:\/\/blog.soton.ac.uk\/pi\/?page_id=141"},"modified":"2013-08-23T16:38:10","modified_gmt":"2013-08-23T16:38:10","slug":"tmp102-temperature-sensor-breakout-board","status":"publish","type":"page","link":"https:\/\/blog.soton.ac.uk\/pi\/tmp102-temperature-sensor-breakout-board\/","title":{"rendered":"TMP102 Temperature Sensor Breakout Board"},"content":{"rendered":"<p><!--\nPRE.ctl { font-family: \"Lohit Hindi\",monospace; }P { margin-bottom: 0.21cm; }A:link {  }\n--><\/p>\n<p align=\"LEFT\"><span style=\"font-family: Times New Roman,serif\"><b>TMP102 Breakout Board \u2192 Temperature Sensor<\/b><\/span><\/p>\n<p align=\"LEFT\"><span style=\"font-family: Times New Roman,serif\">The TMP102 is an ambient temperature sensor capable of detecting .0625\u00baC changes between -25 and +85\u00b0C, with an accuracy of 0.5\u00b0C. It does all of this while only consuming 10\u00b5A. The breakout board makes it easier to connect the sensor to a breadboard and wire it up for different applications.The TMP102 is an I2C device, so it will actually tell you the temperature, not send an analog signal that you then need to interpret. <\/span><\/p>\n<p align=\"LEFT\"><a href=\"http:\/\/bildr.org\/blog\/wp-content\/uploads\/2011\/01\/tmp102.png\"><span style=\"color: #000080\"><img loading=\"lazy\" decoding=\"async\" alt=\"\" src=\"http:\/\/bildr.org\/blog\/wp-content\/uploads\/2011\/01\/tmp102.png\" width=\"590\" height=\"335\" align=\"BOTTOM\" border=\"1\" \/><\/span><\/a><\/p>\n<p align=\"LEFT\"><span style=\"font-family: Times New Roman,serif\">To use the TMP102 temperature sensor we will connect it to the Gertboard and program the Atmega chip using the Arduino IDE, in a similar way to how we did for the servo motors. The diagram is the one of Figure above, which we will need to adjust to use with the Gertboard rather that Arduino. The easiest way to connect them is to attach the TMP102 on a breadboard and then make connections on the breadboard (see the beginning of this video) http:\/\/www.youtube.com\/watch?v=UYeKRngfAmI). You will need to have the connections done for programming the ATmega chip through SPI interface, as seen in Figure 4 from the servo motors tutorial (see <\/span><span style=\"font-family: Times New Roman,serif\"><a href=\"http:\/\/blog.soton.ac.uk\/pi\/servo-motors\/\">http:\/\/blog.soton.ac.uk\/pi\/servo-motors\/<\/a>). You will also need to have two jumpers installed for serial connection, as seen in Figure 6 from the servo motor tutorial. Now you can make the connections above: <\/span><span style=\"font-family: Times New Roman,serif\"><b>3V3<\/b><\/span><span style=\"font-family: Times New Roman,serif\"> (from the top left of the Gertboard) to <\/span><span style=\"font-family: Times New Roman,serif\"><b>Vcc <\/b><\/span><span style=\"font-family: Times New Roman,serif\">on the Temp Sensor. <\/span><span style=\"font-family: Times New Roman,serif\"><b>GND <\/b><\/span><span style=\"font-family: Times New Roman,serif\">(from the pins on the right column of jumper <\/span><span style=\"font-family: Times New Roman,serif\"><b>J25<\/b><\/span><span style=\"font-family: Times New Roman,serif\"> located on the left side of the Gertboard) to <\/span><span style=\"font-family: Times New Roman,serif\"><b>GND <\/b><\/span><span style=\"font-family: Times New Roman,serif\">and <\/span><span style=\"font-family: Times New Roman,serif\"><b>ADD0 <\/b><\/span><span style=\"font-family: Times New Roman,serif\">on the TMP102. Finally Analog pin 4 (<\/span><span style=\"font-family: Times New Roman,serif\"><b>PC4 <\/b><\/span><span style=\"font-family: Times New Roman,serif\">on <\/span><span style=\"font-family: Times New Roman,serif\"><b>J25)<\/b><\/span><span style=\"font-family: Times New Roman,serif\"> to<\/span><span style=\"font-family: Times New Roman,serif\"><b> SDA<\/b><\/span><span style=\"font-family: Times New Roman,serif\"> and analog pin 5 (<\/span><span style=\"font-family: Times New Roman,serif\"><b>PC5 <\/b><\/span><span style=\"font-family: Times New Roman,serif\">on <\/span><span style=\"font-family: Times New Roman,serif\"><b>J25<\/b><\/span><span style=\"font-family: Times New Roman,serif\">) to <\/span><span style=\"font-family: Times New Roman,serif\"><b>SCL. <\/b><\/span><\/p>\n<p align=\"LEFT\"><span style=\"font-family: Times New Roman,serif\">In the code, we will need the Wire library for communicating between the Temperature Sensor and the Gertboard. The address pin (ADD0) is used to change the address the sensor is located at. This is useful if you need more than one of these connected to the same device and still call them independently even on the same bus. We are grounding this pin so that the sensor will use the address of 72 (0\u00d748 in hex). As you can see, we are not using the <b>Alert<\/b> pin so it is left unconnected.<\/span><\/p>\n<p align=\"LEFT\"><span style=\"font-family: Times New Roman,serif\">Once all the connections have been done, copy the following code into the Arduino IDE <\/span><span style=\"font-family: Times New Roman,serif\">and upload it onto the Atmega on the Gertboard. See <\/span><a href=\"http:\/\/blog.soton.ac.uk\/pi\/servo-motors\/\"><span style=\"font-family: Times New Roman,serif\">http:\/\/blog.soton.ac.uk\/pi\/servo-motors\/<\/span><\/a><span style=\"font-family: Times New Roman,serif\">for more details on how to do this. To view the temperature, open a terminal and then open <\/span><span style=\"font-family: Times New Roman,serif\"><b>minicom <\/b><\/span><span style=\"font-family: Times New Roman,serif\">by typing <\/span><span style=\"font-family: Times New Roman,serif\"><b>sudo minicom ama0. <\/b><\/span><span style=\"font-family: Times New Roman,serif\">The temperature will start displaying on the screen, updating at the interval given by the delay. <\/span><\/p>\n<pre><span style=\"font-family: Times New Roman,serif\">#include &lt;Wire.h&gt;<\/span>\r\n<span style=\"font-family: Times New Roman,serif\">int tmp102Address = 0x48;<\/span>\r\n\r\n<span style=\"font-family: Times New Roman,serif\">void setup(){<\/span>\r\n  <span style=\"font-family: Times New Roman,serif\">Serial.begin(9600); \/\/Set up serial connection at 9600 baud rate<\/span>\r\n  <span style=\"font-family: Times New Roman,serif\">Wire.begin(); \/\/Initialise the wire library<\/span>\r\n<span style=\"font-family: Times New Roman,serif\">}<\/span>\r\n\r\n<span style=\"font-family: Times New Roman,serif\">void loop(){<\/span>\r\n\r\n  <span style=\"font-family: Times New Roman,serif\">\/\/Call the function which reads the temperature in celsius<\/span>\r\n  <span style=\"font-family: Times New Roman,serif\">float celsius = getTemperature(); <\/span>\r\n  <span style=\"font-family: Times New Roman,serif\">\/\/Displays the temperature on the screen<\/span>\r\n  <span style=\"font-family: Times New Roman,serif\">Serial.print(\"Celsius: \");<\/span>\r\n  <span style=\"font-family: Times New Roman,serif\">Serial.println(celsius);<\/span>\r\n\r\n  <span style=\"font-family: Times New Roman,serif\">\/\/Converts to Fahrenheit and prints the temp in Fahrenheit on the screen<\/span>\r\n  <span style=\"font-family: Times New Roman,serif\">float fahrenheit = (1.8 * celsius) + 32;  <\/span>\r\n  <span style=\"font-family: Times New Roman,serif\">Serial.print(\"Fahrenheit: \");<\/span>\r\n  <span style=\"font-family: Times New Roman,serif\">Serial.println(fahrenheit);<\/span>\r\n\r\n  <span style=\"font-family: Times New Roman,serif\">delay(200); \/\/Controls the speed at which readings are displayed<\/span>\r\n<span style=\"font-family: Times New Roman,serif\">}<\/span>\r\n\r\n<span style=\"font-family: Times New Roman,serif\">\/\/Function reading the temp in celsius<\/span>\r\n<span style=\"font-family: Times New Roman,serif\">float getTemperature(){<\/span>\r\n  <span style=\"font-family: Times New Roman,serif\">\/\/Request two readings from the temperature sensor, specifying the address to read from and the number of readings<\/span>\r\n  <span style=\"font-family: Times New Roman,serif\">Wire.requestFrom(tmp102Address,2); <\/span>\r\n\r\n  <span style=\"font-family: Times New Roman,serif\">\/\/MSB will contain the integer part of the temperature reading<\/span>\r\n  <span style=\"font-family: Times New Roman,serif\">byte MSB = Wire.read();<\/span>\r\n  <span style=\"font-family: Times New Roman,serif\">\/\/LSB will contain the decimal part of the temperature reading<\/span>\r\n  <span style=\"font-family: Times New Roman,serif\">byte LSB = Wire.read();<\/span>\r\n\r\n  <span style=\"font-family: Times New Roman,serif\">\/\/This line maps the MSB and LSB (full explanation below)<\/span>\r\n  <span style=\"font-family: Times New Roman,serif\">int TemperatureSum = ((MSB &lt;&lt; 8) | LSB) &gt;&gt; 4; <\/span>\r\n\r\n  <span style=\"font-family: Times New Roman,serif\">\/\/Convert the temperature reading to celsius and return it<\/span>\r\n  <span style=\"font-family: Times New Roman,serif\">float celsius = TemperatureSum*0.0625;<\/span>\r\n  <span style=\"font-family: Times New Roman,serif\">return celsius;<\/span>\r\n<span style=\"font-family: Times New Roman,serif\">}<\/span><\/pre>\n<p align=\"LEFT\"><span style=\"font-family: Times New Roman,serif\"><span style=\"font-size: medium\">The line <b>int TemperatureSum = ((MSB &lt;&lt; 8) | LSB) &gt;&gt; 4; <\/b>is a bit more complicated and can be explained as follows: It maps the MSB and LSB (e.g. 24 + 0.4 = 24.4) by first extending the MSB to 16bits (MSB &lt;&lt; 8). The MSB is a byte (8bit) reading so by shifting it 8 bits to the left we will result with a 16bit number with the last 8 bits being 0. The second step is applying the OR operator which will map the LSB to the last 8 bits of MSB (which are all 0 at the moment). Finally, the TemperatureSum variable is converted into a 12bit number (by the <b>&gt;&gt; 4 <\/b>operation which shifts the number 4 bits to the left, hence the last 4 bits will be lost), which is the required format of the temperature reading.<\/span><\/span><\/p>\n<p align=\"LEFT\">http:\/\/bildr.org\/2011\/01\/tmp102-arduino\/<\/p>\n","protected":false},"excerpt":{"rendered":"<p>TMP102 Breakout Board \u2192 Temperature Sensor The TMP102 is an ambient temperature sensor capable of detecting .0625\u00baC changes between -25 and +85\u00b0C, with an accuracy of 0.5\u00b0C. It does all of this while only consuming 10\u00b5A. The breakout board makes it easier to connect the sensor to a breadboard and wire it up for different &hellip; <\/p>\n<p><a class=\"more-link block-button\" href=\"https:\/\/blog.soton.ac.uk\/pi\/tmp102-temperature-sensor-breakout-board\/\">Continue reading &raquo;<\/a><\/p>\n","protected":false},"author":84718,"featured_media":0,"parent":0,"menu_order":0,"comment_status":"closed","ping_status":"closed","template":"","meta":{"footnotes":""},"class_list":["post-141","page","type-page","status-publish","hentry","nodate"],"_links":{"self":[{"href":"https:\/\/blog.soton.ac.uk\/pi\/wp-json\/wp\/v2\/pages\/141","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/blog.soton.ac.uk\/pi\/wp-json\/wp\/v2\/pages"}],"about":[{"href":"https:\/\/blog.soton.ac.uk\/pi\/wp-json\/wp\/v2\/types\/page"}],"author":[{"embeddable":true,"href":"https:\/\/blog.soton.ac.uk\/pi\/wp-json\/wp\/v2\/users\/84718"}],"replies":[{"embeddable":true,"href":"https:\/\/blog.soton.ac.uk\/pi\/wp-json\/wp\/v2\/comments?post=141"}],"version-history":[{"count":6,"href":"https:\/\/blog.soton.ac.uk\/pi\/wp-json\/wp\/v2\/pages\/141\/revisions"}],"predecessor-version":[{"id":145,"href":"https:\/\/blog.soton.ac.uk\/pi\/wp-json\/wp\/v2\/pages\/141\/revisions\/145"}],"wp:attachment":[{"href":"https:\/\/blog.soton.ac.uk\/pi\/wp-json\/wp\/v2\/media?parent=141"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}