Blog

How to learn robotics with Raspberry Pi (2/2)

Learn robotics
Share
Comment apprendre la robotique avec Raspberry Pi (2/2)

In the previous post, we gave you an overview of how to learn robotics with Raspberry Pi, so you can know what is Raspberry Pi, and which board to choose.

In this post, we’ll show you what you need to do to actually learn robotics with Raspberry Pi.

Ready ? Let’s go :

Installing an operating system on Raspberry Pi :

In this part we will focus on Raspberry Pi 3 board, but most of these advices are also valid for Raspberry Pi 2.

First of all, you need a microSD card. Even if you can install almost any OS with just a 8GB card, we recommend using a 16GB or 32GB one. Also, check that your microSD card has a class 6 or 10 (10 is best).

Installing an operating system image on an SD card is pretty straight forward. The Raspberry Pi official website provides great tutorial about this topic. You can also directly buy an SD card with a pre-installed image, but we recommend that you do that by yourself while following the tutorial, as it is easy and you will learn some basics.

Now, which OS (operating system) to install ? Raspbian is an OS specially created for Raspberry Pi products. It is better to start with that, as you are sure that most features will be supported, and the hardware will work nicely out of the box. You can download Raspbian on the Raspberry Pi official website. If you are using Raspberry Pi for the first time, and don’t know much about computer science, then there is an OS for you, which is called Noobs (New Out Of the Box Software).

If you like Ubuntu (like us), you will be happy to know that many Ubuntu version have been adapted to run on Raspberry Pi : Ubuntu Mate, Xubuntu, Lubuntu, Ubuntu server. Check out download links here.

For more advanced user, you can also find lightweight OS versions, with no graphical interface. Those will allow you to speed up your applications by a significant amount.

Programming on Raspberry Pi

Raspberry Pi is a great platform to learn robotics, and at some point you will need to do some programming tasks to control your robot – controlling motors, read data from sensors, or creating a server program to control your robot from a web interface.

The good news is that Raspbian and most of the operating systems already come with a Python development environment. Python is a good language to start programming and is often adopted by beginners. More than a language for learning, Python is widely used in real applications, and allows fast prototyping and development.

You will also find a lot of open source Python libraries to help you interact with the pins and ports of your Raspberry Pi board. That way, you can create useful stuff for your robot without too much struggle.

Of course, you can use any language you want (C, C++, Ruby, Javascript, …), depending on the application you are building. For robotics projects, Python and C++ are mostly used. Combined together, they allow fast development, and optimized code for better performance.


Use GPIO pins


After you installed an OS and get to know about basic programming, you will be able to start using the GPIO pins of the Raspberry Pi board. Those allow you to connect your board to hardware components, through i2c and spi protocols for example.

Some libraries were developed to allow you to easily use those communication protocols without knowing how they’re working under the hood. For example, SMBus is a Python library which makes I2C communication very easy.


From the 40 pins of the Raspberry Pi (2 and 3) you will be able to :

  • Control the inclination of your robot with an IMU sensor (Inertial Measurement Unit)
  • Control the position of your robot with a laser detector
  • Get environment info such as temperature, pressure, …
  • Communicate with another computer board or a microcontroller board (ex: Arduino)

Embed a camera


Raspberry Pi has a camera interface
, and you can buy a camera specially made for Raspberry Pi, which is low cost, easy to connect, and which provides good image quality.

Imagine all the possibilities ! You could build your own drone, and use the camera to process images from the environment, so your drone can know where to land, and how to avoid obstacles.

If you are willing to use a camera on your Raspberry Pi board, have a look at OpenCv library. You can use this open source library to process images from your camera, for recognizing parts of the environment, faces, etc.

 


Communicate with an Arduino board

What’s great with Raspberry Pi, is that you can connect it to almost anything. Imagine a Raspberry Pi + Arduino combination… Well, that’s possible, and it’s a very good idea for robotics applications.

But when do you need an Arduino board with your Raspberry Pi board ?

  • Sometimes you have some real-time constraints, and the OS on your Raspberry Pi can’t handle them quite well. In this case you may want to use an Arduino board to perform the real-time stuff, and connect each other so the Raspberry can still perform high computation and let the Arduino do the lower level jobs.
  • If you need to control a lot of motors, let’s say, 5 stepper motors, you will need to add a board to your Raspberry Pi, to handle power supply and motor control (sometimes with real-time constraints). An Arduino Mega with RAMPS 1.4 shield can do that perfectly !
  • If you want to control multiple pieces of hardware in your home with only one command center, then you can connect multiples Arduino boards with one Raspberry Pi board.

Connect your robot to your home

With Ethernet connection, you can directly plug your Raspberry Pi to your home router, and here you go ! You just have a 40$ server just for you.

Using Wi-Fi and Bluetooth connection, you will be able to have your Raspberry Pi embedded in your robot and still communicating with the outside. That way, you can imagine creating a server on your robot, so you can control it from a mobile application, or from a remote position at the other side of the world.

Let’s take back the example of the drone. While processing images with OpenCV, you could also stream the video to your computer, so you are able to see what the robot sees.

Real use case : Niryo One

After all those points, you might want to get an example of a real robotics project using a Raspberry Pi board.

At Niryo, we use a Raspberry Pi 3 board to control our robot, Niryo One. We made this choice because we wanted the robot to be more clever. We also wanted to embed Ubuntu operating system so we can run Robot Operating System (ROS), a great set of tools for powerful robotics applications.

Your turn !

We gave you here an introduction on how to learn robotics with Raspberry Pi. With all these points you will be able to see what you can do, and how to find the right information to make progress at the beginning.

We strongly encourage you to take part in the community around Raspberry Pi, such as the official forums, or other websites providing great tutorials. After you build your robot you can share your work with the community, and get feedback and positive comments, everything you need to keep motivating yourself.

Now, it’s your turn to learn robotics with Raspberry Pi !