HenryHunt
HenryHunt

Reputation: 183

Converting ADC value from wind direction sensor into degrees

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

Answers (1)

TomServo
TomServo

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:

enter image description here

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.

  1. First, you must enable I2C on Linux on the Pi, for example.
  2. Consult an online tutorial on configuring and wiring the I2C device. The datasheet on Digikey for your device is a great place to start.
  3. Using the address you've selected with the pins, read the device using a python library widely available online, for example.

Upvotes: 1

Related Questions