Reputation: 183
I'm building a weather station using the raspberry pi and am trying to add the wind direction sensor (through a 12-bit ADS1015 analog to digital converter that I'm waiting to receive). I've looked around for some time on how to do this in python but was only able to get 1 piece of code working on an arduino, to convert raw values into actual wind directions, in degrees.
I now wish to do the same thing in python, on the raspberry pi.
Assuming I use a 12 bit ADC connected to 3.3 volts on the raspberry pi, how do I convert the raw signals from the ADC (gotten using adc_value = adc.read_adc(1, gain = 1)
with the Adafruit library for the ADC) into actual wind directions in degrees? The analog voltage of the sensor ranges from 5% of the input voltage (indicating 0 degrees), to 95% of the input voltage (indicating 360 degrees). I'm not sure how to map them.
Upvotes: 2
Views: 1094
Reputation: 7409
I did a bit of modeling in a spreadsheet, which is how I've derived linear mappings for such devices in the past. Assumes linearity over the range:
Graph and table demonstrates a linear range varying from 5% to 95% of potential ADC values, per the datasheet. After recording high and low points, I calculated the delta ADC per 20 degrees. I then plotted them and included the linear trendline along with the resultant y=mx+b formula. This is the conversion formula for raw ADC values (based on 3.3V) that you need to use.
Now, as to how to do this in python on the Pi, that's another matter. The device you're using is an I2C device. There are many tutorials on this topic.
Upvotes: 1