0

Voltage on Analog Pins with nothing plugged in?
Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.

Voltage on Analog Pins with nothing plugged in?

by eat_sleep_code on Tue Oct 06, 2020 11:27 am

I have the code similar to the following:

Code: Select all | TOGGLE FULL SIZE
pin1 = AnalogIn(board.D1)
pin1Threshold = 1.6

def getVoltage(pin):
    voltage = (pin.value * 3.3) / 65536
    return voltage

def gitPin(pin)
    if pin == 1:
        return pin1Threshold, getVoltage(pin1)

pinNumber = 1
threshold, voltage = getPin(pinNumber)
print('Threshold: ', threshold)
print('Voltage: ', voltage)

In my actual code, I have this for pins 1 - 4, but edited here for brevity.

The voltage of the pins with nothing plugged in varies between 0.8 to 2.2volts with nothing plugged in. This is with just a Trinket M0 plugged into the desktop using the micro USB.

Why is this? I would think the voltage should be 0 if there is nothing plugged in?

I am running the latest (as of yesterday) production release versions of both CircuitPython and the boot loader (was happening on the original version too, upgraded to see if it was a bug).

eat_sleep_code
 
Posts: 53
Joined: Sat Dec 30, 2017 1:30 am

Re: Voltage on Analog Pins with nothing plugged in?

by adafruit_support_bill on Tue Oct 06, 2020 11:36 am

With nothing connected, the inputs will 'float' and the values will be unpredictable. If you want to see a 0, you need to tie the input to ground either directly or via a pulldown resistor.

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

Re: Voltage on Analog Pins with nothing plugged in?

by eat_sleep_code on Tue Oct 06, 2020 11:26 pm

Thanks!

eat_sleep_code
 
Posts: 53
Joined: Sat Dec 30, 2017 1:30 am

Re: Voltage on Analog Pins with nothing plugged in?

by maesoph on Thu Sep 23, 2021 12:58 pm

Fair warning: Mechanical engineer that thinkers with electronics.......

Working with a Trinket M0 - does it have a built in pull up / pull down resistor???

I've tried both schemes and the voltage just seems to float about in the middle of the range.. Assuming the answer is likely "NO"..... What is the minimum resistance that should be used for pull up / pull down resistors?? I have a very limited selection of resistors - don't think I have anything in the neighborhood of 10k ohms...

maesoph
 
Posts: 51
Joined: Thu Mar 03, 2016 9:04 pm

Re: Voltage on Analog Pins with nothing plugged in?

by adafruit_support_bill on Thu Sep 23, 2021 1:23 pm

These processors do have built-in pullups, but you need to explicitly enable them with a PinMode statement: https://www.arduino.cc/reference/en/lan ... o/pinmode/

The exact value is usually not critical. 10K is commonly used. 1K would be considered a fairly 'strong' pullup. 100K would be on the 'weak' side. The internal pullups are typically in the 20K Ohm range.

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

Please be positive and constructive with your questions and comments.