Giter Club home page Giter Club logo

rpiplc-python3-lib's Introduction

Python Library for Industrial Shields Raspberry PLCs

Summary

This library is developed for Industrial shields Raspberry PLCs and is only supported by Python3. It performs the following functions:

  • Analog Read
  • Analog write
  • Digital Read
  • Digital write
  • Relay

Installation

To install this library, You need to first clone this repository to your PLC using the following command:

$git clone -b <tagname> https://github.com/Industrial-Shields/rpiplc-python3-lib

tagname = v1.X.X = RPI PLC Version 3

tagname = v2.X.X = RPI PLC Version 4

You can find the available tags here: https://github.com/Industrial-Shields/rpiplc-python3-lib/tags

After which, run the following command to install the library:

$python3 setup.py install

Once installed, make sure to comment the following lines from config.txt file:

You can find the file here:

/boot/config.txt

Reboot the PLC once done.

#dtoverlay=mcp23017,noints,mcp23008,addr=0x20
#dtoverlay=mcp23017,noints,mcp23008,addr=0x21
#dtoverlay=i2c-pwm-pca9685a,addr=0x40
#dtoverlay=i2c-pwm-pca9685a,addr=0x41
#dtoverlay=ads1015,addr=0x48
#dtparam=cha_enable=true,cha_gain=1
#dtparam=chb_enable=true,chb_gain=1
#dtparam=chc_enable=true,chc_gain=1
#dtparam=chd_enable=true,chd_gain=
#dtoverlay=ads1015,addr=0x49
#dtparam=cha_enable=true,cha_gain=1
#dtparam=chb_enable=true,chb_gain=1
#dtparam=chc_enable=true,chc_gain=1
#dtparam=chd_enable=true,chd_gain=1
#dtoverlay=ads1015,addr=0x4a
#dtparam=cha_enable=true,cha_gain=1
#dtparam=chb_enable=true,chb_gain=1
#dtparam=chc_enable=true,chc_gain=1
#dtparam=chd_enable=true,chd_gain=1
#dtoverlay=ads1015,addr=0x4b
#dtparam=cha_enable=true,cha_gain=1
#dtparam=chb_enable=true,chb_gain=1
#dtparam=chc_enable=true,chc_gain=1
#dtparam=chd_enable=true,chd_gain=1

API

PLC initialization

rpiplc.init("RPIPLC_57R")

You can choose from the below model list to fill the parameter. PLC Model list:

  • RPIPLC_19R
  • RPIPLC_21
  • RPIPLC_38AR
  • RPIPLC_38R
  • RPIPLC_42
  • RPIPLC_50RRA
  • RPIPLC_53ARR
  • RPIPLC_54ARA
  • RPIPLC_57AAR
  • RPIPLC_57R
  • RPIPLC_58

Pin initialization: It is a good practice to initialize the pins as inputs or outpust, for this use the following code:

pin_mode(pin_name, mode) # mode can be rpiplc.OUTPUT ;rpiplc.INPUT or 1 ; 0

Pin Functions: analog_read()

rpiplc.analog_read("I0.2")

analog_write()

rpiplc.analog_write("A0.0",value) # Here the value is in the range of 0 to 4095. 0 being 0V and 4095 is 10v

digital_read()

rpiplc.digital_read("I0.0")

digital_write()

rpiplc.digital_write("Q0.0",rpiplc.HIGH)

relay()

rpiplc.digital_write("R0.1",rpiplc.HIGH)

Examples

from rpiplc_lib import rpiplc

def digital_read_write():
    rpiplc.pin_mode("I0.0",rpiplc.INPUT)
    read_value=rpiplc.digital_read("I0.0")
    print("The I0.0 is reading: {}".format(read_value))
 
    rpiplc.pin_mode("Q0.0",rpiplc.OUTPUT)
    rpiplc.digital_write("Q0.0",rpiplc.HIGH)
    rpiplc.delay(1000)
    rpiplc.digital_write("Q0.0",rpiplc.LOW)
    rpiplc.delay(1000)
    
    
def analog_read_write():
    rpiplc.pin_mode("I0.2",rpiplc.INPUT)
    read_value=rpiplc.analog_read("I0.2") # 0 - 2047
    print("The I0.2 is reading: {}".format(read_value))

    rpiplc.pin_mode("A0.0",rpiplc.OUTPUT)  	
    rpiplc.analog_write("A0.0",1024) # 2.5v Output
    rpiplc.delay(2000)
    rpiplc.analog_write("A0.0",4095) # 10v Output
    rpiplc.delay(2000)
    rpiplc.analog_write("A0.0",0)


def relay_test():
    rpiplc.pin_mode("R0.1",rpiplc.OUTPUT)
    rpiplc.digital_write("R0.1",rpiplc.HIGH)
    rpiplc.delay(1000)
    rpiplc.digital_write("R0.1",rpiplc.LOW)
    rpiplc.delay(1000)
    
    
def main():
    rpiplc.init("RPIPLC_57R")

    while True:
        digital_read_write()
        analog_read_write()
        relay_test()


if __name__ == "__main__":
    main()

rpiplc-python3-lib's People

Contributors

ams-tech13 avatar dsq-industrialshields avatar jordicasals avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.