{"id":3362,"date":"2020-12-15T22:38:13","date_gmt":"2020-12-15T13:38:13","guid":{"rendered":"https:\/\/programresource.net\/?p=3362"},"modified":"2020-12-15T22:38:17","modified_gmt":"2020-12-15T13:38:17","slug":"using-infrared-temperature-sensor-gy-906-mlx90614","status":"publish","type":"post","link":"https:\/\/programresource.net\/en\/2020\/12\/15\/3362.html","title":{"rendered":"Using Infrared-Temperature sensor GY-906 MLX90614"},"content":{"rendered":"\n<p>Recently, I bought cheap infrared temperature sensor, GY-906 from aliexpress, only about $5 including shipping fee.<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><a href=\"https:\/\/programresource.net\/images\/2020\/12\/P_20201213_143446_vHDR_Auto.jpg\"><img decoding=\"async\" src=\"https:\/\/programresource.net\/images\/2020\/12\/P_20201213_143446_vHDR_Auto-1024x577.jpg\" alt=\"\" class=\"wp-image-3359\" srcset=\"https:\/\/programresource.net\/images\/2020\/12\/P_20201213_143446_vHDR_Auto-1024x577.jpg 1024w, https:\/\/programresource.net\/images\/2020\/12\/P_20201213_143446_vHDR_Auto-300x169.jpg 300w, https:\/\/programresource.net\/images\/2020\/12\/P_20201213_143446_vHDR_Auto-768x433.jpg 768w, https:\/\/programresource.net\/images\/2020\/12\/P_20201213_143446_vHDR_Auto-1536x865.jpg 1536w, https:\/\/programresource.net\/images\/2020\/12\/P_20201213_143446_vHDR_Auto.jpg 1647w\" sizes=\"(max-width: 1024px) 100vw, 1024px\" \/><\/a><\/figure>\n\n\n\n<p>Adafruit MLX90614 library can be used for this module.<\/p>\n\n\n\n<p><a href=\"https:\/\/github.com\/adafruit\/Adafruit-MLX90614-Library\">https:\/\/github.com\/adafruit\/Adafruit-MLX90614-Library<\/a><\/p>\n\n\n\n<p>Communication via I2C and address is 0x5A. I thought using device is simple as other sensor device; but didn&#8217;t work as expected, returning fixed value, 1037.55.<\/p>\n\n\n\n<p>After searching through forum, found out that changing I2C frequency to 50000 makes this thing work.<\/p>\n\n\n\n<p>I can set frequency at Wire.begin if this is only device I&#8217;m using, but once I try to use OLED to show readout, OLED works but sensor stops working again.<\/p>\n\n\n\n<p>Finally, I was able to make both OLED and sensor to work by adding setClock instruction to dynamically adjust I2C frequency in Adafruit_MLX90614.cpp source code in Adafruit library.<\/p>\n\n\n\n<p>Adjust to 50000 before transmitting data to sensor, then set back to 100000 before exiting.<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: cpp; title: ; notranslate\" title=\"\">\nuint16_t Adafruit_MLX90614::read16(uint8_t a) {\n  uint16_t ret;\n\n  Wire.setClock(50000);\n  Wire.beginTransmission(_addr); \/\/ start transmission to device\n  Wire.write(a);                 \/\/ sends register address to read from\n  Wire.endTransmission(false);   \/\/ end transmission\n\n  Wire.requestFrom(_addr, (size_t)3); \/\/ send data n-bytes read\n  ret = Wire.read();                  \/\/ receive DATA\n  ret |= Wire.read() &lt;&lt; 8;            \/\/ receive DATA\n\n  uint8_t pec = Wire.read();\n  \n  Wire.setClock(100000);\n\n  return ret;\n}\n<\/pre><\/div>\n\n\n<p><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Recently, I bought cheap infrared temperature sensor, GY-906 from aliexpress, only about $5 including shipping fee. Adafruit MLX90614 library can be used for this module. https:\/\/github.com\/adafruit\/Adafruit-MLX90614-Library Communication via I2C and address is 0x5A. I thought using device is simple as other sensor device; but didn&#8217;t work as expected, returning fixed value, 1037.55. After searching through forum, found out that changing I2C frequency to 50000 makes this thing work. I can set frequency at Wire.begin if this is only device I&#8217;m using, but once I try to use OLED to show readout, OLED works but sensor stops working again. Finally, I was able to make both OLED and sensor to work &#8230;<\/p>\n","protected":false},"author":2,"featured_media":3360,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"ngg_post_thumbnail":0,"jetpack_post_was_ever_published":false,"_jetpack_newsletter_access":"","footnotes":"","jetpack_publicize_message":"","jetpack_is_tweetstorm":false,"jetpack_publicize_feature_enabled":true,"jetpack_social_post_already_shared":true,"jetpack_social_options":{"image_generator_settings":{"template":"highway","enabled":false}}},"categories":[866,868],"tags":[870,1010,1014,1013,1011,1012],"jetpack_publicize_connections":[],"jetpack_featured_media_url":"https:\/\/programresource.net\/images\/2020\/12\/P_20201213_143446_vHDR_Auto.jpg","jetpack_shortlink":"https:\/\/wp.me\/p3pJyQ-Se","jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/programresource.net\/en\/wp-json\/wp\/v2\/posts\/3362"}],"collection":[{"href":"https:\/\/programresource.net\/en\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/programresource.net\/en\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/programresource.net\/en\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/programresource.net\/en\/wp-json\/wp\/v2\/comments?post=3362"}],"version-history":[{"count":1,"href":"https:\/\/programresource.net\/en\/wp-json\/wp\/v2\/posts\/3362\/revisions"}],"predecessor-version":[{"id":3363,"href":"https:\/\/programresource.net\/en\/wp-json\/wp\/v2\/posts\/3362\/revisions\/3363"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/programresource.net\/en\/wp-json\/wp\/v2\/media\/3360"}],"wp:attachment":[{"href":"https:\/\/programresource.net\/en\/wp-json\/wp\/v2\/media?parent=3362"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/programresource.net\/en\/wp-json\/wp\/v2\/categories?post=3362"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/programresource.net\/en\/wp-json\/wp\/v2\/tags?post=3362"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}