Engee documentation
Notebook

Sending data via COM: Arduino Blink

This example looks at modelling in Engee with external hardware connected. The COM port of the computer running Engee is in the mode of sending messages to the COM port of the Arduino MEGA microcontroller. Receipt of messages on the microcontroller is processed to control the built-in LED. Adjusting the model parameters at runtime allows you to change the data sent to the Arduino.

Introduction

Engee has the ability to connect external equipment -. such as, for example, a COM port. This interface can be used to connect not only office and multimedia devices, but also instrumentation devices such as sensors, microcontrollers, programmable logic controllers.
To familiarise ourselves with the possibilities of using COM connection in the Engee model, in this example we will send data - a periodic discrete signal to the Arduino MEGA microcontroller.

Example model

The example model - com_send_blink.engee contains two blocks from the Interfaces -> COM section of the Engee block library:

  • COM Setup - for connection setup,
  • COM TX - for serial data transfer from Engee.

image_2.png

Interface settings, block COM Setup:

  • port name - for Windows, this is, for example, "COM5";
  • baud rate, baud - 9600;
  • the number of data for reception-transmission, bits - 8;
  • number of stop bits for reception-transmission, bit - 1;
  • parity bit - none.

In the transmitter block COM TX it is necessary to define the port name - "COM5" and the buffer size for transmission = 1.

To the inputs of this block are transmitted:

  • number of elements from the data array for transmission: number in the format UInt32in our case = 1,
  • vector of data to be transmitted in the format UInt8.

The second input will supply a periodic pulse signal with amplitude = 1, fill factor $D=50\, \%$ and variable period.

Preparation for the execution of the model

Before running a model in Engee, several preparatory steps must be performed as described in manual.

Installing the support package

Run the following command at the Engee command line:

bash.
engee.package.install("Engee-Device-Manager")

After executing the command, the following messages will be displayed indicating that the external hardware support package was successfully installed in Engee:

image_2.png

Using the link provided, depending on the operating system, you need to download the archive, unzip it and run the client programme.

Connecting to Engee

Next, in the opened window of the client programme you should enter the received link for connection and click the "Connect" button:

image.png

The message "Connection to server established!" and the connection status "Connected" in the client programme window indicate that Engee has gained access to the computer interfaces.

❗️ Do not close the user programme window during operation, otherwise the connection will be lost.

Connecting the Arduino

Now let's connect the equipment to the "COM5" port specified in the model.

❗️ The port name to which you connect your device according to this example can be switched off. Determine the name of the port to which your device is connected and set it in the interface setting blocks of the model (COM Setup and COM TX).

In this example, the Arduino MEGA is connected to port "COM5", which is indicated by the connection status in the Arduino IDE:

image.png

You can also define the port in the Arduino IDE connection settings:

image.png

Arduino programming

The programme for processing the data received by Arduino from Engee over the serial port is given in the sketch arduino_com_read_sketch.ino.

The principle of the programme operation is described in detail in the sketch comments. The essence of the work is as follows. If the controller receives "1" from Engee, it lights up the LED built on the board, if it does not receive "1", the LED does not light up.

To program the Arduino Mega, simply do the following:

  • download the arduino_com_read_sketch folder with the sketch,
  • open the sketch in Arduino IDE,
  • determine the board model - Arduino Mega or Mega 2560 and the port name - in the case of this example it is COM5,
  • check the sketch,
  • upload it to the board.

In case of successful download and compilation you can proceed to the execution of the model in Engee, which will send signals to Arduino MEGA via COM.

Executing the example model

❗️ Before running the model in Engee, ensure that the steps are completed:

  1. The External Hardware Support Pack is installed.
  2. The client programme from the support package is running.
  3. The Engee connection status in the client programme is "Connected".
  4. The controller is connected in the COM port.
  5. A COM signal processing programme is running on the controller.
  6. The name of the COM port to which the controller is connected corresponds to that set in the model's interface blocks.

Let's run the model in Engee, after compilation we can observe the formation of a pulse signal on the Engee graph and synchronous flashing of the LED on the Arduino MEGA board:

ubar.gif

The parameters of the blocks can be changed while the model is running, in other words "on the fly". From the above video it can be seen that Engee successfully transmits a periodic pulse signal with variable frequency to the microcontroller via COM port.

Conclusion

In the example model the process of setting up the connection to external equipment was considered, and also the beginning of work with the transfer of signals from Engee to the serial port of a personal computer was described. The example model generates a periodic pulse signal, and the Arduino MEGA microcontroller connected to the computer receives this signal via COM port with further processing.