Welcome to our new forum
All users of the legacy CODESYS Forums, please create a new account at account.codesys.com. But make sure to use the same E-Mail address as in the old Forum. Then your posts will be matched. Close

Raspberry PI 4, GPIO Configuration

fjcano
2020-11-04
2020-12-05
  • fjcano - 2020-11-04

    Hello,

    I have a Raspberry PI 4 Model B, with the CODESYS CONTROL for RASPBERRY PI 3.5.16.20 runtime installed on it. I have bought a four relais module to control an AC load. In specific, the following one:
    https://www.az-delivery.de/es/products/4-relais-module
    I have connected the GPIOS 1 (3V3), 9 (GND), AND 11, (GPIO17) to the module and if I execute this simple python script i can command the connection/disconnection of the relay:

    import RPi.GPIO as GPIO
    from time import sleep
    
    GPIO.setmode(GPIO.BCM)
    GPIO.setwarnings(False)
    
    Relay1PIN = 17
    GPIO.setup(Relay1PIN, GPIO.OUT)
    
    print('[press ctrl+c to end the script]')
    try: # Main program loop
        while True:
            GPIO.output(Relay1PIN, GPIO.HIGH)
            print(GPIO.input(Relay1PIN))
    
            sleep(1) # Waitmode for 1 second
            GPIO.output(Relay1PIN, GPIO.LOW)
            print(GPIO.input(Relay1PIN))
    
            sleep(1) # Waitmode for 1 second
    except KeyboardInterrupt:
        print('Script end!')
    finally:
        GPIO.cleanup()
    

    My problem is that when IΒ΄m trying to implement this proccess in Codesys I canΒ΄t achive nothing. I have declared a global variable PIN_17 (figure 1). And in the GPIOS_B_PI2 Device at GPIOs Configuration i declare the GPIO17 as output (figure 2). Finally i associate at the GPIOs E/S asignation the bit 17 of the digital output array to my global variable "GVL_GPIO.PIN_17" (figure 3). The problem is when i change the value of the variable PIN_17 i cant connect/disconnect the relay. I dont know if IΒ΄m doing something wrong or IΒ΄m missing any step but any help would be grateful.

    In addition I have tried also with the other GPIOs device (GPIOs A/B) but the result is the same. Both versions are the 3.5.16.0

    Thanks,

     

    Last edit: fjcano 2020-11-04
  • mosfet - 2020-12-05

    Hello,
    I also have the same problem. On the raspberry pi4 model B, the GPIOs controlled with Codesys do not work while if controlled with Python scripts they work correctly. Can someone help me?
    Thanks

     

Log in to post a comment.