Skip to content

Arduino PLC IDE - Launch (Tutorials + Software Page) #713

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Dec 6, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
141,731 changes: 141,731 additions & 0 deletions ...s-and-kits/portenta-machine-control/tutorials/can-setup/assets/PMC-CAN-pins.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
@@ -0,0 +1,141 @@
---
title: 'CAN Bus Setup with Arduino PLC IDE'
description: 'This tutorial will show you how to set up the CAN bus communication with the Arduino PLC IDE.'
tags:
- PLC
- CAN
author: 'Pablo Marquínez'
hardware:
- hardware/05.pro-solutions/solutions-and-kits/portenta-machine-control
software:
- plc-ide
---

## Overview

The Arduino Portenta Machine Control has the **TJA1049T** CAN transceiver which allows to use the **Controller Area Network (CAN) protocol** communication.

### What Is CAN

CAN is the acronym used for Controlled Area Network. This protocol was developed to be used on automotive and industrial applications to communicate with precise and critical demanding sensors.

The main advantages of the CAN bus protocol are:

* **Reduced wiring:** The CAN communication only uses two wires, creating a bus communication where all the devices of the network are connected. This is a huge advantage for industrial applications, like the automotive one, where we can connect all the electronic components of a car to the same network using only two wires, saving cost, materials, and simplifying the programming and manufacturing process.

* **Fast speed communication:** The CAN protocol is one of the most used communication protocols in the industry not only for its simplicity but also for its speed rates.

* **Strength and reliability:** Thanks to the twisted pair cables and the differential signal between them, the CAN bus protocol protects the data against electrical noise in industrial environments keeping the critical information safe and without data losses.

Structure of a CAN network:
* **Main device:** Main controller or orchestrator of the communication. It interacts with the rest of the devices on the network, sending and receiving data from them. It usually is a controller device like the Portenta Machine control.
* **Node or ECU (Electronic Control Unit):** Devices capable of interacting on the data bus. Although every device on the network can listen to the data that is being transferred on the bus each device has an unique number (ID) to communicate with that is included in every message, ignoring the messages that do not match their ID. However, all the nodes have access to the messages of the network, being possible for a node to read and use the data from another node if necessary.

CAN has built-in error detection so the application can handle its own errors in case of data loss (like CRC).

## Goals

- Set up the Portenta Machine Control with the Arduino PLC IDE
- Configure the CAN communication inside the IDE

## Required Hardware and Software

- [Arduino Portenta Machine Control](https://store.arduino.cc/products/arduino-portenta-machine-control) board
- [Arduino PLC IDE](../../software/plc-ide) license

## Set Up

### Software

In order to configure the Portenta Machine Control you will need to connect to the device through the Arduino PLC IDE:

1. Connect the device to the computer through USB
2. Click "Connects to the target" button on the PLC IDE

***The device needs to be activated with a license, check the steps on the [PLC IDE Set-up tutorial](./plc-ide-setup-license)***

### Hardware

In order to use the CAN communication, you will need to:
1. Supply the board with 24V DC, through the 24VIn and GND
2. Connecting the CANH, CANL, and GND with a CAN Device

![Header pinout for CAN communication](assets/PMC-CAN-pins.svg)

## Enable The CAN Communication

Inside the Arduino PLC IDE navigate to the left side panel and click on the "Resources" tab.

![Arduino PLC IDE Resources panel, -> CANopen CAN0](assets/CAN-configuration.png)

### CANopen Configuration

To configure in depth the settings you need to add the **Generic CANopen device** from the item's catalog.

![Add Items to CANopen's resource](assets/CAN-configuration-add.png)

![Item from the catalogue](assets/CAN-configuration-add-catalog.png)

Once the **Generic CANOpen device** has been added you can customize the configuration to comply your needs.

![CANopen configuration window](assets/CAN-configuration-general.png)

<!--
Below, you will find an enumeration of the options located in each of the CAN configuration tabs and windows.

#### Network Settings Tabs

* Node number
* Node Guard Period(ms)
* Life time factor
* Boot time elapsed
* Wait boot-up message
* Node heartbeat producer time
* Node heartbeat consumer time
* Master heartbeat consumer time
* Mandatory
* Identify Object Check

#### PDO Mapping

* PDO Auto Mapping

#### PDO Tx Communication Settings Tab
Modes:
* User Defined Mode
* Sync Mode
* Event mode
* Cyclic mode

#### PDO Rx Communication Settings Tab
Modes:
* User Defined Mode
* Sync Mode
* Evemt Mode
-->

### Parametrization Tab

![CANopen objects mapping table](assets/CAN-configuration-parametrization.png)

This window allows to create objects and set the addresses, this is called a mapped variable table.

### PDO Tables

This table customize the PDO (Process Data Object) dictionary, so you will set the variables for the information that you want to have usually cause they are time-critical, any device can overwrite those addresses, so it acts like shared variables.

You can edit the table by adding, removing new variables, you can also assign and unassign existing variables on your programs (Global Variables) to this table.

#### PDO Tx Input Tab

![CANopen PDO Tx configuration](assets/CAN-configuration-pdo-tx.png)

#### PDO Rx Output Tab

![CANopen PDO Rx configuration](assets/CAN-configuration-pdo-rx.png)

### Next Steps

Now that you have completed the setup of the Portenta Machine Control and its CAN bus communication with the Arduino PLC IDE, you can continue with:
- Plug a CAN sensor to your device and get its data.
- Expand your CAN bus network with more nodes sending and receiving messages from each one of them.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
@@ -0,0 +1,161 @@
---
title: 'ModBus Setup with Arduino PLC IDE'
description: 'This tutorial will show you how to set up the ModBus communication with the Arduino PLC IDE.'
tags:
- PLC
- ModBus
author: 'Pablo Marquínez'
hardware:
- hardware/05.pro-solutions/solutions-and-kits/portenta-machine-control
software:
- plc-ide
---

## Overview

The Arduino Portenta Machine Control (PMC) is a fully-centralized, low-power, industrial control unit. For equipment and machinery control, industrial communication protocols, such as Modbus RTU over RS485 and Modbus TCP/IP over Ethernet, can be implemented in the PMC. In this tutorial, we will learn about how to get started on how to configure the ModBus communication with the Arduino PLC IDE.

## Goals

- Configure the ModBus communication (RTU and TCP)

## Required Hardware and Software

- [Arduino Portenta Machine Control](https://store.arduino.cc/products/arduino-portenta-machine-control) board
- [Arduino PLC IDE](../../../../software/plc-ide) license

## Set Up

In order to configure the Portenta Machine Control you will need to connect to the device through the Arduino PLC IDE.

1. Connect the device to the computer through USB
2. Click "Connects to the target" button on the PLC IDE

***The device needs to be activated with a license, check the steps on the [PLC IDE Set-up tutorial](./plc-ide-setup-license)***

***Both ModBus RTU and ModBus TCP can run at the same time in parallel***

## Configure The ModBus RTU Communication

***Important: Once you use the ModBus Mode to Master/Slave the RS485 ports will be only dedicated to ModBus, so the RS485 protocol is not accessible while using ModBus***

### ModBus RTU Configuration

Inside the Arduino PLC IDE navigate to the left side panel and click on the "Resources" tab.

To configure the ModBus communication click on the "RS485 Serialport" label, it will open a new window on the middle to customize:

![Arduino PLC IDE Resources panel, -> RS485 settings](assets/PLC-IDE-ModBus.png)

Then you can attach some functions to the Generic Modbus item, they will appear also in the **Catalog Tile Window**, you need to select first the **Generic Modbus_01**

![Modbus catalog add new item](assets/modBusCatalog-add.png)

![Modbus catalog select new item](assets/modbusCatalog-add-prompt.png)

#### Mode

* Not used
* ModBus RTU Master
* ModBus RTU Slave

#### Baud Rate

Bauds per second of the clock, options:
* 600
* 1200
* 2400
* 4800
* 9600
* 19200
* 38400
* 57600
* 115200

#### Serial Mode

| Name | Parity | data bits | stop bits |
| ------- | ----------- | --------- | ----------|
| N, 8, 1 | No parity | 8 | 1 |
| E, 8, 1 | Even parity | 8 | 1 |
| O, 8, 1 | Odd parity | 8 | 2 |
| N, 8, 2 | No parity | 8 | 2 |
| O, 8, 2 | Odd parity | 8 | 2 |

#### Slave Settings

(Only available on slave mode)

* ModBus address
Address of the device, from 1 to 247, it can not be repeated within the same ModBus net.

#### ModBus Node Configuration

Once you have configured your device as a **ModBus Master** you can attach some blocks to configure it, you can see them while you have the **RS485 SerialPort** on the **Catalog Tile Window**
![Modbus catalog](assets/modBusCatalog.png)

* Generic Modbus
Configure the device name, Modbus address and the minimum polling time.

### ModBus TCP Configuration

***Important: Once you use the ModBus Mode, the ethernet port will be only dedicated to ModBus, so the ethernet protocol is not accessible while using ModBus***

Inside the Arduino PLC IDE navigate to the left side panel and click on the "Resources" tab.

To configure the ModBus communication click on the "Ethernet" label, it will open a new window on the middle to customize:

![Arduino PLC IDE Resources panel, -> Ethernet configuration](assets/modbusTCP-configuration.png)

* ModBus TCP Master: Enables the Master mode on the TCP bus (ModBus)
* ModBus TCP Slave: Always enabled, address 255

Then you can attach some functions to the Generic Modbus item, they will appear also in the **Catalog Tile Window**, you need to select first the **Generic Modbus device**

![ModBus catalog add new item](assets/modbusTCP-configurationAdd.png)

![ModBus catalog select new item](assets/modbusTCP-configurationCatalogAdd.png)

![ModBus TCP general configuration tab](assets/modbusTCP-configuration-general.png)

Settings:
* Name
* IP address
* Minimum polling time

## ModBus Parametrization

On the Generic
![Generic ModBus Parametrization Tab](assets/modbusParametrization.png)

## ModBus Devices Functions (Modbus FC)

* Modbus FC-01: This will read the status of the coils (digital outputs)
* Modbus FC-02: Reads the discrete inputs
* Modbus FC-03: Reads the holding registers
* Modbus FC-04: Read the input registers
* Modbus FC-05: Writes single coil state
* Modbus FC-06: Write single register
* Modbus FC-15: Write multiple coils
* Modbus FC-16: Write multiple registers

To configure the block you can click on it and it will show the configuration panel on the main window.
![ModBus item catalog](assets/genericModbus-catalog.png)

Inside each of the "devices" (functions) you can set its:
**General**
* Start address
* Polling time
* Time Out

![ModBus item general configuration](assets/genericModbus-catalog-setting-general.png)

**Coil/Register/Table**
This is a table to link all the coils, registers or variables that the function is going to poll/write.

![ModBus item specific configuration](assets/genericModbus-catalog-setting-specific.png)

### Next Steps

- Configure it as a ModBus Master device and connect a ModBus sensor to get data from.
- Interconnect two Portenta Machine Control boards and create a sketch to communicate between them.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading