PNP Proximity sensor with RevPi Compact

Topics about the Hardware of Revolution Pi
Post Reply
arrowtec31
Posts: 2
Joined: 19 Aug 2021, 11:24

PNP Proximity sensor with RevPi Compact

Post by arrowtec31 »

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:
20210819_112716.jpg
20210819_112716.jpg (36.07 KiB) Viewed 3741 times
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
User avatar
dirk
KUNBUS
Posts: 2174
Joined: 15 Dec 2016, 13:19

Re: PNP Proximity sensor with RevPi Compact

Post by dirk »

RTFM :-D Take a look at the video "Quick Start Guide" then some will become clear. https://revolution.kunbus.com/tutorials ... rect=en_US
arrowtec31
Posts: 2
Joined: 19 Aug 2021, 11:24

Re: PNP Proximity sensor with RevPi Compact

Post by arrowtec31 »

Hello Dirk,

Thank you for guiding me to the video. The video basically explains that data can be read from the RevPi compact using the piTest program that is already pre-installed on the RevPi, which is written in C. I was able to read the data using the piTest program.

As I am looking to read the value of the inductive sensor through Digital Input pin 1, is there any way to read this data through a code in python? That is why I require the pin assignments for the RevPi Compact. Or is it only possible to read this data through this pin using the piTest program, using the predefined names for the pins
User avatar
dirk
KUNBUS
Posts: 2174
Joined: 15 Dec 2016, 13:19

Re: PNP Proximity sensor with RevPi Compact

Post by dirk »

Hi with interest I read your request many thanks for your patience And please sorry for the long response. Have a look at this tutorial:
https://revolutionpi.com/tutorials/digi ... rect=en_US
It contains the explanation how you can get the values of the pins with or without the process image.
Regarding Python, have a look at the BitMirror example:
https://revolutionpi.de/forum/viewtopic ... rror#p9196
Post Reply