Voting resources, early voting, and poll worker information - VOTE. ... Adafruit is open and shipping.
0

Reading analog voltage gives values when nothing is applied
Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.

Reading analog voltage gives values when nothing is applied

by Assemble_In_Mexico on Thu Aug 06, 2020 9:46 pm

Strange. I am getting positive voltage readings on pins A0 through A5 on more than one M0 and M4 when nothing is applied or connected. To illustrate, I ran:

Code: Select all | TOGGLE FULL SIZE
import board
import time
from analogio import AnalogIn

def get_voltage(pin):
    return 3.3*pin.value/65535

voltage0 = AnalogIn(board.A0)
voltage1 = AnalogIn(board.A1)
voltage2 = AnalogIn(board.A2)
voltage3 = AnalogIn(board.A3)
voltage4 = AnalogIn(board.A4)
voltage5 = AnalogIn(board.A5)

while True:
    print(get_voltage(voltage0))
    print(get_voltage(voltage1))
    print(get_voltage(voltage2))
    print(get_voltage(voltage3))
    print(get_voltage(voltage4))
    print(get_voltage(voltage5))
    print()
    time.sleep(2)


and get statistically consistent readings for each pin and across chips. Readings for the M0 on average show for example,

1.72254
1.46552
1.43974
0.783923
1.47439
1.50097

and for the M4s,

1.13278
1.10539
0.842737
0.737999
0.77506
0.836292

Any idea why these values are not close to zero? Also of interest, it is noted that the value for pin A0 on the M0 is higher than the others while that of A3 is lower. Likewise the M4 values for pins A0 & A1 are higher than the others.

Assemble_In_Mexico
 
Posts: 18
Joined: Sun May 03, 2020 10:50 am

Re: Reading analog voltage gives values when nothing is appl

by franklin97355 on Fri Aug 07, 2020 12:22 am

The pins may be floating. You should attach a high-value resistor to ground or vcc depending on what you are testing (voltage or a short)

franklin97355
 
Posts: 21586
Joined: Mon Apr 21, 2008 2:33 pm
Location: Lacomb, OR.

Re: Reading analog voltage gives values when nothing is appl

by Assemble_In_Mexico on Fri Aug 07, 2020 2:12 am

The pins may be floating.
I knew it had to be something like that. Yes, in practical application I plan to tie a pin in question to a voltage or ground, trusting it would work as expected. Thank you so much Franklin for sharing your expertise so quickly.

For the benefit of all including myself, could someone offer to explain more about the concept of "floating"? What is it exactly and what causes it out of curiosity?

Assemble_In_Mexico
 
Posts: 18
Joined: Sun May 03, 2020 10:50 am

Re: Reading analog voltage gives values when nothing is appl

by adafruit_support_bill on Fri Aug 07, 2020 5:38 am

An unconnected pin configured for input is like an antenna. It can pick up ambient electromagnetic interference. Since it has a very high input impedance, the current flow is negligible, so even small signals can produce measurable voltages.

https://www.mouser.com/blog/dont-leave- ... s-floating

adafruit_support_bill
 
Posts: 78758
Joined: Sat Feb 07, 2009 10:11 am

Re: Reading analog voltage gives values when nothing is appl

by Assemble_In_Mexico on Fri Aug 07, 2020 9:29 am

I learn something every day. Thank you so much for the understanding of a rather interesting circuit phenomenon!

Assemble_In_Mexico
 
Posts: 18
Joined: Sun May 03, 2020 10:50 am

Please be positive and constructive with your questions and comments.