Home Solutions Host-to-Smart Display CANopen Communication with Button and Indicator Control

Host-to-Smart Display CANopen Communication with Button and Indicator Control

July 25,2023

Introduction

CANopen Communication Between the Host and Smart Display

Controlling a Smart Display requires a system interface and communication protocol. From a host-control perspective, this article uses a practical Arduino example to demonstrate how the HOST sends commands to change the color of an indicator on the Smart Display. In this example, a touch button is placed on the UI and a physical button is connected to the Arduino. Pressing either the physical button or the touch button changes the color of the on-screen indicator and turns the external LED on or off.

This application demonstrates how to use an Arduino development board to control a 3.5-inch CAN Smart Display, including how to program the physical button, touch button, on-screen indicator, and LED on the board, as well as how the Smart Display receives commands from the HOST. An Arduino Mega 2560 equipped with a CAN Bus shield serves as the host controller and communicates with the Smart Display via CANopen.

The system block diagram is shown below:

CANopen communication between Arduino host and Smart Display

System Block Diagram

The following components are required for this application:

  1. 3.5-inch CANopen Smart Display
  2. Arduino Mega 2560
  3. CAN Bus shield for Arduino Mega 2560
  4. CAN Bus Dongle
  5. Physical button
  6. LED
  7. Smart Display GUI Builder v0.4.2 or later
 

This demo is divided into three parts:

  1. Design the project in GUI Builder
  2. Build and upload the project
  3. Program the Arduino host
 

Design the Project in GUI Builder

First, create a new project and enter a project name. Select the device type; this example uses a 3.5-inch device. Select CANopen as the communication protocol and set the display orientation to Landscape. Next, select the Blank Template from the UI templates, and then click Create to create the new project, as shown below.

02-design-the-demo-project-in-gui-builder

After completing these settings, a blank page will open.

02-design-the-demo-project-in-gui-builder-1

For this application example, add a touch button and an Indicator widget to the workspace. Select the required widgets from the control panel and drag them onto the workspace, as shown below.

02-design-the-demo-project-in-gui-builder-2

Build and Upload the Project

After completing the previous settings and UI design, the project is ready to be built and uploaded. Click Device on the GUI Builder toolbar and select Device Property. In the Device Property window, you can use the default baud rate or adjust it according to your application requirements. Make sure that the baud rate configured in the Arduino program matches the setting in GUI Builder. After completing the settings, click Upload to upload the project to the Smart Display, as shown below.

03-build-and-upload-the-project

When the project upload is complete, the message "Upload project completed" will appear. Click OK to close the window, as shown below.

03-build-and-upload-the-project-1-1

After the upload is complete, the Smart Display will show the startup screen, as shown below.

03-build-and-upload-the-project-2-1

After the startup screen, the Smart Display will switch to the uploaded application page, indicating that the project has been successfully built and uploaded.

03-build-and-upload-the-project-3-1

Program the Arduino Host

This example uses Arduino IDE v2.0.4 to program the Arduino host. The mcp2515_can.h library and several supporting libraries are used for CAN Bus communication. For more details, refer to the Arduino code. When establishing communication between the host and the Smart Display, it is important to verify the addresses associated with the objects. For more information about CAN Bus communication between the host and the Smart Display, refer to the communication log in GUI Builder. The required object addresses are defined in the Arduino IDE program, as shown below.

04-program-the-arduino-host

In the CANopen structure, the index of the Button style corresponds to 0 (0x2000), while the index of the Indicator style corresponds to 1 (0x2001). It is important to take note of each object's index. If the index of an object is known, its status can be changed through the Arduino host program. The corresponding object indexes can be observed in the command information shown in the simulation log table below:

04-program-the-arduino-host01-1

 

04-program-the-arduino-host01-2

The data type of each object is defined here. If additional objects are required, their corresponding data types must also be defined in the program.

04-program-the-arduino-host02

The following figure shows how ObjectFunCallback handles the values received from each object. Users can modify the code or add additional object-handling logic according to their application requirements.

04-program-the-arduino-host03

When the Arduino host detects a change in the physical button state, it sends the corresponding value to the Smart Display via CANopen. Refer to the following code for the IDs and sub-indexes used in the command structure. This section of the program updates the value of the Indicator (object index 2) according to the state of the physical button.

04-program-the-arduino-host04

Define the register addresses for all objects, configure the pin modes for external components such as the physical button and LED as inputs or outputs, and set the baud rate, as shown below:

04-program-the-arduino-host05-1

04-program-the-arduino-host05-2

Finally, the logic required for this application scenario is defined in the loop(). When either the physical button or the touch button on the Smart Display is pressed, the system changes the color of the on-screen Indicator and turns the external LED on or off.

04-program-the-arduino-host06

After successfully verifying and uploading the program through Arduino IDE, pressing either the physical button or the touch button on the Smart Display turns on the LED and changes the Indicator color to green. When the Indicator is red and the LED is off, neither the physical button nor the touch button is being pressed, as shown below.

05-appendix-set-up-the-project

The program described above can be downloaded from the GitHub link. Additional files and information about this demo project are also available in the examples. The actual hardware setup is shown below.

05-appendix-set-up-the-project01

After completing these steps, the physical button or the touch button on the Smart Display can be used to control the on-screen Indicator status and the external LED, completing this Smart Display CANopen communication demo.

Conclusion

This example demonstrates the operation and application of GUI Builder while helping users understand how to develop host-side control applications using CAN Bus. It also shows how the host sends and receives commands to control the Smart Display. Through this example, developers can gain a better understanding of CANopen communication and control between the host and the Smart Display and use it as a reference for developing Smart Display applications.

Have questions about display solutions for your business? Contact Us!

Subscribe

Receive emails about news updates from Winstar.

Contact Us

Price/Datasheet/General inquiry

Technical Support

Contact us for any technical information

go top
Contact Us
close

We value your privacy

By clicking "Allow All Cookies", you agree to the storing of cookies on your device to enhance site navigation, analyse site usage, and assist in our marketing and performance efforts. You can find further information this subject in our policy.

We value your privacy

Winstar and certain third parties use cookies on www.winstar.com.tw. The details regarding the types of
cookies, their purpose and the third parties involved are described below and in our Cookie Policy.
Please click on “Allow All” to consent to our usage of cookies in order to have the best possible
experience on our websites. You can also set your preferences or reject cookies (except for strictly
necessary cookies).

Manage Consent Preferences

Always Active
Essential Cookies

These cookies are essential in order to enable you to move around the website and use its
features, such as setting your privacy preferences, logging in or filling in forms.

Analytics Cookies

Also known as “statistics cookies,” these cookies collect information about how you use a website, like which pages you visited and which links you clicked on. See Detail