So I have a project that is using a simple voltage divider. Two 10K resistors from a 5V. When I try and read it with the Teensy, I am getting around 4.0 voltage, but I even verified it with my fluke that it is at 2.5V!!! Why would my teensy not read the proper voltage.
Here is the Code I am using. Could the ADC be screwed up? It does change when I change the voltage divider, but it kinda seems it is always 1V above the true voltage.
void setup()
{
Serial.begin(9600);
}
void loop()
{
int sensorValue = analogRead(A9);
float voltage = sensorValue * (5.0 / 1023.0);
Serial.println(voltage);
}
Is there not an on-board 3.3V regulator on the teensy board? I think 2 holes down from VIN is "3V", if you check that and it is 3.3V then yes there is a on-board regulator.
EDIT: Or set any digital output pin high and measure the voltage on that pin, whatever that voltage is should represent your reference voltage (for use in sensorValue * (5.0 / 1023.0))
I just looked at a teensy circuit diagram. This one.
Both USB in and Vin connect (via a series diode) to a voltage regulator input (inside the micro).
As far as I can see, everything runs on 3.3volt.
Leo..
I am in total agreement with you Wawa, that was what I was getting at above. I suggested doing a digitalWrite and measuring the voltage at the pin simply for the OP to determine beyond a doubt what voltage the chip is actually being supplied (as digitalWrite voltage will be equal to the voltage supplied to the chip itself, not what is supplied to the board).
BH72:
I am in total agreement with you Wawa, that was what I was getting at above. I suggested doing a digitalWrite and measuring the voltage at the pin simply for the OP to determine beyond a doubt what voltage the chip is actually being supplied (as digitalWrite voltage will be equal to the voltage supplied to the chip itself, not what is supplied to the board).
I don't get this.
Reading the chip's supply with a Vref that is the same as the chip's supply will always give you a value of 1023.
No matter what the supply is.
Leo..
Wawa:
I don't get this.
Reading the chip's supply with a Vref that is the same as the chip's supply will always give you a value of 1023.
No matter what the supply is.
Leo..
I should have phrased this better.
Measure the output produced by digitalWrite with a DMM, this becomes the reference voltage to put in the formula.
Ahh, I see.
You want to set an output pin to "high", and measure it to see if it's 3.3volt or 5volt.
Sure, but measure the true voltage afterwards on the corresponding supply pin.
Leo..
Wawa:
Ahh, I see.
You want to set an output pin to "high", and measure it to see if it's 3.3volt or 5volt.
Sure, but measure the true voltage afterwards on the corresponding supply pin.
Leo..
Exactly, check the pin with a DMM to get past this 3.3V/5V thing and then check the supply pin to get the proper reference for the formula.
Haha, was just thinking of that. but I can't explain.
"Sensorvalue" can be 0-1023, so 1023 max.
If the formula is "sensorvalue (5 / 1024)", I get 4.995117volt on my calculator (~4.995volt).
If the formula is "sensorvalue (5 / 1023)", I get 4.999999volt on my calculator (~5volt).
(calculator rounds)
Please explain why 1023 gives the right answer.
Leo..