Skip to content

SOLO Arduino Library – Hello World

Arduino

Introduction

In this article, we would like to help with the first step in order to make communication between SOLO and Arduino using our Arduino library that works on top of digital protocols. Using this library you are able to send complex orders to SOLO using protocols such as UART and CANopen.

We will start to discuss the Arduino setup and then explain the UART and CANopen alternatives as they will change the schematic between Arduino and SOLO plus a couple of code lines! We will start with UART which is easy in terms of Hardware demands and we will finish with the CANopen protocol as the suggested one in terms of quality of communication but with the throwback of requiring an Arduino Shield as not on board protocol supported by Arduino.

Is also possible to access the Code documentation here, which lists in detail the Library code

Arduino IDE

In order to program your Arduino, you need an IDE capable of compiling and flashing your Arduino. Alternatives are possible, but we stick to the official Arduino IDE over our examples. (Is possible to use the suggested IDE 2 or the iconic old IDE)

Include The Library

In order to use the library you first need to include the library in the Arduino IDE. You can do it in the Arduino IDE 2 with Library icon on the left > search for SOLO Motor Controllers library > Install the last version

Arduino IDE 2 Install Library

Old IDE with Sketch>include Library> Manage Libraries… >SOLOMotorControllers > Install, As in the image show

import

After restarting the Arduino IDE is also possible to see our example in the Arduino IDE (Similar for IDE2 or old IDE) File>Examples>SOLOMotorControllers> as show in the image too

examples

Manually Include The Library

Manually is possible to install the library following this step (We showcase the process with old IDE) :

1. Download the library from our GitHub repo:

git step

2. Include the library in the ARDUINO IDE*:

2.1. Unzip the downloaded library.

2.2. Create a new zip folder and insert on it the file you find in the SOLO-motor-controllers-ARDUINO-library/src (the name can be “SOLO”)

2.3. In the Arduino IDE go to Sketch > Include Library > Add.Zip Library.. And selected the zip file created in the previous step 2.2

tutorial1

*A deeper documentation on how to include the library is possible to be found on the Arduino website.

3. At this point when you compile a sketch that include the SOLO ARDUINO library, it will succeed.

tutorial2

System Calibration

To find the proper setup for your system we suggest using the Motion Terminal, this Application gives all the tools for properly identifying and testing the proper values without the need to do these activities programmatically. When the Calibration is done you will probably not need to bring this step in your code as these parameters are saved in the non-volatile memory of your Solo Unit. In Motion Terminal all the parameters that will be stored in the non-volatile memory are identify by the Floppy Disc Icon (💾) close to the name of the parameter.

UART

The library supports the UART protocol, which is used to send and receive packet information. The protocol itself is one of the most common and widespread protocols thanks to the simplicity of use and implementation. The trade-off of simplex protocol and cheaper hardware requirements is the stability of the protocol itself, as it does not prevent communication errors or it is not designed for network systems or for high-density communication.

SOLO Controllers Configuration

SOLO devices are able to use the UART protocol with different Baud Rates that define the speed with which the communication happens.

A high Baud Rates determinate a faster communication and a less performance demand on SOLO, for this reason, the default UART Baud Rate for solo is set to 937500 but is possible to be changed it in the Motion Terminal, in the section: Action / Configuration / UART Line baud-rate[bits/s]*

If the SOLO has a different baud rate than ARDUINO the communication will not work. Is possible to change the ARDUINO baud rate directly using the library, as in the construction line you can set the baud rate.

Arduino Tips

We suggest to use great entry level as Arduino UNO R4 Minima or Arduino UNO R4 WiFi to have better perform especially if you want to use the UART protocol.

Arduino UNO R3, Older or Similar Note

NOTE 1: Whenever you want to program old ARDUINO UNO board through the ARDUINO IDE, YOU need to disconnect the UART_RX of ARDUINO UNO, by not doing this, you might get some errors in ARDUINO IDE during uploading the code.

( In ARDUINO UNO, there is only 1 line of UART which is shared between the UART to USB convertor of the ARDUINO board itself which is also used for flashing the ARDUINO UNO board as well. To know more, read this post on the ARDUINO website). )

NOTE 2: For Arduinos rated at +5V, to have a consistent start-up while Arduino is connected to SOLO, you need to make sure that the +5V output of SOLO is also connected to the +5V of Arduino

(Arduino might disturb SOLO during boot-up stages due to over-current drained from TX and RX lines.)

Schematic

In order to have communication between Arduino and SOLO we need to connect the 2 devices.

Over the UART protocol we need to have this general condition and connect this pinout:

Device 1 TX to Device 2 RX

Device 2 RX to Device 1 RX

GND Device 1 to GND Device 2

*Device 1 can be ARDUINO or SOLO, the same for Device 2.

ARDUINO models have different pin numbers and locations to be used. And some models have more than 1 UART protocol line to be used. A reference here.

Wirings

SOLO UNO wiring

SOLO UNO ARDUINO UART Wiring

Check SOLO UNO

SOLO PICO

solo pico connecting setup guide 3

Products Specs page here

SOLO MINI

solo mini connecting setup guide 3

Products Specs page here

SOLO UNO

solo uno connecting setup guide 3

Products Specs page here

SOLO MEGA

solo mega connecting setup guide 3

Products Specs page here

Tips

We suggest not to use the default serial line of the Arduino as it can be shared with USB port of it! But what does it mean in practice?

If you run a program, using the default serial line, printing command to the serial monitor and use our library, you will see a lot of ??? in the serial monitor. That symbols are in reality communication shared between SOLO and Arduino. It’s not only hard to read the serial monitor, but all the text printed using Serial are also going inside the communication between the 2 boards creating noise and extra pressure over the protocol. If the Serial print is highly used it can lead to a complete distortion of the normal communication between the devices. In this case, the suggestion is to reduce the character to be printed in the serial monitor or to use a different Serial line considering also changing the type of ARDUINO used as ARDUINO Uno has only one option but Mega, Due and other models have different UART lines.

Example Code

Is possible to see example codes in the example folder of the repository.

For this time we will use this code:

temperature.ino
#include "SOLOMotorControllersUart.h"
SOLOMotorControllers *SOLO_Obj1;

void setup() {
  Serial.begin(115200);
  SOLO_Obj1 = new SOLOMotorControllersUart();
}

void loop() {
  Serial.println((String) "Read from SOLO the temperature: " + SOLO_Obj1->GetBoardTemperature());
  delay(1000);
}

The previous code will simply print the temperature read from SOLO board.

Is also interesting to share with you a bit of code related to the alternative in the construction of the SOLO class that gives the possibility to change the parameters of the protocol.

uart_protocol_class_initialization.ino
#include "SOLOMotorControllersUart.h"
SOLOMotorControllers *SOLO_Obj1;

//EXAMPLE 1: All setup are as default:
SOLO_Obj1 = new SOLOMotorControllersUart();

//EXAMPLE 2: All parameters are as default but explicit:
//This option give no difference to the example 1
int SOLOdeviceAddress = 0;  //Device adress of SOLO (default vale in SOLO units is 0)
HardwareSerial &serialSelected = Serial; // Serial port that Arduino will use (Arduino 1 have only Serial, but other version have more like Serial1)
SOLOMotorControllers::UartBaudrate baudrate = SOLOMotorControllers::UartBaudrate::rate115200;  // Boudrate Arduino will use for the comunication (SOLO neet the same value, is possible to set in the Motion Terminal)
long millisecondsTimeout = 200; //Timout in milliseconds before interrupt the wait
int packetFailureTrialAttempts = 5; //How many time will happen a try on the same comunication if an error heppen
SOLO_Obj1 = new SOLOMotorControllersUart(SOLOdeviceAddress, serialSelected, baudrate, millisecondsTimeout, packetFailureTrialAttempts);

//EXAMPLE 3: Partial usage of paramets
//the order of the parametrs is mandatory, but the value can change
int SOLOdeviceAddress = 3;  //Device adress of SOLO (default vale in SOLO units is 0)
SOLO_Obj1 = new SOLOMotorControllersUart(SOLOdeviceAddress);

//EXAMPLE 4: Partial usage of paramets without variable
//is possible to pass directly in the Initialization the value
//in this case, we have no difference with the example 3
SOLO_Obj1 = new SOLOMotorControllersUart(3);

CANopen

For the most demanding and industry-based applications, the library supports the CANopen protocol, which can be used as a protocol between Arduino and SOLO, simple to use as the UART section of the library. In nutshell, the protocol is much more strong in comparison to UART, able to support high-intensity communication, error handling, and networking. The throwback of this will be the requirement of extra hardware as Arduino doesn’t have it embedded, so an Arduino shield board is required. SOLO has the CAN on board so it’s self-sufficient if used in different CANopen environments rather than Arduino.

As the CANopen is not on board for ARDUINO we choose to develop the protocol on top of the MCP2515 chip that is available for Arduino in several formats as a shield or as an external board.

The compatible solutions are: CAN-BUS Shield V2.0 or Arduino MKR CAN Shield, during this article we will give more visibility to the CAN-BUS Shield V2.0 as it looks reasonable more convenient for Arduino Uno users.

SOLO Controllers Configuration

If the SOLO has a different baud rate than ARDUINO the communication will not work. Is possible to change the ARDUINO baud rate directly using the library, as in the construction line you can set the baud rate. You can change the SOLO baudrate in the Motion Terminal, in the section: Action / Configuration / CANopen baud-rate[kbits/s]*

Schematic

In order to have communication between Arduino and SOLO we need to connect the 2 devices.

Over the CAN open protocol we need to have this general condition and connect this pinout:

Device 1 CANH to Device 2 CANH

Device 2 CANL to Device 1 CANL

GND Device 1 to GND Device 2

*Device 1 can be Arduino or SOLO, the same for Device 2.

Wirings

SOLO UNO wiring

SOLO UNO CANsheild Connection CANopen 1

Check SOLO UNO

SOLO MINI wiring

SOLO MINI CANsheild Connection CANopen

Check SOLO MINI

Example Code

Is possible to see example codes in the example folder of the repository.

For this time we will use this code:

temperature_canopen.ino
#include "SOLOMotorControllersCanopenMcp2515.h"
SOLOMotorControllers *SOLO_Obj1;

void setup() {
  Serial.begin(115200);
  SOLO_Obj1 = new SOLOMotorControllersCanopenMcp2515();
}

void loop() {
  Serial.println((String) "Read from SOLO the temperature: " + SOLO_Obj1->GetBoardTemperature());
  delay(1000);
}

The previous code will simply print the temperature read from SOLO board.

Is also interesting to share with you a bit of code related to the alternative in the construction of the SOLO class that gives the possibility to change the parameters of the protocol.

canopen_protocol_class_initialization.ino
// EXAMPLES of all to setup possible with UART Protocol
#include "SOLOMotorControllersCanopenMcp2515.h"
SOLOMotorControllers *SOLO_Obj1;

//EXAMPLE 1: All setup are as default:
SOLO_Obj1 = new SOLOMotorControllersCanopenMcp2515();

//EXAMPLE 2: All parameters are as default but explicit:
//This option give no difference to the example 1
int SOLOdeviceAddress = 0;  //Device adress of SOLO (default vale in SOLO units is 0)
int chipSelectPin = 9; //The chip select dipends on what board you want to work with, the default value is matching with shild board for arduino uno CAN-BUS Shield v2.
SOLOMotorControllers::CanbusBaudrate baudrate = SOLOMotorControllers::UartBaudrate::rate1000;  // Boudrate Arduino will use it for the comunication [kbits/s] (SOLO need the same value, is possible to set in the Motion Terminal)
long countTimeout = 6000 //Iteration before interrupt the receive from SOLO
SOLO_Obj1 = new SOLOMotorControllersCanopenMcp2515(SOLOdeviceAddress, chipSelectPin, baudrate, countTimeout);

//EXAMPLE 3: Partial usage of paramets
//the order of the parametrs is mandatory, but the value can change
int SOLOdeviceAddress = 3;  //Device adress of SOLO (default vale in SOLO units is 0)
SOLO_Obj1 = new SOLOMotorControllersCanopenMcp2515(SOLOdeviceAddress);

//EXAMPLE 4: Partial usage of paramets without variable
//is possible to pass directly in the Initialization the value
//in this case, we have no difference with the example 3
SOLO_Obj1 = new SOLOMotorControllersCanopenMcp2515(3);

Errors

Communication errors can happen for a lot of reasons and thinking the communication will be every time successful can not be the correct approach for every application. So here is an example that shows how to check possible errors, this will help to make code more resilient. .

error_handling.ino
//EXAMPLE 1: get function with no error
// if error happen the value recived is -1
long commandMode = SOLO_Obj1->GetCommandMode();
Serial.println((String)"COMMAND MODE: " + commandMode);

//EXAMPLE 2: get function with error
int error; // if is 0 mean no Error Detected.
long commandMode = SOLO_Obj1->GetCommandMode();
Serial.println((String)"COMMAND MODE: " + commandMode + " ERROR: "+ error );

//NOTE error is generated following this enum SOLOMotorControllers::Error
  enum Error
  {
    NO_ERROR_DETECTED = 0,                      /*!< no error detected */
    GENERAL_ERROR = 1,                          /*!< general error */
    NO_PROCESSED_COMMAND = 2,                   /*!< command is not valid */
    OUT_OF_RANGE_SETTING = 3,                   /*!< setting is out of range */
    PACKET_FAILURE_TRIAL_ATTEMPTS_OVERFLOW = 4, /*!< trial attempt overflow */
    RECEIVE_TIMEOUT_ERROR = 5,                  /*!< receive time error */
    ABORT_OBJECT = 6,                           /*!< abort object */
    ABORT_VALUE = 7,                            /*!< abort value */
    MCP2515_TRANSMIT_ARBITRATION_LOST = 8,      /*!< MCP2515 transmit arbitration lost */
    MCP2515_TRANSMIT_ERROR = 9,                 /*!< MCP2515 transmit error */
    OBJECT_NOT_INITIALIZE = 10,                 /*!< Kvaser object not initialize */
    CAN_EMPTY_BUFFER = 11,                      /*!< Kvaser buffer have no data for the defined COBID */
    PDO_PARAMETER_ID_OUT_OF_RANGE = 12,         /*!< PDO configuration id out of range */
    PDO_SYNC_OUT_OF_RANGE = 13,                 /*!< PDO configuration sync out of range */
    PDO_MISSING_COB_ID = 14,                    /*!< PDO no specific CobId for the specified pdo*/
    PDO_RTR_COMMAND_NOT_ALLOWED = 15,           /*!< PDO RTR specific command not allowed*/
  };

//EXAMPLE 3: is possible to compare the error with SOLOMotorControllers specific error
if (error != SOLOMotorControllers::Error::noErrorDetected)
{
  Serial.println(" Error happen, is possible to react according to this sitatuon!");
}

//EXAMPLE 4: set funtion with no error
// if error happen the value recived is -1
SOLO_Obj1->SetCommandMode(SOLOMotorControllers::CommandMode::analogue);

//EXAMPLE 5: set function with error
int error; // if is 0 mean no Error Detected.
SOLO_Obj1->SetCommandMode(SOLOMotorControllers::CommandMode::analogue, error);
Serial.println((String)" ERROR: "+ error );

//EXAMPLE 6: set function with error and success boolean
bool isSetSuccess; // set function return True if the operation go well
int error; // if is 0 mean no Error Detected.
isSetSuccess = SOLO_Obj1->SetCommandMode(SOLOMotorControllers::CommandMode::analogue, error);
Serial.println((String)"SUCCESS : "+ isSetSuccess + " ERROR: "+ error );

*Error handle have no difference between UART and CANopen

* The Get and Set functions have no difference between UART and CANopen If you are stuck, here is a simple list a common reason:

– If SOLO E2 led is not blinking there are some issues and a proper power cycle of SOLO is needed

– If communication has an issue check that SOLO and Arduino have the correct baud-rate setup

Final Tips

As you probably get a lot of possibilities are given within the library, you can use different Arduino boards or different protocols (UART, CANopen) too, and most of the considerations are based on your specific requirements and constraints but as general considerations, we personally overall suggest to use CANopen protocol using Arduino shield + Arduino, and when you have space or hardware constraints we suggest to evaluate the UART protocol using Arduino UNO R4 or similar.

Products in this article

SOLO UNO V2

SOLO UNO V2

175.00€

In Stock

SOLO MINI V2

SOLO MINI V2

159.00€

In Stock

Browse all categories

Drive your next innovation today

Discover our High-Performance Motor Controllers, Test Benches, and Services trusted worldwide.