简体   繁体   中英

Raspberry GPIO: Is it possible to guess what type of device is connected to the gpio pins?

Let's imagine that someone has plugged some sensor on his raspberry, but I don't know which one. Would it be possible for me to create a program that guess which sensor is connected?

So that I could then give him a program that would use those sensor.

If it is possible, is there a python library to do that?

The value of state can be either 1 or GPIO.HIGH or True for the ON state and 0 or GPIO.LOW or False for OFF.

sudo pip install RPi.GPIO

RPi.GPIO

import RPi.GPIO as GPIO 
GPIO.setup( self.PIN , GPIO.IN )
if( GPIO.input( self.PIN ) == 0 )
    self.value = 'Device not connected'
else:
    #self.value = 'Device is connected'
    return GPIO.output(pin, 1)

gpiozero

def _state_to_value(self, state):
    return int(state == self._active_state)

def _read(self):
    try:
        return self._state_to_value(self.pin.state)
    except (AttributeError, TypeError):
        self._check_open()
        raise

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM