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’ll load it here if/when I find it.
To use this, you will need to place an include in your python program:
from wind_dir import wind_dir
Then when you want to get the value, you call the function with your ADC reading:
wind_direction = wind_dir(wind_dir_read)
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 & min values established through testing:
#!/usr/bin/env python
wind_dir_high_NNE=962
wind_dir_high_NE=937
wind_dir_high_ENE=885
wind_dir_high_E=839
wind_dir_high_ESE=798
wind_dir_high_SE=760
wind_dir_high_SSE=726
wind_dir_high_S=695
wind_dir_high_SSW=667
wind_dir_high_SW=641
wind_dir_high_WSW=616
wind_dir_high_W=593
wind_dir_high_WNW=571
wind_dir_high_NW=550
wind_dir_high_NNW=535
wind_dir_low_NNE=935
wind_dir_low_NE=884
wind_dir_low_ENE=838
wind_dir_low_E=797
wind_dir_low_ESE=759
wind_dir_low_SE=725
wind_dir_low_SSE=694
wind_dir_low_S=666
wind_dir_low_SSW=640
wind_dir_low_SW=615
wind_dir_low_WSW=592
wind_dir_low_W=570
wind_dir_low_WNW=549
wind_dir_low_NW=534
wind_dir_low_NNW=527
def wind_dir(amt):
if amt <= wind_dir_high_NNE and amt >= wind_dir_low_NNE:
wind_direction = 'NNE'
elif amt <= wind_dir_high_NE and amt >= wind_dir_low_NE:
wind_direction = 'NE'
elif amt <= wind_dir_high_ENE and amt >= wind_dir_low_ENE:
wind_direction = 'ENE'
elif amt <= wind_dir_high_E and amt >= wind_dir_low_E:
wind_direction = 'E'
elif amt <= wind_dir_high_ESE and amt >= wind_dir_low_ESE:
wind_direction = 'ESE'
elif amt <= wind_dir_high_SE and amt >= wind_dir_low_SE:
wind_direction = 'SE'
elif amt <= wind_dir_high_SSE and amt >= wind_dir_low_SSE:
wind_direction = 'SSE'
elif amt <= wind_dir_high_S and amt >= wind_dir_low_S:
wind_direction = 'S'
elif amt <= wind_dir_high_SSW and amt >= wind_dir_low_SSW:
wind_direction = 'SSW'
elif amt <= wind_dir_high_SW and amt >= wind_dir_low_SW:
wind_direction = 'SW'
elif amt <= wind_dir_high_WSW and amt >= wind_dir_low_WSW:
wind_direction = 'WSW'
elif amt <= wind_dir_high_W and amt >= wind_dir_low_W:
wind_direction = 'W'
elif amt <= wind_dir_high_WNW and amt >= wind_dir_low_WNW:
wind_direction = 'WNW'
elif amt <= wind_dir_high_NW and amt >= wind_dir_low_NW:
wind_direction = 'NW'
elif amt <= wind_dir_high_NNW and amt >= wind_dir_low_NNW:
wind_direction = 'NNW'
else:
wind_direction = 'N'
return wind_direction
As you can see from the above, I get all the way down to the minor directions such as “NNE” & “ESE”, etc. You can change it to suit your needs.
No comments