{"id":256,"date":"2014-08-11T19:59:52","date_gmt":"2014-08-11T19:59:52","guid":{"rendered":"http:\/\/blog.cup-of-joe.me\/?p=256"},"modified":"2018-12-12T19:41:12","modified_gmt":"2018-12-12T19:41:12","slug":"wind-direction-reading","status":"publish","type":"post","link":"http:\/\/blog.cup-of-joe.me\/?p=256","title":{"rendered":"Wind Direction Reading"},"content":{"rendered":"<p>As I stated in the previous post, the readings of this sensor take a lot of work to setup.  You have to get a reading at each direction and then split the difference between them to get a high and low.  Somewhere I have an excel file that I use to do all the calculations and print out the code.  I&#8217;ll load it here if\/when I find it.  <\/p>\n<p>To use this, you will need to place an include in your python program:  <\/p>\n<p><code>from wind_dir import wind_dir<\/code><\/p>\n<p>Then when you want to get the value, you call the function with your ADC reading:<\/p>\n<p><code>wind_direction = wind_dir(wind_dir_read)<\/code><\/p>\n<p>The annoying part of this is setting up this file.  All it does is take your reading and see where it falls within the table of max &#038; min values established through testing:<\/p>\n<p><code><br \/>\n#!\/usr\/bin\/env python<\/p>\n<p>wind_dir_high_NNE=962<br \/>\nwind_dir_high_NE=937<br \/>\nwind_dir_high_ENE=885<br \/>\nwind_dir_high_E=839<br \/>\nwind_dir_high_ESE=798<br \/>\nwind_dir_high_SE=760<br \/>\nwind_dir_high_SSE=726<br \/>\nwind_dir_high_S=695<br \/>\nwind_dir_high_SSW=667<br \/>\nwind_dir_high_SW=641<br \/>\nwind_dir_high_WSW=616<br \/>\nwind_dir_high_W=593<br \/>\nwind_dir_high_WNW=571<br \/>\nwind_dir_high_NW=550<br \/>\nwind_dir_high_NNW=535<br \/>\nwind_dir_low_NNE=935<br \/>\nwind_dir_low_NE=884<br \/>\nwind_dir_low_ENE=838<br \/>\nwind_dir_low_E=797<br \/>\nwind_dir_low_ESE=759<br \/>\nwind_dir_low_SE=725<br \/>\nwind_dir_low_SSE=694<br \/>\nwind_dir_low_S=666<br \/>\nwind_dir_low_SSW=640<br \/>\nwind_dir_low_SW=615<br \/>\nwind_dir_low_WSW=592<br \/>\nwind_dir_low_W=570<br \/>\nwind_dir_low_WNW=549<br \/>\nwind_dir_low_NW=534<br \/>\nwind_dir_low_NNW=527<\/p>\n<p>def wind_dir(amt):<br \/>\n        if amt <= wind_dir_high_NNE and amt >= wind_dir_low_NNE:<br \/>\n\t\twind_direction = 'NNE'<br \/>\n\telif amt <= wind_dir_high_NE and amt >= wind_dir_low_NE:<br \/>\n\t\twind_direction = 'NE'<br \/>\n        elif amt <= wind_dir_high_ENE and amt >= wind_dir_low_ENE:<br \/>\n                wind_direction = 'ENE'<br \/>\n        elif amt <= wind_dir_high_E and amt >= wind_dir_low_E:<br \/>\n                wind_direction = 'E'<br \/>\n        elif amt <= wind_dir_high_ESE and amt >= wind_dir_low_ESE:<br \/>\n                wind_direction = 'ESE'<br \/>\n        elif amt <= wind_dir_high_SE and amt >= wind_dir_low_SE:<br \/>\n                wind_direction = 'SE'<br \/>\n        elif amt <= wind_dir_high_SSE and amt >= wind_dir_low_SSE:<br \/>\n                wind_direction = 'SSE'<br \/>\n        elif amt <= wind_dir_high_S and amt >= wind_dir_low_S:<br \/>\n                wind_direction = 'S'<br \/>\n        elif amt <= wind_dir_high_SSW and amt >= wind_dir_low_SSW:<br \/>\n                wind_direction = 'SSW'<br \/>\n        elif amt <= wind_dir_high_SW and amt >= wind_dir_low_SW:<br \/>\n                wind_direction = 'SW'<br \/>\n        elif amt <= wind_dir_high_WSW and amt >= wind_dir_low_WSW:<br \/>\n                wind_direction = 'WSW'<br \/>\n        elif amt <= wind_dir_high_W and amt >= wind_dir_low_W:<br \/>\n                wind_direction = 'W'<br \/>\n        elif amt <= wind_dir_high_WNW and amt >= wind_dir_low_WNW:<br \/>\n                wind_direction = 'WNW'<br \/>\n        elif amt <= wind_dir_high_NW and amt >= wind_dir_low_NW:<br \/>\n                wind_direction = 'NW'<br \/>\n        elif amt <= wind_dir_high_NNW and amt >= wind_dir_low_NNW:<br \/>\n                wind_direction = 'NNW'<br \/>\n\telse:<br \/>\n\t\twind_direction = 'N'<\/p>\n<p>        return wind_direction<\/p>\n<p><\/code><\/p>\n<p>As you can see from the above, I get all the way down to the minor directions such as &#8220;NNE&#8221; &#038; &#8220;ESE&#8221;, etc.  You can change it to suit your needs.  <\/p>\n","protected":false},"excerpt":{"rendered":"<p>As I stated in the previous post, the readings of this sensor take a lot of work to setup. You have to get a reading at each direction and then split the difference between them to get a high and low. Somewhere I have an excel file that I use to do all the calculations [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[3,2,7],"tags":[],"_links":{"self":[{"href":"http:\/\/blog.cup-of-joe.me\/index.php?rest_route=\/wp\/v2\/posts\/256"}],"collection":[{"href":"http:\/\/blog.cup-of-joe.me\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/blog.cup-of-joe.me\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/blog.cup-of-joe.me\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/blog.cup-of-joe.me\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=256"}],"version-history":[{"count":1,"href":"http:\/\/blog.cup-of-joe.me\/index.php?rest_route=\/wp\/v2\/posts\/256\/revisions"}],"predecessor-version":[{"id":257,"href":"http:\/\/blog.cup-of-joe.me\/index.php?rest_route=\/wp\/v2\/posts\/256\/revisions\/257"}],"wp:attachment":[{"href":"http:\/\/blog.cup-of-joe.me\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=256"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/blog.cup-of-joe.me\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=256"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/blog.cup-of-joe.me\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=256"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}