Forum Rule: Always post complete source code & details to reproduce any issue!

# Thread: Measure Vcc like Arduino SecretVoltmeter

1. ## Measure Vcc like Arduino SecretVoltmeter

Hi,

Does the Teensy 3.1 / ARM Cortex-M4 hv something similar to Arduino SecretVoltmeter measuring the Vcc ?

HTML Code:
`http://provideyourown.com/2012/secret-arduino-voltmeter-measure-battery-voltage/`
Thanks...

2. Yes, you can measure the internal 1.2V reference as an analog input, using the 3.3V power as a reference, and then do some simple math to figure out what the 3.3V level actually was.

3. Thanks, I was thinking of something similar like the SecretVoltmeter without using up an analog pin for this purpose..

Do u hv a sample codes for this ?

4. Code:
```void setup() {
analogReference(DEFAULT);
}

void loop() {
int mv;
mv = 1195 * 4096 /analogRead(39);
Serial.println(mv);
delay(2000);
}```

5. Ok, thanks... tried it and got a value of 3293, I would assume this is 3.293V ...

Not sure what does those number means ( 1195 * 4096 ) , care to enlighten me or point me to the correct pages ?

What is analogRead(39) ? Is this an internal pin ?

6. yep, sketch calculates millivolts. analog "channel" 39 is mapped by core library (hardware/teensy/cores/teensy3/analog.c) to the internal ADC input. Teensy 3.1 reference manual 3.7.1.4.1 enumerates various ADC inputs. The datasheet gives specs of 1.195v The analog resolution is set to 12 bits, hence 4096.

Paul actually measured the internal AREF here

More discussions of voltage measurement here

7. Originally Posted by manitou
Code:
```void setup() {
analogReference(DEFAULT);
}

void loop() {
int mv;
mv = 1195 * 4096 /analogRead(39);
Serial.println(mv);
delay(2000);
}```
I've done this exactly on a 3.5 but I am getting 1325 abouts as my reading. Other external ADC reads operate fine, but I seem to have an issue measuring the internal reference this way.

If i switch to using the 1.2V internal reference, and then measure external ADC pins this also behaves as expected.

Pulling my hair out to why this isn't working for me. Any suggestions?

8. Sadly a symbolic name has never been assigned to these internal ADC channels. For T3.5/3.6, use analogRead(71)

hardware/teensy/avr/cores/teensy3/analog.c

9. Originally Posted by manitou
Sadly a symbolic name has never been assigned to these internal ADC channels. For T3.5/3.6, use analogRead(71)

hardware/teensy/avr/cores/teensy3/analog.c
ARGH At least it wasn't a mistake starring me in the face.

Would be nice to give that a symbolic name if it keeps changing across the boards. And/or maybe an "Analog IO" page is worthwhile on the Teensy reference (https://www.pjrc.com/teensy/teensyduino.html) to match the digital IO page. Could explain all the advanced (or specific to Teensy) Analog stuff you can do.