Arduino/AVR tutorial

Ready to build your first robot under 3h?

Download as .zip Download as .tar.gz View on GitHub

Tutorial overview

Introduction

Have you ever dreamed of making your own electronic device? Do you think it’s a difficult task and requires at least a PhD in electronics? Well, we no longer live in Stone Age and there is no need to chisel transistors out of a silicon wafer. There are way better solutions on the market nowadays.

This tutorial presents an affordable way to your very first robotics. For ~€20-25 you can build your own robot that actually can fight!

Robot - picture
Figure: Completed robot, photo

[!IMPORTANT] This tutorial assumes you have basic familiarity with one of C-like languages: C, C++, Java, JavaScript, Python.

This tutorial shall follow DRY principle: Don’t Repeat Yourself. If there’s a good resource, I’ll simply point you there.

Table of contents

Your best friend during the course - Atmega328P Datasheet!

Bill of materials

To complete the tutorial, you’ll need:

[!NOTE] If you just want to learn basics you can complete the introductory chapters with only one stepper motor. You also don’t need to 3d-print anything in that case!

Bill of Materials: 3D printed elements

To complete the tutorial and build a robot, you’ll need:

Additionally:

All STL files can be downloaded from this tutorial repository: 3d_models.

The robot has been design to require no screws, bolts, anything. It’s ugly but functional :). Printing instruction:

Once you print all the parts, you’ll have a robot that resembles the render photos below:

Front render
Figure: Front render

Rear render
Figure: Rear render

Integrated development environment

You need to install an integrated development environment to start developing your programs ASAP. It’s the easiest and fastest way (of course you can use a standalone AVR Toolchain1 and AVRDude 2… it’s your choice but make sure you have plenty of time and tenacity).

Since it’s a quick way to get you started I suggest you install both, yes both, environments:

Why two IDEs? Well, Arduino IDE is so simple that it’s a very nice place to start. Lots of pre-installed examples that you can simply run. All toolchains install automatically (AVR, ARM, etc.). It provides an easy to use terminal to see UART data (refer to UART). However, anything bigger than one file tends to be more and more difficult to maintain.

VSCode is an advanced text editor that can work quite nicely as an IDE if you configure it properly. PlatformIO provides support for most of development boards available on the market. It also handles external dependencies quite well, so you don’t need to download 3rd party libraries on your own. It all comes with a greater complexity and is slightly more difficult to use. Just slightly.

Now, sometimes it’s easier to compile software in Arduino IDE than in VSCode. You download a lib, compile, and run. VSCode can sometimes be a pain in this aspect. So Arduino IDE is also a good tool for any quick debugging you may need.

TL;DR; Skip tutorial, give me a robot

If you are impatient and want the robot now without following the tutorial, here are all the steps you need to create your robot.

PINOUT

Device Arduino Pin
Servo PWM line D9
Right Stepper IN1 D7
Right Stepper IN2 D6
Right Stepper IN3 D5
Right Stepper IN4 D4
Left Stepper IN1 PIN_A4
Left Stepper IN2 PIN_A3
Left Stepper IN3 PIN_A2
Left Stepper IN4 PIN_A1

Disclaimer

All presented materials serve educational purposes only. Working with electricity poses hazard to your health and life. If you decide to follow the tutorial, you do it at your own risk. You can get destroy your electronic components (i.e., ESD - electrostatic discharge), get electrocuted, burn down your surroundings. You have been warned!

Similarly, 3D printing comes with it’s own risks. My first cheap 3D printer caught fire twice… You need some basic skills to operate FDM/FFF printer. Please refer to your printer user manual. Remember, you do it at your risk!

References