Tested on:Raspberry Pi 3; Raspbian Jessie; Python 2; Raspirobotboard v3
Prerequisites:Robot Chassis with motors
Raspberry Pi with Raspbian Jessie and internet connection (see steps 1-7 in the Introduction)
Hardware:Batteries and fitting holder
Raspirobotboard v3
Ultrasonic Sensor HC-SR04
Breadboard, pushbutton and 2* male-to-female jumper cables (or soldering equipment)
0

Build a basic Raspberry Pi Robot in no time with the RaspiRobotBoard v3 HAT

Raspberry Pi Robot

Raspberry Pi Robot


Building a robot has never been more easy than with the Raspberry Pi and the RaspiRobotBoard v3 from Simon Monk. Learn in this tutorial how to build a robot that rovers around and avoids collisions with obstacles, with just a few lines of code.
The RobotBoard itself is available for 27€ on Amazon; all in all, the robot presented herein costs around 90€.
Have a look at the RaspiRobotBoard documentation on GitHub for an detailed overview of its capabilities.

Batteries
I’m using two 9 Volt blocks with my robot chassis because i had them here and the holders were a snug fit. It need to be two 9V blocks connected in parallel, because the maximum discharge current of a single 9V block is just 800mA, which is way to little for a Raspberry Pi with motors.

Robot Batteries

The GND and V+ of the right battery are connected to the GND and V+ of the left batterie in parallel

The resulting 1.6A maximum discharge is still rather low, but sufficient for this simple robot. A rechargeable LiPo battery with a higher discharge current would be a better choice!

Assembly
Follow the installation instructions which came with your robot chassis. Attach the RoboBoard to the GPIO, then plug the ultrasonic sensor into the female pin header labeled HC-SR04. Put the cables of the left motor into the RaspiRobotBoard screw terminal marked with an l and the right motor cables into the one with the r. If the wheels of the robot are turning into the wrong direction later on, switch the polarity of the motor cables.
Now, attach a pushbutton to the RaspiRoboBoard pins labeled SW1 like this:

RaspiRobotBoard - Button

RaspiRobotBoard – Button

Finally, connect the battery holder plus and minus pole to the board screw terminals V+ and GND.

Installation
The installation is very simple: you only need to install the RaspiRobotBoard drivers from Simon Monks GitHub account and download the minimum robot script. Do this by entering

Autostart the Robot
For starting the minimum robot automatically afer booting the RPi, open rc.local with

and enter the line

before

Save and exit, then reboot. After booting, start the robot by pressing the pushbutton. Pressing the pushbutton again will shutdown the Raspberry Pi.

Demo

Everytime the ultrasonic sensor detects an obstacle, the robot reverts for a second and then turns randomly.

Code explained
Luckily, the library coming with the RaspiRobotBoard does most of the work. First, a robotboard object is created with

This says that the RobotBoard expects an input voltage of 9V and drives the motors with 6V.

In the robots life cycle (an endless loop), it is checked if the distance to an obstacle is below 10 centimeters with the RaspiRobotBoard library function get_distance. If not, the robot goes forward. Else, avoid_collision is called which makes the robot go backward for a second, then turn for up to a second either left or right.

The complete script
Click on Full Script to show all of the code.

Conclusion
The RaspiRobotBoard v3 delivers! It’s neat, the price is ok and the software library coming with the board is very comfy. Only thing i did miss is a 40 pin header which covers the complete GPIO of the newer Raspis and screw holes fitting for the RPi3.

Links
Simon Monk website: http://simonmonk.org/
RaspiRobotBoard on GitHub: https://github.com/simonmonk/raspirobotboard3

Knight of Pi

Johannes Bergs aka Knight of Pi. Diploma in Bioinformatics, some Webdesign and Python coding then. Living in the beautiful city of Vienna.

Comment

Time limit is exhausted. Please reload CAPTCHA.