Giter Club home page Giter Club logo

mcu-plc's Introduction

MCU-PLC

MCU-PLC is a proof-of-concept port of OpenPLC core to microcontrollers (currently ESP32 only). You can run standard Structured Text programs right on the MCU rather than using the MCU as an external slave device (standard OpenPLC way).

The core does not contain any communication protocols support for now, just GPIO-in/out and ADC.

BEWARE: This is really just a proof of concept. DO NOT USE IT FOR ANYTHING OTHER THAN RESEARCH!

Principle

Similarly to OpenPLC, The Structured Text program is translated into C++ source files using Matiec compiler. These files are linked with OpenPLC lib files and a very thin MCU-specific layer (also mostly an OpenPLC rip-off). The resulting binary can be uploaded straight into the MCU. I.e. there's no API for uploading the ST program, starting and stopping the PLC or anything like that. Your ST program just runs on your MCU, that's it.

I'm using the Arduino framework but the code is very easily portable to any other PlatformIO-supported framework (see hal.cpp file).

Requirements

You need:

  • standard build-essential or equivalent packages to build Matiec
  • working PlatformIO installation

The code is tested on the NodeMCU ESP-32S board but it should work on every ESP32 board with small or no modifications. You can change the board type by changing board option in the platformio.ini file (see PlatfrmIO docs). Pin mapping is defined in the src/hal.cpp file (..._PINS[] arrays).

Preparation

Get OpenPLC sources:

$ git submodule init
$ git submodule update

Compile matiec (IEC 61131-3 compiler):

$ cd OpenPLC_v3/utils/matiec_src/
$ autoreconf -i
$ ./configure
$ make
$ cd ../../..

PLC Program Compilation

At first, generate PLC sources (using matiec) using:

$ make

This will generate files from the default blink.st program. You can compile different program using:

$ make PLC_SRC_FILE=programs/blink2.st

All PLC C sources are ready now, you can connect your ESP32 to your PC and build and upload the program using PlatformIO:

$ pio run -t upload

If everything went well, you should see blinking LED on your ESP32 now.

Running on Host (Linux only)

To make debugging more convenient, you can run your PLC straight on the host computer, if it's a Linux machine:

$ pio run -e linux_x86_64
$ .pio/build/linux_x86_64/program

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.