Best 3 Programming Languages for Raspberry PLC
Learn some Raspberry PLC programming examples with this basic tutorial
22 November, 2021 by
Best 3 Programming Languages for Raspberry PLC
Boot & Work Corp. S.L., Fernandez Queralt Martinez

INTRODUCTION

There are multiple programming languages as well as programming tools by which a Raspberry PLC can be programmed.

In this blog, we show a tutorial on how to program the Raspberry PLC with languages and/or tools like Python, Bash script, node.js or Node-RED.

Latest Posts

REQUIREMENTS

PROGRAMMING LANGUAGES

Although there are many useful programming languages for Raspberry, not everyone will like to program with all of them. Between them there is a difference in terms of syntax, also the speed whose operating system will execute the commands, some of them are low-level and you can go to modify the hardware, etc.

Here is a list of the 3 most useful programming languages for you to play with your programmable logic controllers:


1- Python

Python is an interpreted, dynamic and multiplatform programming language whose philosophy emphasizes the readability of its code.

If you follow the following tutorial, you will find how to use the Python Library for Raspberry PLC >  that you can find in our github >.

Based on that library, you can see an example of a basic blink:

from rpiplc_lib import rpiplc

def digitalreadwrite():
    rpiplc.pin_mode("Q0.0", 1)

    rpiplc.digital_write("Q0.0", rpiplc.HIGH)
    rpiplc.delay(1000)
    rpiplc.digital_write("Q0.0", rpiplc.LOW)
    rpiplc.delay(1000)

def main():
    rpiplc.init("RPIPLC_21")

    while True:
        digitalreadwrite()

if __name__ == "__main__":
    main()



2- JavascriptNode.JS and Node-RED

JavaScript (commonly abbreviated JS) is an interpreted programming language, dialect of the ECMAScript standard. It is defined as object-oriented, prototype-based, imperative, loosely typed, and dynamic.

It is used mainly on the client side, implemented as part of a web browser allowing improvements in the user interface and dynamic web pages, among others.

Node.js® is a JavaScript runtime built on Chrome's V8 JavaScript engine. As an asynchronous event-driven JavaScripBased on that library, you can see an example of a basic blink:t runtime, Node.js is designed to build scalable network applications. 

And Node-RED is a programming tool, based on Node.JS, for wiring together hardware devices, APIs and online services in new and interesting ways. It provides a browser-based editor that makes it easy to wire together flows using the wide range of nodes in the palette that can be deployed to its runtime in a single-click.

From the following links, you will learn how to control the inputs and outputs of the Raspberry PLC through Node-RED:

1- Node-RED Tutorial: How to read digital inputs from Raspberry PLC >

2- Node-RED Tutorial: How to read analog inputs from Raspberry PLC >

3- Node-RED Tutorial: How to set digital outputs to Raspberry PLC >

4- Node-RED Tutorial: How to set analog outputs to Raspberry PLC >

 You will find more examples about how to program with Node-RED in the Raspberry Blog >




3- C or C++

The C programming language is one of the most widely used programming languages in the world. Programs written in C:

  • can be run on a wide range of platforms.

  • its code runs almost as fast as assembly code.

  • can access powerful low level machine functions

  • can be read with a syntax easier than assembly code.

C++ is a cross-platform language that can be used to create high-performance applications. C++ was developed by Bjarne Stroustrup, as an extension to the C language. C++ gives you a high level of control over system resources and memory.

You can download the rpiplc-lib from our Github > written in C and C++, in order to control the outputs of your Raspberry PLC from a low-level programming language!

Based on that library, you can see an example of a basic blink:

void setup() {
  printf("Num digital outputs: %d\n", numDigitalOutputs);
  for (int i = 0; i < numDigitalOutputs; ++i) {
    pinMode(digitalOutputs[i], OUTPUT);
  }
}

void loop() { value = value == 0 ? 1 : 0; printf("Set value %d\n", value); for (int i = 0; i < numDigitalOutputs; ++i) { digitalWrite(digitalOutputs[i], value); }
delay(1000); }
Best 3 Programming Languages for Raspberry PLC
Boot & Work Corp. S.L., Fernandez Queralt Martinez
22 November, 2021
Share this post
Archive

Looking for your ideal Programmable Logic Controller?

Take a look at this product comparison with other industrial controllers Arduino-based. 

We are comparing inputs, outputs, communications and other features with the ones of the relevant brands.


Industrial PLC comparison >>>

Do you want more information?

Just fill the form!

Tell me more!