Category : CAN-BUS PROJECTS
In this section we will see how to configure the module RubinoLAB CAN-ISO on Arduino and how to test it.
The implemented protocol uses a standard ASCII communication. This makes the system compatible with any program (Python, LabVIEW, MATLAB etc), simple to adapt to your project.
The first step is to install the MCP_CAN library (if you have not already installed it), in the Arduino editor. Here is the link of the library:
Create a project with the example code shown here or alternatively download the attached project and unpack it in your workbook.
Compile and upload it to the Arduino module.
Now we are ready to start!
Code test (Transmission)
A typical CAN-Bus connection in the industrial automation domain is shown in the figure, where there is a master and several multi slaves. In the master/slave one device or process (known as the master) controls one or more other devices or processes (known as slaves). Once the master/slave relationship is established, the direction of control is always from the master to the slave(s).
For the code test it is necessary to create a CAN-BUS micro-network, for example using two Arduino CAN-BUS interfaces.
For the example code shown here we used an Arduino CAN-BUS interface connected to a commercial CAN-BUS interface.
NB. The interface is configured for a CAN communication speed of 500kbps. Change this value in the code for a different speed. The addresses are configured to 11bit.
Open the serial terminal from the Arduino editor and configure it for a speed of 115200 baud, no flow control.
Enter the following string: @00A0102030405060708 and press enter.
The string consists of three parts:
- @ (Attention) warns the interface that a new string is coming and that it must realign for a new send
- 00A destination address
- 01 02 03 04 05 06 07 08 are the 8 bytes to be sent in hexadecimal format. Recall that a hexadecimal byte is between 00 and FF.
If all the operations have been carried out correctly, the other interface will receive at the address 0A the bytes as in the sequence shown.
Code test (Reception)
For the reception code test, the reverse operation is performed.
We send to the address 0B, the string 08 07 06 05 04 03 02 01
In reception we will have an ASCII string formatted in the same way as the transmission, as shown below:
A YouTube video where CAN-ISO communicates with a CAN BUS industrial device, using the “CANINO” code and the “LabView” graphical interface:
Now that the code is tested and we are able to transmit / receive a generic package, appropriately formatted, the next step is to use the interface with a program. In the next tutorial we will see how to use the interface with Python, LabVIEW, MATLAB, bash shell and others.
Contact us to let us know your opinions: info(at)rubinolab dot com