-1

I want to give signal via PLC to Raspberry Pi and when the raspberry pi gets that signal, it should run the python script and when the python script execute properly and cycle is completed, it should wait for the other signal from PLC to again run the same script and same cycle should go on.

here is my snippet:

import cv2
import numpy as np
import RPi.GPIO as GPIO
import time
from picamera import PiCamera
from PIL import Image
camera = PiCamera()
GPIO.setwarnings(False)
GPIO.setmode(GPIO.BOARD)
RedLedPin = 36
GreenLedPin = 38
PLC_Input_signal = 37
GPIO.setup(PLC_Input_signal, GPIO.IN)
GPIO.setup(RedLedPin, GPIO.OUT)
GPIO.setup(GreenLedPin, GPIO.OUT)
GPIO.input(PLC_Input_signal)
GPIO.output(RedLedPin, GPIO.HIGH)
GPIO.output(GreenLedPin, GPIO.HIGH)
if (GPIO.input(PLC_Input_signal) == GPIO.LOW):
    time.sleep(10)
    camera.resolution = (4056, 3040)
    camera.start_preview()
    
else:
    print('Signal Not Received')
GPIO.input(PLC_Input_signal) == GPIO.HIGH
GPIO.cleanup()
cv2.waitKey(0)

but when i am providing 5v supply to gpio pin i.e. as defined in code pin 37, it is not working accordingly. please help me out. please note that gpio is active low pin which gpio.low turns on the power while gpio.high turns off the power

please help me out

3
  • The GPIO pins are not 5V tolerant. You can damage the pin or the Pi by doing so. Jul 19 at 4:35
  • @SteveRobillard can you suggest what is the error then
    – dsp
    Jul 19 at 5:23
  • 1
    ?? One error is as Steve explained - the GPIO pins are designed to handle 3.3V... NOT 5V. If you're looking for someone to debug your code, you might have better luck at StackOverflow.
    – Seamus
    Jul 19 at 6:25

1 Answer 1

0

An experienced developer would approach your issue (which is unclear) on a step by step approach .

  1. Detect a signal
  2. Write code to do something with signal
  3. Next step.

Start with 1

1
  • @Gil why are you addressing this to me? Nothing to do with my answer.
    – Milliways
    Aug 19 at 22:03

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.