Raspberry Pi MC SL with MCP23017

Runtime
2019-12-20
2020-01-13
  • oliverboswall

    oliverboswall - 2019-12-20

    Hello Everyone,

    I am a new user here and I have a raspberry Pi 3 model B which I have installed CODESYS Control for Raspberry Pi MC SL. I am trying to communicate with the MCP23017 chip using i2c. I have downloaded the library, and driver as well as the sample code but I am not able to get it to work - thus any help would be greatly appreciated.

    I have managed to communicate with the MCP23017 chip using the raspberry pi terminal itself using the code

    $ i2cset -y 1 0x20 0x00 0x00 (this code on the pi declares all pins of Bank A (GPA) as outputs)
    $ i2cset -y 1 0x20 0x14 0x01 (this code on the pi turns on the 1st led on channel A)

    I have been trying to replicate this in codesys but its not working and I am quite lost. If anyone has some tips please contact me.

    Kind regards, Oliver

     
  • Anonymous - 2019-12-21

    Originally created by: phenixrb

    hello oliver,
    Codesys does not manage MCP23017 in I2C, but MCP23S17 in SPI.

    l viewtopic.php?f=23&t=6247 l

     
  • i-campbell

    i-campbell - 2019-12-21

    Hello, in my brief search I couldn't find your exact Codesys driver.

    You can make your own though, here is the documentation.
    https://forge.codesys.com/drv/io-drivers/doc/I2C/

    If you decide to develop your driver on forge.codesys.com, there is a wonderful community to help when you are stuck.

    Let me know if there are any specific questions about the process, or of course you can ask there.

     
  • eschwellinger

    eschwellinger - 2019-12-28

    Hi,
    you could give the driver from the section here a try:
    l viewtopic.php?f=23&t=5872 l
    or is it what you have already done?

    This section will move to forge too...next
    BR
    Edwin

     
  • oliverboswall

    oliverboswall - 2019-12-30

    Hello everyone,

    Sorry for my late response - hope you all had a lovely Christmas.

    Yes I downloaded that driver, library and sample code from that thread Edwin but I was not able to get any response. I think I am missing something trivial but such as setting the GPIO to an input/output but I am not able to see the i2c gpio in codesys. Is this correct?

    If anyone has 30 minutes (or any time at all) to have a quick run through of what I have already done and give some advice I would greatly appreciate it.

    I look forward to hearing from you

     
  • eschwellinger

    eschwellinger - 2019-12-31

    Hi,
    no mapping is needed for I2C on the GPIO's.
    Did you enable I2C by using CLI?

    sudo raspi-config
    That's basically the only thing which is needed.

    You could check your device by:
    i2cdetect -y 1
    0 1 2 3 4 5 6 7 8 9 a b c d e f
    00: -- -- -- -- -- -- -- -- -- -- -- -- --
    10: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
    20: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
    30: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
    40: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
    50: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
    60: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
    70: -- -- -- -- -- -- -- --
    If this works CODESYS should work with the I2C too.

    BR
    Edwin

     
  • JJoe

    JJoe - 2020-01-13

    Hello
    from time to time I trying to work with the MCP23017. I have no problem to use the MCP ports as inputs but until now I was not able to use the MCP ports as outputs (e.g. to control a LED).
    Regards
    JJoe

     
  • JJoe

    JJoe - 2020-01-13

    Sorry I forgot my Codesys code:
    MCP23017_0x24.OUT_A:=16#00; //Porta --> Output
    MCP23017_0x24.OUT_B:=16#FF; //PortB --> Input
    GVL.xPB:=MCP23017_0x24.IN_B.0;

    IF NOT GVL.xPB THEN
    MCP23017_0x24.OUT_A.0:=TRUE;
    MCP23017_0x24.OUT_A.1:=TRUE;
    MCP23017_0x24.OUT_A.2:=TRUE;
    MCP23017_0x24.OUT_A.3:=TRUE;
    MCP23017_0x24.OUT_A.4:=TRUE;
    MCP23017_0x24.OUT_A.5:=TRUE;
    MCP23017_0x24.OUT_A.6:=TRUE;
    MCP23017_0x24.OUT_A.7:=TRUE;
    END_IF

    IF GVL.xPB THEN
    MCP23017_0x24.OUT_A.0:=FALSE;
    MCP23017_0x24.OUT_A.1:=FALSE;
    MCP23017_0x24.OUT_A.2:=FALSE;
    MCP23017_0x24.OUT_A.3:=FALSE;
    MCP23017_0x24.OUT_A.4:=FALSE;
    MCP23017_0x24.OUT_A.5:=FALSE;
    MCP23017_0x24.OUT_A.6:=FALSE;
    MCP23017_0x24.OUT_A.7:=FALSE;
    END_IF

     

Log in to post a comment.