Arduino Library and Blocks

Learn about the Twin Activate Arduino library modes and blocks.

Simulation and Code Modes

The Twin Activate Arduino block library can be used in two different modes:

Mode 1: Simulation Mode
In the simulation mode, Twin Activate performs computations and the Arduino board performs the task of interfacing with the electronic components to which the board is connected. The Arduino board performs this task through a generic ino code that is uploaded into the board. In this mode, the code runs in Twin Activate, but a live connection and exchange of data occurs between Twin Activate and the Arduino board.
Mode 2: Ino Code Generation
In the code-generation mode, Twin Activate generates a custom code that is designed to run autonomously on the Arduino board. The code includes the Twin Activate computations so that the Arduino board can operate as a stand-alone device without any connections to Twin Activate. The Twin Activate code generator produces the custom ino code from a Twin Activate diagram.

Arduino Palette and Blocks

Arduino Palette and Configuration Block

The Configuration block is mandatory and must be included and properly parameterized in a given Twin Activate diagram.

In particular, the COM port is defined on this block. On a personal computer system, the COM port is emulated by the USB port. The Arduino board is connected to the USB port of the computer. The actual COM port assigned by Windows is indicated by the Windows Device Manager. This information is required to define the Configuration block.


Basic Palette
The Basic palette includes a general set of blocks for building Arduino components in Twin Activate diagrams.


Components Palette
The Components palette includes Arduino components that you can add to Twin Activate diagrams.


Motors Palette
The Motors palette includes the Arduino Servo Motor that you can add to Twin Activate diagrams.


Serial Communication

In Simulation mode, the Twin Activate Arduino block library uses COM information in the Arduino configuration block to open a serial communication with the Arduino board. Twin Activate supports the connection of several Arduino boards simultaneously, in which case multiple Arduino configuration blocks, one for each board, must be included in the model.

Every Arduino block includes a Serial tab with two parameters:
  • Parameter 1: Specifies if opened serial communication is to be used.
  • Parameter 2: Specifies which communication port is to be used.

If the model contains only one Arduino Configuration block, select the Use Opened Serial check box (the default option). In this case, the serial communication port does not need to be defined in each block.

If the model is connected to more than one Arduino board, clear the Use Opened Serial check box and instead define the communication port for each block. In this case, a best practice is to place all of the blocks representing components connected to a board into a separate super block and mask the super block by making the communication port a mask parameter of that super block. This makes the model more modular and thus easier to share.

Note:
  • In Code Generation mode, only one board is supported. This restriction should be lifted in the future.
  • To generate code for a given super block containing Arduino blocks, the super block should not have any inputs or outputs.
  • In Twin Activate, data of type double are stored as float64_t. In Arduino, they can be stored either as float32_t or float64_t depending on the type of Arduino board.