Weather Station Wind Vane

I bought one of these:

And have got the wind speed working. I am currently trying to get the wind vane working to no avail. I am following this guide:

https://projects.raspberrypi.org/en/projects/build-your-own-weather-station/7

The wind vane I have also uses reid switches in combination with resistors to calculate wind direction, but the code in the tutorial im following only produces 2 results, when 16 should be coming through. This is the code:

from gpiozero import MCP3008
import time
adc = MCP3008(channel=0)
count = 0
values = []
while True:
	wind = round(adc.value*3.3,1)
	if not wind in values:
		values.append(wind)
		count+=1
		print(count)

I should be getting results:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16

But I am only getting result:

1
2

I have tried changing the value of the resistor used on channel 0 of the MCP3008 and it does give closer results, but never upto the full 16 voltage combinations I should have.

Any ideas?

Thanks,

Jeroth

1 Like

Hi Jeroth,

Great work on your project so far. While you may have done this already, I’d examine each step in the chain to make sure it’s working:

  • Have you tested the output of the vane with a multimeter to confirm what voltages you get back?
  • Have you tried printing the raw ADC values to make sure that’s working fine?

Keen to see your results from this so we can better debug your code :slight_smile:

1 Like

Dont have a multimeter, may have to buy one then. As for:

  • Have you tried printing the raw ADC values to make sure that’s working fine?

How would I go about this? Running the code with nothing connected to the MCP3008 Analog in? If so ive done this and got the required 1 - 16 output from the code.

Thanks,

Jeroth

Hi Jeroth,

To print the raw ADC you can try a script like the following, which will print both the raw ADC value and the scaled value between 0 and 3.3 volts, every 200 milliseconds.

from gpiozero import MCP3008
import time
adc = MCP3008(channel=0)
while True:
    raw_adc = adc.value
    scaled_adc = raw_adc * 3.3
    rounded_adc = round(scaled_adc, 1)
    
    print("Raw ADC", raw_adc)  # Should be a number between 0 and 1, likely with a bit of noise
    print("Scaled ADC", scaled_adc)  # Should be a number between 0 and 3.3, likely with a bit of noise
    print("Rounded ADC", rounded_adc)  # Should be a number between 0 and 3.3, rounded to help reduce the noise
    time.sleep_ms(200)

If you run the script while slowly turning the vane 360 degrees you should be able to observe the change in raw readings - at each of the 16 steps of the vane you should see a distinct step/change in the ADC readings.

If you’re not getting 16 distinct readings - e.g. it’s maxing out at 3.3 after one or two positions - it will be helpful to see some pictures of how you have it all wired up, and also a report of the raw readings at each vane position.

Cheers,

Jacob

1 Like

Thanks for the reply, Il give this a shot and report back.