{"id":757,"date":"2019-02-06T15:22:10","date_gmt":"2019-02-06T23:22:10","guid":{"rendered":"http:\/\/ismellsmoke.net\/\/?p=757"},"modified":"2019-02-06T15:22:10","modified_gmt":"2019-02-06T23:22:10","slug":"am2315-update","status":"publish","type":"post","link":"https:\/\/ismellsmoke.net\/?p=757","title":{"rendered":"AM2315 Update"},"content":{"rendered":"\n<p>Hello to all my smoke-eating Maker friends. O&#8217;l Sopwith has a story to tell. In my February 1st post, I posted the pure Python source code and updated the implementation documentation for the ever-so-popular AM2315 temperature sensor.<\/p>\n\n\n\n<p>I did this after receiving an Email from a fellow Maker who wanted to know why my sample AM2315 code did not work with Python3. The day after I published that blog entry, a <a href=\"https:\/\/ismellsmoke.net\/\/?p=725#comment-25484\" target=\"_blank\" rel=\"noreferrer noopener\" aria-label=\"comment (opens in a new tab)\">comment<\/a> was posted stating they could not get their sensor working. The AM2315 was visible in the <em>i2cdetect<\/em> test, but it would not return any data. The Python code crashed and burned.<\/p>\n\n\n\n<p>About a week of communicating back-and-forth to troubleshoot the problem, this is what we did:<\/p>\n\n\n\n<ul class=\"wp-block-list\"><li>Turned on Debug mode in the python script<\/li><li>Made sure the device was wired correctly<\/li><li>Made sure the correct software was installed<\/li><li>Disconnected all other devices from the Pi<\/li><li>Ran the SwitchDoc Labs test script (same stack trace)<\/li><li>Ensured the Pi had a 2.0 amp power supply<\/li><\/ul>\n\n\n\n<p>About the same time this was going on, the mate who asked about the Python3 port downloaded and tested the new code. He could not get it to work either. Thinking he had a bad sensor, he set up a test harness and tested his sensor on an Arduino. It worked fine. After some fiddling around, he determined the MAXREADATTEMPT = 3 on line 23 was too small a value. He changed it to 10, and his sensor worked fine.<\/p>\n\n\n\n<!--more-->\n\n\n\n<p>This code change immediately fixed the other problem I was working on. I have updated my source code and reposted it to reflect this change.<\/p>\n\n\n\n<p>It interesting to me that the MAXREADATTEMPT = 3 setting worked fine with my AM2315. I have never had it fail. It clearly does not work with some other devices.<\/p>\n\n\n\n<p>The technical reason for this is due to the fact that the digital output of the Pi GPIO was really never meant to work with a device like the AM2315. Because of timing issues, in software, the Pi has to do what is called &#8216;bit-banging.&#8217; This essentially means you have to shoot signals to the device and hope the timing signals are &#8216;close enough&#8217; to get it to respond. If the timing is off, then you either get back no response or garbage. That is why you have to use a loop to try multiple times to get the right response.<\/p>\n\n\n\n<p>The default loop value in the original code only tried 3 times and this was not enough for some devices. I am glad that two Makers can move on with their projects and put the AM2315 to work.<\/p>\n\n\n\n<p>Lesson learned? Never, ever give up on a problem until you solve it. Don&#8217;t be intimidated because you do not know what to do. Try something! Also &#8211; ask for help. One more thing &#8211; most electronic devices today are manufactured to such high standards, they rarely fail. If they are going to fail, they usually do so in the first few hours of use. Most of the time in the first few minutes. After that, they almost always provide years of service.<\/p>\n\n\n\n<p>Unless of course, you do something that makes them emit smoke. <\/p>\n\n\n\n<p><em>Sopwith<\/em><\/p>\n\n\n\n<p><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Hello to all my smoke-eating Maker friends. O&#8217;l Sopwith has a story to tell. In my February 1st post, I posted the pure Python source code and updated the implementation documentation for the ever-so-popular AM2315 temperature sensor. I did this &hellip; <a href=\"https:\/\/ismellsmoke.net\/?p=757\">Continue reading <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[9,11,6,3],"tags":[],"class_list":["post-757","post","type-post","status-publish","format-standard","hentry","category-code","category-education","category-how-to","category-raspberry-pi"],"_links":{"self":[{"href":"https:\/\/ismellsmoke.net\/index.php?rest_route=\/wp\/v2\/posts\/757","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/ismellsmoke.net\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/ismellsmoke.net\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/ismellsmoke.net\/index.php?rest_route=\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/ismellsmoke.net\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=757"}],"version-history":[{"count":3,"href":"https:\/\/ismellsmoke.net\/index.php?rest_route=\/wp\/v2\/posts\/757\/revisions"}],"predecessor-version":[{"id":760,"href":"https:\/\/ismellsmoke.net\/index.php?rest_route=\/wp\/v2\/posts\/757\/revisions\/760"}],"wp:attachment":[{"href":"https:\/\/ismellsmoke.net\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=757"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/ismellsmoke.net\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=757"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/ismellsmoke.net\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=757"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}