[solved] analogRead(BATTERY)

Discussion about Z-Uno product. Visit http://z-uno.z-wave.me for more details.
Post Reply
michap
Posts: 312
Joined: 26 Mar 2013 10:35
Contact:

[solved] analogRead(BATTERY)

Post by michap » 31 Jan 2018 23:06

Hi,

I have tried the new analogRead(BATTERY) function, but something seems to be wrong for me.

Have powered the Z-Uno on 5V pin with battery, and get values about 408 / 409 units.
This should be 3.3V for my understanding - right?
Same values if powered via USB.

How to use this function right? ;)

Thanks!

Michael

User avatar
PoltoS
Posts: 4167
Joined: 26 Jan 2011 19:36

Re: analogRead(BATTERY)

Post by PoltoS » 01 Feb 2018 02:11

Z-Uno measures it's Vcc voltages against an internal reference ~1.21V. Once you power Z-Uno from 5V pin (or USB) or 7-18V pin, the Vcc on the chip is behind a voltage converter. So you are measuring pretty stable 3.3V.

If you need to measure your 5V battery, use voltage divider to normalize it to something lower than 3.3V and use normal ADC to measure it. Then use battery custom hander to report your own value for the battery level.

michap
Posts: 312
Joined: 26 Mar 2013 10:35
Contact:

Re: analogRead(BATTERY)

Post by michap » 01 Feb 2018 10:16

PoltoS wrote:
01 Feb 2018 02:11
So you are measuring pretty stable 3.3V.
Right - this was the question. I know that I measure the voltage at the 3.3V pin.

But why the value is about 410?
https://z-uno.z-wave.me/Reference/analogRead/ say:
"This means that it will map input voltages between 0 and Vcc (about 3 V) into integer values between 0 and 1023."

So I thought it should be a value near 1000?
Even if the reference description is not correct - and Z-Uno measure against internal reference 1.21V, I can not understand the value 410 in this time ;)

Thanks
Michael

User avatar
PoltoS
Posts: 4167
Joined: 26 Jan 2011 19:36

Re: analogRead(BATTERY)

Post by PoltoS » 02 Feb 2018 01:47

The doc is correct - Vcc = 1.21×1024÷value. In your case 1.21×1024÷410 = 3.022 V.

Note that 1.21 is not strictly accurate (from Z-Uno to Z-Uno it can change by 10% - you need to calibrate yours).

michap
Posts: 312
Joined: 26 Mar 2013 10:35
Contact:

Re: analogRead(BATTERY)

Post by michap » 02 Feb 2018 09:51

Thanks,

I haven't noticed about the remark in the end of the reference:
" [!] If BATTERY is used, the reported value is the position of 1.21V..."

(was not visible at screen by default...)

Michael

Post Reply