Only seeing 8-bit values from analog input

I’m using a Davis anemometer to measure wind direction and speed. Direction is a wind vane attached to a 20k pot. I’ve plugged that into A0, and I’ve also attached power to 3.3v (3V3 pin) and ground (GND pin) appropriately. See this description of the device.

I think I should get 12 bits of resolution with the 20k pot giving values of approx 0-4096. However I only get 8-bit resolution values of 0-255.

Any ideas?

EDIT: is it that the device is expecting to scale over 5v?

Can you post the relevant code portions?
analogRead() will return values between 0 and 4095 but you’d also need to store them in an appropriate variabel.

Not seeing your code does make this a guessing game.

This is the devices internal wind direction schematic from the document you cited:
image

The document equates pin 2 to Vcc, pin 4 to Gnd, and pin 3 to the signal (analog voltage) that denotes wind direction.

Effectively, this circuit is just a voltage divider. Assuming Vcc = 3.3 volts, the signal is zero when the 20K pot is turned to zero, and the signal would be around 0.071v when the 20k pot is turned to 20k. Since analog reads range from 0 = 0v to 4095 = 3.3v, and this device returns 0 to 0.071 volts, the analog reading would range from 0 to ~88.

The problem is that the 909k resistor overpowers the 20k pot, I’m not sure of the best way to fix this. Hopefully, someone else can.

How does a 909k resistor (basically 1Meg) overpower a 20k ?

I think there is something wrong in the logic.
When you have the potentiometer turned all the way CW you'll have a voltage divider of

3.3V ━━ R1=(0k || 909k) ━┳━ R2=20k ━━ GND
                         ┃
                        Vout

giving you a voltage of 3.3V since no voltage drop occures over a parallel between any resistor with a 0Ohm resistance (3.3V * (20k / (0k + 20k))).

And going all the way CCW you'd have

3.3V ━━ R1=(20k || 909k) ━┳━ R2=0k ━━ GND
                          ┃
                         Vout

R1 = (20k * 909k) / (20k + 909k) = 19.57k

you'd expect 3.3V * (0k / (0k + 19.57k) = 0V

So you should (theoretically) get the full range 0..4095.

Hence I'd just reiterate what I said earlier

1 Like

Sorry, I was looking at the circuit wrong.

Sorry, not posting my code was bad form. Here’s the example:

#include "particle.h"

void setup() {
}

void loop() {
   int32_t direction;

   direction = analogRead(A0);
   Serial.printf("dir[%d]\n", direction);
   delay(500);
}

I’ve also noticed the values seem to have an odd distribution. The first 270 degrees returns values from 0 to 96, but the last 90 degrees goes from 96 to 255!

I put the pot on a meter off the circuit and it’s evenly distributed across the 20k ohms.

What device OS version are you using?

New Boron running DeviceOS 1.1.1.

What do you get when remove the external circuitry and leaving A0 float, connect to GND and connect to 3v3?
My Boron 2G/3G on 1.1.1 gives me the expected values between 0 and 4095.

Excellent idea… Gnd generates zero, 3v3 generates 4095, and floating generates values in between.

Must be my circuit!

2 Likes