Mapping GPIO and adding GPIO configurations

2014-08-04
2023-11-16
  • barnstormer - 2014-08-04

    Hello, I'm working on a project where I need 16 GPIO pins on the PI. (I'm new to CoDeSys and PLCs in general, but have good programming background and understanding of the PI.) I don't understand how to map and configure the pins under CodeSys 3.5. I'm looking at the GPIO example application and there are only 12 configurable pins in the GPIOs Configuration Tab. How do I add other pins to configure as inputs or outputs?

    Next, how do these GPIO pin configurations in the GPIOs Configuration Tab map to the Channel bit under the GPIOs I/O Mapping tab? And, how do the channels/addresses map to the HMI elements?

    For example I was able to assign Bit18 to variable gxOut, which I guessed somehow aligned with variable GPIOs_Instance._GPIO.axInputs[18] as defined in the HMI example. Sure enough, the light blinks when I run the simulation. It would seem there would be a link between the channel or the address to the HMI element. But, I don't understand.

    Is there reference material that I missed reading? Thanks for your help.

     
  • eschwellinger

    eschwellinger - 2014-08-05

    Hi,

    we will extend the GPIO's to B+ model on next version.

    you could map variables to the IO's in the mapping tap or use the instance of the IOdriver

    GPIOs_Instance ist the instance of the GPIO Iodriver (which is implicite called by the system)
    GPIOs_Instance._GPIO.axOutputs
    GPIOs_Instance._GPIO.axInputs

    You could access the mapped variables in the visualization on different ways:

    This example from store use the instance, this is more because it seems the one who did the example was a kind if lazy to map the
    variables, therefore he get them from the IOdriver instance.
    You could also map your variable like in screenshot GPIOMappin2.jpg and access it that way.

    BR
    Edwin

    IMG: GPIOMapping2.jpg

    IMG: ConfigGPIO.jpg

    IMG: GPIOMapping.jpg

     
  • barnstormer - 2014-08-06

    Thanks for the information. I think I understand the mappings. Thanks for the reference diagram, too.

    As for the number of GPIO, the GPIO example only has 12 pins defined in the configuration tab, but the B version of the PI has 21 possible GPIOs. Some of the pins can do multiple things like SPI, serial, etc, but I would like to use 16 pins for GPIO. The B+ verson of the PI extends connector P1, as you can see in the reference you provideded. In my example, I'm working with the B version of the PI.

    In the GPIO Tab the following pins are defined, with the corresponding physical pinout from the reference you provideded:

    GPIO4 P1-7
    GPIO17 P1-11
    GPIO18 P1-12
    GPIO22 P1-15
    GPIO23 P1-16
    GPIO24 P1-18
    GPIO25 P1-22
    GPIO27 P1-13
    GPIO28 P5-03
    GPIO29 P5-04
    GPIO30 P5-05
    GPIO31 P5-06

    The configuration tab in CoDeSys does not have configuration options for (missing GPIOs) these GPIOs (Revision 2):

    GPIO02
    GPIO03
    GPIO07
    GPIO08
    GPIO09
    GPIO10
    GPIO11
    GPIO14
    GPIO15

    Since my project requires 16 GPIO's and the Configuration Tab only has 12 GPIO's defined, is there a way I can ADD configurations for the other missing GPIOs so they are available to use under CoDeSys?

    Thanks for your help.

     
  • eschwellinger

    eschwellinger - 2014-08-07

    Hi,

    yes, this is possible.
    We only provide the free GPIOs because we assume that in many cases I²c, SPI and the other options are used, so we reduced the standard IOs.
    Please see attached the device description file (devdesc.xml) that contains the description and the parameters of the “GPIO” device in the device tree. Feel free to modify/customize it, but consider to give it a new ID (DeviceIdentification section) and a new name (DeviceInfo section)
    Snippet from GPIOs.devdesc.xml

    <Device hideInCatalogue="false">
        <DeviceIdentification>
          <Type>504</Type>
          <Id>0000 0000</Id>
          <Version>1.0.0.0</Version>
        </DeviceIdentification>
        <DeviceInfo>
          <Name name="local:ModelName">GPIOs</Name>
    

    to distinguish it from the standard one. You need to install it in the device repository and update your device.

    Please see also the attached library that interprets the configuration and executes it.

    BR
    Edwin

    IoDrvGPIO.library [388.32 KiB]

    GPIOs.devdesc.xml [9.54 KiB]

     
  • alexdrik - 2015-05-21

    Hello,

    can you please give some more infos about how to modify the gpio.devdesc.xml and how to import it into CoDeSys.

    I want to make a berryclip plus (http://www.raspberrypi-spy.co.uk/berryc ... tructions/) work with the Raspberry and CoDeSys.
    Switch 2 (at GPIO 25), LED 2 (at GPIO 17) and LED 3 (at GPIO 22) are already working, but the others don't.

    The python scripts are all working, so it is no hardware problem.

    Thanks for your help.

     
  • alexdrik - 2015-06-16

    Hello,

    thanks to the 3S-Support i could get all GPIOs working.

    Attached is the DevDesc.xml with all Pins.

    First of all, you have to install the DevDesc.xml under "Tools" -> "Install Device..." and select the file.

    Then, you have to navigate to "Tools" -> "Options...", select "Features" and click on "Predefined Feature Set" and change it to "Professional".

    Now you can right-click on the Raspi in the project manager, select "update device..." and there is a new option "display all versions (for experts only)" and select the modified device description file.

    Remember to map the Inputs and Outputs to plc-variables and to configure the used pins as input or as output.

    IMG: Profesional.png

    AllGPIOs.devdesc.xml [10.97 KiB]

     
  • Ledrunner - 2016-03-18

    Hi everyone! Anyone help me to understand GPIO structure. I talk about pull-up resistors, how configured I/O in Codesys driver, when I select port is input? For example I need use button working on ground.

    IMG: Screenshot_1.jpg

     
  • SimonD - 2016-05-17

    alexdrik hat geschrieben:
    First of all, you have to install the DevDesc.xml under "Tools" -> "Install Device..." and select the file.
    Then, you have to navigate to "Tools" -> "Options...", select "Features" and click on "Predefined Feature Set" and change it to "Professional".
    Now you can right-click on the Raspi in the project manager, select "update device..." and there is a new option "display all versions (for experts only)" and select the modified device description file.
    Remember to map the Inputs and Outputs to plc-variables and to configure the used pins as input or as output.

    Hi, I don't have the "Features" option under the Tools - Options tabs! Am I missing something please?

     
  • Anonymous - 2016-05-18

    Originally created by: M.Schaber

    Hi,

    in recent CODESYS versions, the "Featureset" functionality was removed, CODESYS now always behaves as "Professional".

    HTH,
    Markus

     
  • artemka - 2016-06-08

    Hello! I need to set GPIO11 as input. I edit the file GPIOsBplus.devdesc.xml, in the settings this output appeared, but it's not working, can you fix it?

    IMG: GPIO1.jpg

    IMG: GPIO.jpg

     
  • artemka - 2016-06-09

    artemka hat geschrieben:
    Hello! I need to set GPIO11 as input. I edit the file GPIOsBplus.devdesc.xml, in the settings this output appeared, but it's not working, can you fix it?

    Is it possible to implement it?

     
  • Peter1983 - 2019-07-07

    Edwin Schwellinger hat geschrieben:
    Hi,
    yes, this is possible.
    We only provide the free GPIOs because we assume that in many cases I²c, SPI and the other options are used, so we reduced the standard IOs.
    Please see attached the device description file (devdesc.xml) that contains the description and the parameters of the “GPIO” device in the device tree. Feel free to modify/customize it, but consider to give it a new ID (DeviceIdentification section) and a new name (DeviceInfo section)

    <Device hideInCatalogue="false">
        <DeviceIdentification>
          <Type>504</Type>
          <Id>0000 0000</Id>
          <Version>1.0.0.0</Version>
        </DeviceIdentification>
        <DeviceInfo>
          <Name name="local:ModelName">GPIOs</Name>
    

    to distinguish it from the standard one. You need to install it in the device repository and update your device.
    Please see also the attached library that interprets the configuration and executes it.
    BR
    Edwin

     
  • greggo - 2019-07-21

    Model: Rpi 3B+
    Hi,
    I would like to use all GPIO pins, 2 to 27 for digital I/O.
    I edited the device description file (devdesc.xml), added in the missing GPIO pins and gave it a new name and loaded it, but it's not enough, it seems apparent you need to update the IoDrvGPIO.library to reference the GPIO numbers to the internal Pi memory address. The GPIOs I/O Mapping table needs to be populated so you can assign variables to the GPIO.

    Edwin, would it be possible to provide a library file with mapping for GPIO 2 to 27?

    IMG: GPIO_capture.JPG

    IMG: GPIO_Channels capture.JPG

     
  • greggo - 2019-07-21

    Hi, further to this I see the pattern for I/O Mapping 8 bits per bank. To edit this and add the additional channels, should I download the CSV file edit it and reload?
    Then for example, if I create channel Bit2 , %IXO.2, it will be GPIO2 ?

     
  • davewkoenig - 2021-10-13

    I am trying to get a PWM circuit to work, I only need one channel for lase control and Raspberry Pi has it, GPIO 12 or 13, how do I enable and control it? I do see a function GPIO that has PWMFrequency and duty cycle

     

Log in to post a comment.