PNP Proximity sensor with RevPi Compact
Posted: 19 Aug 2021, 11:35
Hello Community, I am trying to use a PNP inductive proximity sensor with a RevPi Compact, the PNP sensor I am using is : https://www.digikey.de/products/en?keyw ... 10-1203-ND
The wiring diagram of the sensor is: I have connected the black wire (output) of the PNP sensor to to the Digital Input pin "IN 0" on the RevPi Compact, and the Brown and Blue wires to the power supply pins. I have also connected a 10K resistor between the Black and Blue wires.
Here is the code I have used:
------------------------------------------------------------------------------------------------------------------------------------
As the code requires a GPIO pin number to be specified, I am unable to find the pinout of the RevPi Compact with the exact pin numbers and hence I am not able to get a desired output.
Does anyone have knowledge of the pin numbering of the RevPi Compact, that I could write into the code that can help read the output from the inductive sensor?
Thanks in advance to this amazing community
The wiring diagram of the sensor is: I have connected the black wire (output) of the PNP sensor to to the Digital Input pin "IN 0" on the RevPi Compact, and the Brown and Blue wires to the power supply pins. I have also connected a 10K resistor between the Black and Blue wires.
Here is the code I have used:
Code: Select all
import time
import RPi.GPIO as GPIO
# Pin of Input
GPIOpin = -1
# Initial the input pin
def initialInductive(pin):
global GPIOpin
GPIOpin = pin
GPIO.setmode(GPIO.BCM)
GPIO.setup(GPIOpin,GPIO.IN, pull_up_down=GPIO.PUD_DOWN)
print("Finished Initiation")
print(GPIOpin)
# Detect Metal
def detectMetal():
if(GPIOpin != -1):
state = GPIO.input(GPIOpin)
if state:
print("Metal Detected")
else :
print("Metal Not Detected")
else:
print("Please Initial Input Ports")
# test module
if __name__ == '__main__':
pin = 17
initialInductive(pin)
while True:
detectMetal()
time.sleep(0.2)
As the code requires a GPIO pin number to be specified, I am unable to find the pinout of the RevPi Compact with the exact pin numbers and hence I am not able to get a desired output.
Does anyone have knowledge of the pin numbering of the RevPi Compact, that I could write into the code that can help read the output from the inductive sensor?
Thanks in advance to this amazing community