Programming the arduino

From Claremont MakerSpace
Revision as of 03:49, 9 May 2019 by Tiffany.vincent (talk | contribs)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)

Here are the basics...

The microcontroller board used in the 2020 Bot is compatible with the Arduino family of microcontroller products based on the Atmel ATmega328. Specifically, we're using an Arduino Nano. Using an Arduino compatible board lets us take advantage of all the software and libraries written for these devices. You will need software running on your personal computer (Mac, Windows, or Linux) that allows you to write (or at least download) software for the Arduino Nano on the 2020 Bot.

Plenty of resources exist that help you get started with Arduino:

and many more (Google is your friend!)


The typical steps to follow are:

  1. Download and install the Arduino IDE from Arduino.cc
  2. You may need drivers to communicate with the Arduino Nano. Windows 10 folks are all set, but Mac users need this driver (https://github.com/adrianmihalko/ch340g-ch34g-ch34x-mac-os-x-driver).
  3. Download the .ZIP file for the Timer One Library from GitHub (https://github.com/PaulStoffregen/TimerOne)
  4. Download the .ZIP file for the 2020 Bot Library and Demo Code from GitHub (https://github.com/robojay/_2020Bot_Library)
  5. Start the Arduino IDE.
  6. Select Sketch->Include Library->Add .ZIP Library...
  7. Select the .ZIP file you downloaded for the Timer One Library
  8. Repeat for the .ZIP file you downloaded for the 2020 Bot Library
  9. Plug the 2020 Bot Arduino Nano into your computer via the USB cable
  10. Tell the Arduino software you are using a Nano by selecting Tools->Board->Arduino Nano
  11. Select your Arduino Nano's port under Tools->Port
  12. Load the Demo code by selecting File->Examples->_2020Bot_Library->_2020Bot_Demo
  13. Send it to the 2020 Bot by selecting Sketch->Upload

Although the Demo software shows off the 2020 Bot features, it is difficult for beginners to understand. I will be adding simpler examples to the 2020 Bot Library over time.

Running the Demo Code

The 2020 Bot Demo lets the robot be either remote controlled or operate in autonomous mode.

When you power on the robot, it starts in remote control mode. Pressing the arrow keys on the IR remote will drive the robot in the different directions. Pressing the "OK" button in the middle of the arrow keys will stop the robot. Don't hold the buttons down, just press and release. Each time forward or reverse is pressed, the robot will drive in that direction for a short time. While it's diving, you can always press another button (like OK to stop). The left and right buttons will have the robot pivot the robot in place just a little.

To start autonomous mode, press the # key on the remote. The robot will start wandering around, using it's IR LED and IR Receiver to detect obstacles. It's a simple sensor and won't always detect things. When the robot needs your help, press the * key to go back to remote control mode.