Home

>

Components

Arduino

In this tutorial, we’ll show you how to connect Arduino to Leo Rover.

Prerequisites

No items found.

Home

>

Components

Arduino

In this tutorial, we’ll show you how to connect Arduino to Leo Rover.

What is Arduino?

Before we get started, let’s say a few words about what Arduino actually is.

Arduino is an open-source electronic platform that allows users to easily access advanced technologies interacting with the physical world.

What do I need Arduino for?

You might wonder what the point of having Arduino inside Leo Rover is. After all, isn’t the robot already equipped with a Raspberry Pi micro-computer?

Well, the simplicity of Arduino makes it more convenient for typical hardware projects. Arduino has analog capabilities that the Raspberry Pi lacks by default. Its flexibility allows you to work with almost any type of sensor.

Arduino speeds up the creation of simple projects that don’t require advanced software and a good Internet connection.

Let's not forget that behind the name "Arduino" hide many boards, so if you want to learn how to choose the best one for your project, look here. For our projects, we mostly use Arduino DUE.

What to expect?

Having finished the tutorial you'll know how to connect Arduino to the Leo Rover and use its potential to further improve your projects and make the development process of future projects a little bit faster.

Prerequisites

No items found.

List of components

  • Any Arduino ( or any other compatible board)
  • Any way of connecting the board to the rover
  • USB cable

Mechanical integration

We have created mechanical interfaces for Arduino DUE, which you can get here:

  1. Arduino Due, Addon quarter base.
  2. Arduino Due, Addon quarter cover.

You'll need to press in ten M3, threaded heat-set inserts into the base part. This allows you to use M3x6 Allen screws to hold the Arduino securely. The cover is held by 4 screws of the same size.

Since Arduino Due has the largest footprint out of all the Arduino boards it should be pretty easy to adapt the provided Arduino DUE adapter models to fit other boards inside. All you need to do is use 3D CAD program like fusion 360 to change the way mounting holes for the board are positioned.

Wiring and electronics connection

For most intents and purposes the only connection you need to provide is an USB connection between the board and the USB port at the top of the rover. However, you may want to provide the microcontroller, and the sensors that you are using, with external power source. For such cases powerbox addon might be a good choice.

Software integration

There are several ways to integrate Arduino into the rover. From this tutorial, you’ll learn about two of them so that you can decide which one works best for you. 

The mechanical-engineer way

This way saves you from having to dive into the rover’s insides. It works; however, it does not allow you to communicate between the rover’s onboard computer and Arduino – this, in turn, makes it harder to use the data harvested by any sensors connected to the Arduino. 

First, install Arduino IDE using any of those provided tutorials:

Then, you need to set up Arduino IDE (we’re using Arduino DUE which needs a special configuration in Arduino IDE).

To do so, do as follows: while in IDE, go to: tools -> Board -> Boards Manager

Arduino IDE boards manager navigation screen

Type “DUE” in the search bar and install the latest version of Arduino SAM Boards (32-bits ARM Cortex-M3).

The next step is to take care of the board specific setup:

  • Connect the board to a USB port in your computer (use the port closer to the barrel jack socket)
  • Go to: tools -> Board -> Arduino ARM (32-bits) Boards and choose Arduino Due (Programming Port)
Arduino Due programming Port in Arduino IDE
  • Go to: tools -> Port and choose the port Arduino is connected to
Arduino IDE choosing programming port

Checking setup

The easiest way to check if the board is working, is to use pre-created example codes. One of them is the blink sketch provided in the Arduino IDE examples.

Go to: File -> Examples -> 01.Basics and choose the Blink sketch

Arduino IDE blink example

You should see something similar to this:

Arduino IDE blink example code

Now, you’ll have to verify the code and send it to the board. First, make sure the correct board and ports are chosen as shown below:

Arduino IDE chosen port and board

Now you can verify(1) and upload(2) the code.

Arduino IDE verify and upload code

After a few seconds, you should see two things:

  • The following statement (at least when using Arduino DUE, the statement might be different for other boards):
Arduino IDE done uploading code statement
  • And Arduino’s built-in LED blinking.

Unplug the Arduino from your computer and move it to the rover’s USB Port.

With this step, you have moved all of your Arduino functionality to a battery-powered mobile development platform.

Check this site for more ideas.
You can also visit our site - coming soon.

The software engineer way

This way allows you to communicate between the rover’s onboard computer and the Arduino board. However, it takes a bit longer to set up than the previous method.
Following the steps below gives you the ability to use Arduino IDE and programming the boards directly from the Leo Rover’s on-board computer. This means that you won’t have to disconnect the board from your computer and connect it to the Leo Rover every time you make a small change in the code. However, it comes with a drawback of using a less powerful computer to write the code at.
If reconnecting the Arduino between your computer and Leo Rover every time you make a change to the code is not a problem to you follow The mechanical-engineer way and then skip to Setting up the Rosserial communication.

First connect to the rover via Remote Desktop and connect the rover to the network (see Prerequisites).

Now, install and set up Arduino IDE following instructions below:

  • Visit this website and download the latest version of Arduino IDE. Make sure to get the Linux ARM 64 bits version.

Now, you need to extract the .tar file. To do so open new terminal (ctrl + alt + t) and go to the downloads directory, and unpack the Arduino installation files with tar command.

Unpacking might take a while, just wait untill it's completed.

Also make note of what Arduino IDE version you are installing as it might be different. If you are not sure, what is your file, check the files while beeing in Downloads directory with ls command.

You can see the unpacked files in the directory using ls command.

Now you need to move extracted files from Downloads directory, to /opt directory. To do so type (while being in Downloads directory):

When you are using sudo you might get asked for root password. Just type it in, and confirm with Enter.

Then you need to install the files. To do so go to the moved Arduino files in /opt directory and run install.sh script.

Once again pay attention to your Arduino files version, so you go to the correct directory.
You may also need to give execution rights to install.sh script. To do so type
sudo chmod +x install.sh

Arduino IDE should be installed and you should see new icon on the Desktop.

Arduino IDE desktop icon

Now, connect Arduino to the rover. To do so, plug the USB cable in and then, open the Arduino IDE.

After that, set up the board specific options doing the following steps:

While in IDE, go to: tools -> Board -> Boards Manager

Arduino IDE boards manager navigation screen

Type “DUE” in the search bar and install the latest version of Arduino SAM Boards (32-bits ARM Cortex-M3).

Arduino IDE, Arduino SAM Boards installation

The next step is to take care of the board specific setup:

  • Connect the board to a USB port in your computer (use the port closer to the barrel jack socket)
  • Go to: tools -> Board -> Arduino ARM (32-bits) Boards and choose Arduino Due (Programming Port)
Arduino Due programming Port in Arduino IDE
  • Go to: tools -> Port and choose the port your board is connected to.
Arduino IDE choosing programming port

Checking setup

The easiest way to check if the board is working, is using pre-created example codes. One of them is the blink sketch provided in the Arduino IDE examples.

Go to: File -> Examples -> 01.Basics and choose the Blink sketch

Arduino IDE blink example

You should see something similar to this:

Now, you’ll have to verify the code and send it to the board. First, make sure the correct board and ports are chosen as shown below:

Arduino IDE chosen port and board

Now you can verify(1) and upload(2) the code.

Arduino IDE verify and upload code

After a few seconds, you should see two things:

  • the following statement:
Arduino IDE done uploading code statement
  • and Arduino’s built-in LED blinking

Setting up the Rosserial communication

First step is to download the rosserial library.

Go to: tools -> Manage Libraries

Arduino IDE manage libraries

Type “rosserial” in the search bar and download Rosserial Arduino Library

Arduino IDE rosserial arduino library installation

The board that we are using - Arduino Due - needs one additional step in order to properly work with rosserial.

Skip this step if you are using another board.

Find ArduinoHardware.h 

  • The proper path to find the folder is as follows: /Arduino/libraries/Rosserial_Arduino_Library/src
ArduinoHardware.h
  • Modify line 73 to state:
ArduinoHardware.h modification

Examples

From this point forward, most of our instructions will be rephrased instructions made by wiki.ros.org. You can check this site for more detailed instructions.

In the first tutorial, you can see how to get data from Arduino to the rover’s mind

Arduino Code (hello world – simple publisher)

You can get to the sample code by following the path shown below

Arduino IDE hello world tutorial path

Upload the code to Arduino. Make sure to use the correct PORT and BOARD in Arduino.

Arduino correct board and port selection

Then, start a new terminal window and launch rosserial node, that will start communication between Arduino and the rover's onboard computer.

Remember to set the port argument, to the same port you saw in Arduino IDE.

__name argument can be set to whatever you like your node to be called

Start another terminal window and check the list of running nodes (you should see your node there)

You can get more information about your node - eg. what topics it is listening/publishing to. As you can see, /Arduino_COM_node is publishing to /chatter topic

After "/", you need to provide the correct name of your node. You can start typing the name, and fill the line with tab key (double tap).
rosnode info on /Arduino_COM_node

You can also see list of all active topics (You should see one called “chatter” that was created by Arduino after you’ve created the node you’ve named)

Now to see data published to our topic, type in the terminal

If everything went according to our plan, by running this command you should be able to see the Arduino sending “Hello World” message to this topic.
CTRL + C lets you stop the program running in the terminal.
rostopic echo on chatter topic

Arduino as publisher and subscriber

In this example, we will show you our real live use case of Arduino with LeoRover.

Description

Our task was to check whether there is a correlation between soil quality and motor current in Leo Rover pulling a plow. Therefore we have designed a lowered plow, capable of gathering pulling force data and drove Leo Rover through soil of different quality, while gathering the data. And in the end, we could analyze gathered data.

Leo Rover with lowered plow

The Plow is connected to the rest of the rover with a strain gauge beam. Pulling force can be observed as tiny changes in voltage, that get amplified with an amplifier. Arduino is used to gather the data and send it to the computer.

It's obvious that you will not be able to follow this guide with a plow, so you can replace it with a potentiometer or any other analog sensor.
Here are the instruction, how to connect it, so it works with the rest of the tutorial:
  • Connect your sensor to pin A0 on Arduino
  • Use 2 LEDs connected to respectively digital pin 10 and digital pin 11 (remember to use resistors) to test the subscriber part of the code

Code

Running and visualizing

With the code imported to Arduino and all the necessary wires connected, you can start the Arduino node. To do so, open new terminal and type

In another terminal run

You’ll see a graph following the changes in sensor output.

rqt_plot screen shot

Sending either True or False to plow_control topic controls the plow position for us (either lowered or raised) for you it can control any binary device e.g. turn the LEDs on and off. You can send those messages by typing in the terminal

Or

For instructions related to data recording refer to this site. And If you want to make recordings easier to use, you can change .bag files to .csv files by following this tutorial.

What next?

Other examples

If you want to Learn more about working with ROS (e.g. make arduino node start on Leo Rover startup) check this tutorial.

You can also find other ideas and tutorials here:

Now, everything should work, if not, contact us at contact@fictionlab.pl. We’ll be happy to answer your questions and help you.
Contents

Need help? Contact us - contact@fictionlab.pl