Raspberry PI2 and relay board

burger
2015-10-25
2015-12-06
  • burger - 2015-10-25

    Hello everyone,

    I have Raspberry PI 2 and 4 Relay board (http://www.seeedstudio.com/wiki/Raspber ... Board_v1.0). I have a lot of expirience with codesys in building automation, but I can not solve this.
    How do I connect RPI2 and this relay board in Codesys?
    Has anyone have a sample program (ON OFF relay) so that I can start from there, please? I can not find any library for this and I2C is something new for me.

    Best regards

     
  • eschwellinger

    eschwellinger - 2015-10-26

    Hi,
    serveral Options:
    you need to add ad Driver (library and device description) as shown in the pdf

    "c:\Users\<yourwindowsusername>\CODESYS Control for Raspberry PI\2.2.0.2\DataSheet\RaspberryPI_en.pdf" </yourwindowsusername>

    from your link there is the source code snippet, which shows which addresses are used by the device

    import time

    import smbus
    import signal
    import sys
    bus = smbus.SMBus(1)    # 0 = /dev/i2c-0 (port I2C0), 1 = /dev/i2c-1 (port I2C1)
    class Relay():   
        global bus
        def __init__(self):
       self.DEVICE_ADDRESS = 0x20      #7 bit address (will be left shifted to add the read write bit)
       self.DEVICE_REG_MODE1 = 0x06
       self.DEVICE_REG_DATA = 0xff
       bus.write_byte_data(self.DEVICE_ADDRESS, self.DEVICE_REG_MODE1, self.DEVICE_REG_DATA)
    

    If you have this device working feel free to publish your approach here:

    l viewforum.php?f=23 l

    Thank a lot.
    BR
    Edwin

     
  • burger - 2015-10-26

    Hi,

    thank you for your reply. I have tryed but I am not very good at this, so I am asking for a sample.

    Regards

     
  • eschwellinger

    eschwellinger - 2015-10-26

    Hi,
    you'll find the samles here: (here are the open libs to check how it works with
    libraries:
    "c:\Users\YourWindowsUserName\CODESYS Control for Raspberry PI\2.2.0.2\Libraries\"

    devices:
    "c:\Users\YourWindowsUserName\CODESYS Control for Raspberry PI\2.2.0.2\Devices\"

    another option is to use
    "c:\Users\YourWindowsUserName\CODESYS Control for Raspberry PI\2.2.0.2\Examples\PiFace_FB.project"
    and realize this with I2C Bus... (without Setup a library and devdec)

    BR
    Edwin

     
  • burger - 2015-11-08

    Hi,

    I have no idea how to start end where to start. I will be very grateful if anyone can publish a test sw for this, at lest for one digital output.

    Best regards

     
  • burger - 2015-11-22

    Hi,

    I have made I2C master in Codesys and created a simple code for testing one relay output.

    This is my code and it is not working. My dip switch for on relay board is in state: all 4 switches are on.

    Can anyone tell what I am doing wrong?

    regards

     
  • burger - 2015-12-03

    Hi,
    I have decided to use SainSmart relays. Those have a 5V logic. Will my RPI2 be able to control them with 3,3V logic? On GPIO pin as DO the RPI2 puts 3,3V toGND pin when it is HIGH. Can we control the rlays with GND logic, not 3,3V? Regards.

     
  • burger - 2015-12-06

    Hello,

    I have a problme with this. I have configured GPI17 in GPIO18 as digital output. By default the digital output are FALSE. This means that Sainsmart relay will be TRUE or. LED on relay is ON. When I reboot the RPI2 the GPIO will not give 3,3V and GPIO is TRUE. IF I switch GPIO to FALSE and back to TRUE, then I get 3,3V. Whay is this hapening?

    regards

     

Log in to post a comment.