{"id":7,"date":"2010-06-13T13:27:48","date_gmt":"2010-06-13T13:27:48","guid":{"rendered":"http:\/\/jpwed.com\/Wordpress\/?p=7"},"modified":"2010-06-26T20:26:39","modified_gmt":"2010-06-26T20:26:39","slug":"thermometer-and-clock","status":"publish","type":"post","link":"https:\/\/paulsarduino.co.uk\/?p=7","title":{"rendered":"Thermometer and Clock"},"content":{"rendered":"<figure id=\"attachment_28\" aria-describedby=\"caption-attachment-28\" style=\"width: 150px\" class=\"wp-caption alignright\"><a href=\"http:\/\/paulsarduino.co.uk\/wp-content\/uploads\/2010\/06\/schematic.jpg\"><img loading=\"lazy\" decoding=\"async\" class=\"size-thumbnail wp-image-28 \" title=\"schematic\" src=\"http:\/\/paulsarduino.co.uk\/wp-content\/uploads\/2010\/06\/schematic-150x150.jpg\" alt=\"\" width=\"150\" height=\"150\" \/><\/a><figcaption id=\"caption-attachment-28\" class=\"wp-caption-text\">Schematic view - click for full sized version<\/figcaption><\/figure>\n<p>So, for our first trick we thought we&#8217;d try and conjour up a thermometer, and then we added a clock as well &#8211; just for good measure.<\/p>\n<p>Pretty much all the parts came from <a title=\"Cool Components\" href=\"http:\/\/cool-components.co.uk\/\" target=\"_blank\">Cool Components<\/a> or Maplin. I got a cheap 2 line display on sale which was the starting point, then wondered what we could create to educate&#8230;<\/p>\n<p>The LCD interface is through 3 wires and a 4094 shift register. I&#8217;ve taken the example 3 wire LCD code from the arduino playground at <a title=\"Arduino Playground\" href=\"http:\/\/www.arduino.cc\/playground\/Code\/LCD3wires\" target=\"_blank\">http:\/\/www.arduino.cc\/playground\/Code\/LCD3wires<\/a> and modified and extended it a little to provide some positioning functions and improve the number drawing code.<\/p>\n<h2>Schematic and Breadboard<\/h2>\n<figure id=\"attachment_8\" aria-describedby=\"caption-attachment-8\" style=\"width: 300px\" class=\"wp-caption aligncenter\"><a href=\"http:\/\/paulsarduino.co.uk\/wp-content\/uploads\/2010\/06\/annotated.jpg\"><img loading=\"lazy\" decoding=\"async\" class=\"size-medium wp-image-8\" title=\"Breadboard view\" src=\"http:\/\/paulsarduino.co.uk\/wp-content\/uploads\/2010\/06\/annotated-300x197.jpg\" alt=\"\" width=\"300\" height=\"197\" srcset=\"https:\/\/paulsarduino.co.uk\/wp-content\/uploads\/2010\/06\/annotated-300x197.jpg 300w, https:\/\/paulsarduino.co.uk\/wp-content\/uploads\/2010\/06\/annotated.jpg 809w\" sizes=\"auto, (max-width: 300px) 100vw, 300px\" \/><\/a><figcaption id=\"caption-attachment-8\" class=\"wp-caption-text\">The breadboard version<\/figcaption><\/figure>\n<h2>Explanation<\/h2>\n<p>The thermometer functionality comes from TMP102 module which is connected through an I2C bus, implemented with the Wired library. The I2C interface is very easy to use, call<\/p>\n<pre style=\"padding-left: 30px;\">Wired.begin<\/pre>\n<p>in setup() to initialise it, then its a simple case of reading the latest temperature values. The addressing here assumes that the ADD0 line on the module is pulled to ground:<\/p>\n<pre style=\"padding-left: 30px;\">\/\/ Temperature module commands and registers\r\nint\u00a0 TMP_RD = 0x91;\r\nint\u00a0 TMP_WR = 0x90; \/\/Assume ADR0 is tied to VCC\r\nint\u00a0 TEMP_REG = 0x00;\r\nint\u00a0 TEMP_ADDR = 0b1001000;\r\n\r\nint ReadTemperature()\r\n{\r\n int\u00a0 val_h = 0;\r\n int\u00a0 val_l = 0;\r\n\r\n Wire.requestFrom(TEMP_ADDR, 2);\r\n val_h = Wire.receive();\r\n val_l = Wire.receive();\r\n\r\n  \/\/\u00a0 calc temp in C\r\n int tempint = ((val_h &lt;&lt; 8 ) | val_l) &gt;&gt; 4;\u00a0\u00a0 \u00a0\u00a0 \/\/ combine and shift\r\n float tempflt = float( tempint ) * .0625; \/\/ calculate actual temperature per chip doc\r\n return int(tempflt);\r\n}<\/pre>\n<p>The clock works by using the <em>millis()<\/em> function\u00a0 to establish a base time and a corresponding millisecond count &#8211; then we can update the display anytime by calculating the time since a known base. If the millis() wraps we adjust the base to the last known good value and go from that. There will be a little bit of creep there but only once every 1193 hours ish&#8230;\u00a0 Clock adjustment is through two switches which pull digital inputs to ground &#8211; if they are low we increment the base <em>Hours<\/em> or <em>Minutes<\/em> value depending which button is pressed. The internal pull up resistors are used to ensure the inputs don&#8217;t float about when the button isn&#8217;t pressed, here&#8217;s an extract:<\/p>\n<pre style=\"padding-left: 30px;\">\/\/ set up input\r\n pinMode(HOURS,INPUT);\r\n digitalWrite(HOURS, HIGH);\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 \/\/ turn on pullup resistor\r\n\r\n\/\/Adjust the clock\r\n boolean\u00a0\u00a0\u00a0 bRet = false;         \/\/ was an adjustment made\r\n if (digitalRead(HOURS) == LOW)\u00a0\u00a0 \/\/ read the input switch\r\n {\r\n   iBaseH++;\r\n   if (iBaseH &gt; 23)\r\n   {\r\n     iBaseH = 0;\r\n   }\r\n   bRet = true;\r\n }<\/pre>\n<p>After that all you need to do\u00a0 is just get data for the temperature or the time and then call the display routines.<\/p>\n<p>The code for the <a title=\"Source code\" href=\"http:\/\/paulsarduino.co.uk\/?page_id=19\" target=\"_self\">whole thing is here.<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>So, for our first trick we thought we&#8217;d try and conjour up a thermometer, and then we added a clock as well &#8211; just for good measure. Pretty much all the parts came from Cool Components or Maplin. I got a cheap 2 line display on sale which was the starting point, then wondered what [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[3,4],"tags":[],"class_list":["post-7","post","type-post","status-publish","format-standard","hentry","category-arduino","category-arproject"],"_links":{"self":[{"href":"https:\/\/paulsarduino.co.uk\/index.php?rest_route=\/wp\/v2\/posts\/7","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/paulsarduino.co.uk\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/paulsarduino.co.uk\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/paulsarduino.co.uk\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/paulsarduino.co.uk\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=7"}],"version-history":[{"count":17,"href":"https:\/\/paulsarduino.co.uk\/index.php?rest_route=\/wp\/v2\/posts\/7\/revisions"}],"predecessor-version":[{"id":44,"href":"https:\/\/paulsarduino.co.uk\/index.php?rest_route=\/wp\/v2\/posts\/7\/revisions\/44"}],"wp:attachment":[{"href":"https:\/\/paulsarduino.co.uk\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=7"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/paulsarduino.co.uk\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=7"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/paulsarduino.co.uk\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=7"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}