1

I'm french excuse me for my english language, i works on a industrial vision processing device. I use the following components :

  • Picaméra
  • Raspberry Pi 3B +
  • Relay : SRD-05VDC-SL-C

I work on a python script who permit to analase et recognaze a object with a Cascade.xml file. When the program recognaze a objet, he transmits the information at the relay which transmits at the light column. The code is as follows :

###### déclaration des Bibliotheque #####
import cv2
import RPi.GPIO as GPIO
import time
########################################

########## déclaration cascade #########
path = 'haarcascad/cascade_teste.xml'              #Chemin de la cascade
cameraNO=0                                         # entrer de la camera
objectName = 'Detecté'                             # Nom de l'objet
########################################

# déclaration format de caméra #
frameWidth= 640                      # DISPLAY WIDTH
frameHeight = 480                    # DISPLAY HEIGHT
color= (255,0,255)
########################################

###### déclaration OpenCv ##############
cap = cv2.VideoCapture(cameraNO)
cap.set(3, frameWidth)
cap.set(4, frameHeight)
########################################

########## déclaration Relais ##########
RelayPin = 3
GPIO.setmode(GPIO.BCM)
GPIO.setup(RelayPin, GPIO.OUT)
GPIO.output(RelayPin, GPIO.LOW)
########################################

def empty(a):
    pass

# Créé les barres de piste et le menu
cv2.namedWindow("Result")
cv2.resizeWindow("Result", frameWidth, frameHeight+100)
cv2.createTrackbar("Scale","Result",400,1000,empty)
cv2.createTrackbar("Neig", "Result",8,20, empty)
cv2.createTrackbar("Min Area", "Result",0, 100000, empty)
cv2.createTrackbar("Brightness","Result",180,255, empty)

# Charge les classificateurs téléchargés
cascade = cv2.CascadeClassifier(path)
while True:
# définir la luminosité de la caméra sous forme de valeur de trackbar
    cameraBrightness = cv2.getTrackbarPos("Brightness", "Result")
    cap.set(10, cameraBrightness)
    # obtenir l'image de la caméra et converti en niveaux de gris
    success, img = cap.read()
    gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
    # Détecte l'object en utilisant la cascade
    scaleVal =1 +(cv2.getTrackbarPos("Scale","Result") /1000)
    neig = cv2.getTrackbarPos("Neig","Result")
    objects = cascade.detectMultiScale(gray,scaleVal,neig)
    for (x,y,w,h) in objects:
        area = w*h
        minArea = cv2.getTrackbarPos("Min Area", "Result")
        if area >minArea :
            cv2.rectangle(img,(x,y),(x+w,y+h),color,3)
            cv2.putText(img,objectName,(x,y-5),cv2.FONT_HERSHEY_COMPLEX_SMALL,1,color,2)
            roi_color = img[y:y+h,x:x+w]

            # Activation du relais 
            GPIO.output(RelayPin, GPIO.HIGH)
            time.sleep(1)
            GPIO.output(RelayPin, GPIO.LOW)

    cv2.imshow("Result", img)
    if cv2.waitKey(1) & 0xFF == ord('q'):
        # fin de programme
        GPIO.cleanup()
        break

The script work a few week and 3 weeks later after i didn't use it, he don't work.

The error who i have us : This channel is already in use, continuing anyway, Use GPIO.setwarnings(False) to disable warnings. I try many solution like : uninstall and reinstall the RPi, run the script in root and format the SD Card

if you have any idea it will be useful for me thank you in advance

5
  • 3
    SRD-05VDC-SL-C is normally 5 volt and the output from the GPIO is 3,3 volt.
    – MatsK
    Aug 24 at 14:49
  • SRD-05VDC-SL-C is a relay switch, operating at 5V, which is different from a relay module, operating at 3V3 or 5V, and which consists of a couple of things, including the relay switch. Reference: electronics.stackexchange.com/questions/505318/….
    – tlfong01
    Aug 26 at 0:37
  • when I look at the relay power supply on the site, it does have a logical level of communication between 3.3 and 5 V.
    – Henry
    Aug 26 at 12:25
  • On fr.rs-online.com/web with the RS code : 843-0834
    – Henry
    Aug 26 at 12:27
  • However, I was able to test the program on another Raspberry Pi board. It turned out that the program works (without the connection of the 24V light column). So like you said this is a connection error.
    – Henry
    Aug 26 at 12:27
1

Welcome, If what interpret what you say correctly you have a 5V relay connected directly to a GPIO pin of the RPi. If this is correct you may have a blown GPIO pin or worse. The relay you state is highly inductive and when switching off will create a reverse pulse directly into the GPIO pin of the RPi. Per the data sheet of the 5V relay requires about 70 Ma. The fact that it worked originally is possible but the relay is rated with a minimum pull in at 75% of rating in this case 5V setting the threshold at 3.75 volts. You need to isolate the coil from the RPi with a suitable device such as a MOSFET, Transistor, or Opto-Coupler. I would recommend getting a relay module (they also use them with Arduino) that has a transistor or something to isolate the coil from your port.

1
  • 1
    251 / 5000 Résultats de traduction This is a relay powered by the raspberry by a 5v power supply on the +, a GND on - and the GPIO03 pin on the input S of the relay. I do not think that is put connection because the relay turns on and goes out when I use the same pins.
    – Henry
    Aug 25 at 7:13
0

That is not an error, it is a warning.

You can ignore it if you want.

https://sourceforge.net/p/raspberry-gpio-python/wiki/BasicUsage/

It is possible that you have more than one script/circuit on the GPIO of your Raspberry Pi. As a result of this, if RPi.GPIO detects that a pin has been configured to something other than the default (input), you get a warning when you try to configure a script. To disable these warnings:

GPIO.setwarnings(False)

Are you sure you have not changed the configuration?

GPIO 3 is I2C SCL.

If you have enabled I2C that might cause the problem you are having.

3
  • GPIO 3 is also used for other things, e.g. the dtoverlay for gpio-shutdown, and IIRC, is distinguished by being one of only two GPIO pins having a soldered-in pullup on the board.
    – Seamus
    Aug 25 at 1:54
  • I only make enabled the camera and when i use the command: (GPIO.setwarnings (False) the script keeps not working.
    – Henry
    Aug 25 at 7:22
  • Check the GPIO. elinux.org/R-Pi_Troubleshooting#Testing
    – joan
    Aug 25 at 7:28

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.