Hello World

One of the first programs that I like to write when starting to work on a new platform is a program that will simply prints out the text ‘Hello World’. This allows me to figure out exactly how to build and run programs. With that in mind, let’s get started!

As a starting point we will load the example ‘SimpleRobotBlank’ example. To load example code in the Arduino IDE, simply click on the ‘File’ menu, open the ‘Examples’ menu, and then choose the ‘SimpleRobotBlank’ option from the ‘SimpleRobot’ sub-menu.

LoadExample

Once loaded, you should see the following:

#include <Servo.h>
#include  <MsTimer2.h>

#include <SimpleRobot.h>

class MyRobot : public Robot
{
public:
    /*
     * Setup is called once when you run your program.
     *  All of your initilization code should be place here
     */
    void Setup()
    {
    }
    
    /*
     * After 'Setup' is called, 'Loop' will be called repeatedly
     *  until the program is stopped.
     */
    void Loop()
    {
    }
    
    /*
     * Terminate is called when the program is stopped.
     *  You should do any cleanup neccesary here.
     */
    void Terminate()
    {
    }
} MyRobot;

Robot    *    g_pRobot    = &MyRobot;

The first thing you will notice is that this program differs a bit from a normal Arduino sketch. First of all the Setup and Loop functions are moved into a C++ class (named MyRobot in this example), and that class is based on the Robot class which is defined in the include file SimpleRobot.h.

The Robot class performs a number of valuable functions that we will need to use during the course of our programming.  We won’t discuss the details of how the Robot class works here, but if you are interested, there will be another tutorial which will walk you through its creation.

The important thing you need to know is that the underlying Robot class will not let your program run until you tell it.  Ordinarily, an Arduino program will start executing the moment the download is complete.  This is an undesirable feature in our case since we would like to be able to set the robot up before we let it start.  To start the robot, we will start up a Driver Station program which will allow us to start and stop the robot remotely.

All we want to do with this program is to print out ‘Hello World’ when the program starts.  The perfect place to do this is in the Setup function which will be called once when you command the program to run from the Driver Station.  Do do this we will use the Arduino Serial.println function.  Add the following line to the setup function:

Serial.println("Hello World!");

Once done, your final program should look like:

#include <Servo.h>
#include  <MsTimer2.h>

#include <SimpleRobot.h>

class MyRobot : public Robot
{
public:
    /*
     * Setup is called once when you run your program.
     *  All of your initialization code should be place here
     */
    void Setup()
    {
      Serial.println("Hello World!");
    }
    
    /*
     * After 'Setup' is called, 'Loop' will be called repeatedly
     *  until the program is stopped.
     */
    void Loop()
    {
    }
    
    /*
     * Terminate is called when the program is stopped.
     *  You should do any cleanup neccesary here.
     */
    void Terminate()
    {
    }
} MyRobot;

Robot    *    g_pRobot    = &MyRobot;

Now upload your program to the robot. The first thing you will notice is that nothing happens. Remember, your program will not start until you tell it to via the Driver Station.  In the next section, we will show you how to use the Driver Station to control your robot.

Next: Running Your Program