Note: this page refers to a product that is retired.

Robot Library

The library allows you to interface with the various sensors and peripherals on the control board.

This library is archived and is no longer being maintained. It can be still be downloaded and used, but is read-only and cannot be contributed to. Furthermore, the Robot Library now exists as three separate libraries: Robot_Control, Robot_Motor and RobotIRremote.

The Robot library is included with Arduino IDE 1.0.5 and later.

The Robot has a number of built in sensors and actuators. The library is designed to easily access the robot's functionality.

The robot has two boards, a motor board and control board. Each board has a separate programmable processor.

The library allows you to interface with the various sensors and peripherals on the control board :

  • potentiometer
  • 5 momentary switches
  • 160x120 pixel color screen
  • 512Kbit EEPROM
  • speaker
  • compass
  • 3 I2C connectors
  • 8 TinkerKit input connectors

The library also enables you to do a number of things with the motor board :

  • control motor speed and direction
  • sense the current used by each motor
  • read the state of the 5 floor sensors (also known as line detection sensors)
  • access I/O pins on the board
  • control an I2C port
  • read the state of 4 TinkerKit inputs

For more information about the Robot, visit the getting started guide and the hardware page.

Library structure

This library enables easy access to the functionality of the Arduino Robot. It relies on a number of 3rd party libraries including Fat16, EasyTransfer, Squawk, and IRRemote. It also relies on a number of Arduino libraries like TFT, SPI, and Wire. Their functionality has been replicated inside the robot's library to optimize the code's size.

It is possible to program both the Control and the Motor boards. However, it is recommended that novice programmers begin with programming the control board, leaving the motor board for later. The library exposes the sensors on both boards through a single object.

There are two main classes that command the robot:

  • RobotControl: commands the Control Board as well as the I/Os and motors on the Motor Board, when running the default firmware.
  • RobotMotor: commands the Motor Board. Use it to make your own custom version of the Motor Board firmware

Examples

You can find examples for this library in the Examples from Libraries page.

RobotControl Class


RobotControl

Description

The constructor is empty. As the methods can be accessed through the Robot object directly, you don't need to call the constructor.

Parameters

none

Returns

none

Examples

1#include <ArduinoRobot.h>
2void setup(){
3 //methods can be accessed directly through Robot
4 Robot.begin();
5 Robot.motorsWrite(255,255);
6}
7void loop(){
8}

begin()

Description

Initializes the robot. Must be called in setup() to use Robot-specific features.

Robot.begin() does not initialize features like sound, the LCD module, or the SD card. Refer to the links in the "See also" section for reference on initializing these other modules.

Syntax

1Robot.begin()

Parameters

none

Returns

none

Examples

1#include <ArduinoRobot.h>
2void setup(){
3 Robot.begin();
4 //do stuff here
5}
6void loop(){
7 //do stuff here
8}

setMode()

Description

Change the robot's mode. Depending on the mode it is currently in, the commands may change.

Syntax

1Robot.setMode(modeName)

Parameters

  • modeName: Name of the mode you want to set the robot into.
  • MODE_SIMPLE : the robot will accept all commands.
  • MODE_LINE_FOLLOW : the robot will start line-following, and stop responding to motor commands

Returns

none

Examples

1#include <ArduinoRobot.h>
2void setup(){
3 Robot.begin();
4 Robot.setMode(MODE_LINE_FOLLOW);
5}
6void loop(){
7
8}

pauseMode()

Description

Pause or resume the mode-specific action for the bottom board.

For line-following mode, the robot will stop following the line, but still receiving commands.

Syntax

1Robot.pauseMode(onOff)

Parameters

onOff: boolean. true pauses the mode, false resumes it.

Returns

none

Examples

1#include <ArduinoRobot.h>
2long timer;
3
4void setup(){
5 Robot.begin();
6 Robot.beginLCD();
7 delay(3000);
8
9 Robot.setMode(MODE_LINE_FOLLOW);
10 timer=millis();
11 while(!Robot.isActionDone()){
12 //pauses line-following for 3 seconds every 5 seconds
13 if(millis()-timer>=5000){
14 Robot.pauseMode(true);
15 delay(3000);
16 Robot.pauseMode(false);
17 timer=millis();
18 }
19 Robot.debugPrint(millis());
20 }
21 Robot.text("Done!",0,10,true);
22 while(true);
23
24}
25void loop(){
26}

isActionDone()

Description

Checks if the current motor board mode action is finished.

Line-following mode will report an action completed signal when it reaches a finishing line (a perpendicular line).

Syntax

1Robot.isActionDone()

Parameters

none

Returns

boolean

Examples

1#include <ArduinoRobot.h>
2long timer;
3
4void setup(){
5 Robot.begin();
6 Robot.beginLCD();
7 delay(3000);
8
9 Robot.setMode(MODE_LINE_FOLLOW);
10 timer=millis();
11 while(!Robot.isActionDone()){
12 //pauses line-following for 3 seconds every 5 seconds
13 if(millis()-timer>=5000){
14 Robot.pauseMode(true);
15 delay(3000);
16 Robot.pauseMode(false);
17 timer=millis();
18 }
19 Robot.debugPrint(millis());
20 }
21 Robot.text("Done!",0,10,true);
22 while(true);
23
24}
25void loop(){
26}

lineFollowConfig()

Description

Change the parameters for line following.

Use this function if line-following is not working as expected, or you want to change the robot's speed while line-following.

This function changes the "PD algorithms" that enable to robot to think about what may happen next while line reading. The robot attempts to predict any possible errors on the next reading of the IR sensors, and corrects its movement accordingly by changing the speed of each wheel separately.

See the note below for a deeper explanation.

Syntax

1Robot.lineFollowConfig(KP,KD,robotSpeed,intergrationTime)

Parameters

  • KP : int, proportional gain
  • KD : int, derivative gain
  • integrationTime: int, delay time between each time we run the algorithm in ms
  • robotSpeed: int, between 0 and 100, indicating the percentage speed of motors.

Returns

none

Examples

1#include <ArduinoRobot.h>
2long timer;
3
4void setup(){
5 Robot.begin();
6 Robot.beginLCD();
7 delay(3000);
8
9 Robot.lineFollowConfig(11,5,50,10);//set PID
10 Robot.setMode(MODE_LINE_FOLLOW);
11 timer=millis();
12 while(!Robot.isActionDone()){
13 //pauses line-following for 3 seconds every 5 seconds
14 if(millis()-timer>=5000){
15 Robot.pauseMode(true);
16 delay(3000);
17 Robot.pauseMode(false);
18 timer=millis();
19 }
20 Robot.debugPrint(millis());
21 }
22 Robot.text("Done!",0,10,true);
23 while(true);
24
25}
26void loop(){
27}

digitalRead()

Description

Reads the digital value one the defined port. These are exposed as TinkerKit connectors on the robot. See the diagrams below for pin locations

Syntax

1Robot.digitalRead(portName)

Parameters

port: Valid names are TK0 to TK7 (found on the Control board), TKD0 to TKD5 (on the Control board), and B_TK1 to B_TK4 (on the Motor Board).

Returns

HIGH or LOW

Examples

1#include <ArduinoRobot.h>
2void setup(){
3 Robot.begin();
4 Serial.begin(9600);
5
6}
7void loop(){
8 Serial.println(Robot.digitalRead(TK0)); //Print the value read on port TK0
9 delay(100);
10}

digitalWrite()

Description

Write a HIGH or a LOW value to the defined port on the robot. the ports are exposed on the robot as TinkerKit connectors.

Syntax

1Robot.digitalWrite(port, value)

Parameters

port: TKD0 to TKD5 (on the Control board), B_TK1 to B_TK4(on the Motor Board), or LED1 (located on the control board)

value: HIGH or LOW

Returns

none

Examples

1#include <ArduinoRobot.h>
2void setup(){
3 Robot.begin();
4}
5
6void loop(){
7 Robot.digitalWrite(TDK0, HIGH); // Turn on a Tinkerkit LED connected to TDK0
8 delay(1000);
9 Robot.digitalWrite(TK0, LOW); // Turn the LED off
10 delay(1000);
11}

Note

You cannot call Robot.digitalWrite() on TK0 to TK7


analogRead()

Description

Reads the value from the specified port on the robot. The ports are exposed on the robot as TinkerKit connectors.

The board has a 10-bit analog to digital converter. This means that it will map input voltages between 0 and 5 volts into integer values between 0 and 1023.

Syntax

1Robot.analogRead(port)

Parameters

port: TK0 to TK7 (found on the Control Board), TKD0 to TKD5 (found on the Control Board), or B_TK1 to B_TK4 (found on the motor Board)

Returns

int : 0 to 1023

Note

If the input port is not connected to anything, the value returned by Robot.analogRead() will fluctuate based on a number of factors (e.g. the values of the other analog inputs, how close your hand is to the board, etc.).

Examples

1#include <ArduinoRobot.h>
2
3void setup(){
4 Robot.begin();
5 Serial.begin(9600);
6}
7
8void loop(){
9 Serial.println(Robot.analogRead(TK0)); //Print the value on port TK0
10 delay(100);
11}

analogWrite()

Description

Writes an analog value as PWM to the specified port on the robot. The board has a 8-bit PWM, allowing for 256 discrete levels.

Robot.analogWrite() only works on TKD4, located on the Control Board. It cannot be used at the same time as TK0 through TK7.

Syntax

1Robot.analogWrite(port, value)

Parameters

port: TKD4

value : 0 to 255

Returns

none

Examples

1#include <ArduinoRobot.h>
2
3void setup(){
4 Robot.begin();
5 Serial.begin(9600);
6}
7
8void loop(){
9 for(int x=0;x<256;x++){
10 Robot.analogWrite(TKD4, x); //increase brightness of an LED on TK0
11 delay(20);
12 }
13}

updateIR()

Description

Reads the values of the 5 IR line-reading sensors on the underside of the robot and stores the values in an array. This array can be accessed through Robot.IRarray[]. This function needs to be called from the Control Board.

To obtain the reading from a specific IR sensor, use IRRead() on the Motor Board.

Parameters

none

Returns

Robot.IRarray[] : contains the values of the 5 sensors

Examples

1#include <ArduinoRobot.h>
2
3void setup(){
4 Robot.begin();
5 Serial.begin(9600);
6}
7
8void loop(){
9 Robot.updateIR(); // update the IR array
10 for(int i=0;i<=4;i++){
11 Serial.print(Robot.IRarray[i]); // print the values to the serial port
12 Serial.print(",");
13 }
14 Serial.println("");
15 delay(100);
16}

knobRead()

Description

Gets the analog value as a 10-bit value from the on-board potentiometer. This means that it will map input voltages between 0 and 5 volts into integer values between 0 and 1023.

Syntax

1Robot.knobRead()

Parameters

none

Returns

int: 0 to 1023

Examples

1#include <ArduinoRobot.h>
2
3void setup(){
4 Robot.begin();
5 Serial.begin(9600);
6
7}
8void loop(){
9 Serial.println(Robot.knobRead());
10 delay(100);
11}

compassRead()

Description

Get the current direction from on-board compass. The values are degrees of rotation from north (in a clockwise direction), so that east is 90, south is 180, and west is 270.

Syntax

1Robot.compassRead()

Parameters

none

Returns

int: 0 to 359, representing the number of degrees of rotation from north.

Note

The compass module may be disrupted by magnetic fields in surrounding areas.

Examples

1#include <ArduinoRobot.h>
2
3void setup(){
4 Robot.begin();
5 Serial.begin(9600);
6
7}
8void loop(){
9 Serial.println(Robot.compassRead());
10 delay(100);
11}

keyboardRead()

Description

Detects if one of the 5 momentary buttons on the control board is pressed.

Syntax

1Robot.keyboardRead()

Parameters

none

Returns

  • BUTTON_NONE if no key is pressed
  • BUTTON_LEFT if left key is pressed
  • BUTTON_DOWN if down key is pressed
  • BUTTON_UP if up key is pressed
  • BUTTON_RIGHT if right key is pressed
  • BUTTON_MIDDLE if middle key is pressed

Examples

1#include <ArduinoRobot.h>
2
3void setup(){
4 Robot.begin();
5 Serial.begin(9600);
6}
7
8void loop(){
9 Serial.println(Robot.keyboardRead());
10 delay(100);
11}

waitContinue()

Description

Pauses the current program and waits for a key press from one of the 5 momentary buttons. Once you press the key, the program continues.

Syntax

1Robot.waitContinue()
2Robot.waitContinue(key)

Parameters

key: the momentary switch to listen for. The default value is BUTTON_MIDDLE. Valid choices are

  • BUTTON_LEFT
  • BUTTON_RIGHT
  • BUTTON_MIDDLE
  • BUTTON_UP
  • BUTTON_DOWN

Returns

none

Examples

1#include <ArduinoRobot.h>
2
3void setup(){
4 Robot.begin();
5 Robot.waitContinue();//stop the robot, and wait for the middle button to be pressed
6}
7
8void loop(){
9 Robot.motorsWrite(255,255);
10 delay(2000);
11 Robot.motorsWrite(0,0);
12 delay(2000);
13}

motorsWrite()

Description

Controls the speed and direction of the two motors connected to the robot's wheels. motorsWrite() needs values between -255 and 255. If the value is greater than 0, the wheel turns forward. If less than 0, the motor turns backwards.

Syntax

1Robot.motorsWrite(speedLeft, speedRight)

Parameters

  • speedLeft: the speed of left wheel
  • speedRight: the speed of right wheel

Returns

none

Examples

1#include <ArduinoRobot.h>
2
3void setup(){
4 Robot.begin();
5}
6void loop(){
7 Robot.motorsWrite(255,255); //Make the robot go forward, full speed
8 delay(1000);
9 Robot.motorsWrite(0,0); //Make the robot stop
10 delay(1000);
11 Robot.motorsWrite(255,-255);//Make the robot rotate right, full speed
12 delay(1000);
13 Robot.motorsWrite(0,0); //Make the robot stop
14 delay(1000);
15}

motorsStop()

Description

Stop both motors of the robot.

Syntax

1Robot.motorsStop()

Parameters

none

Returns

none

Examples

1#include <ArduinoRobot.h>
2
3void setup(){
4 Robot.begin();
5}
6void loop(){
7 Robot.motorsWrite(255,255); //Make the robot go forward, full speed
8 delay(1000);
9 Robot.motorsStop(); //Fast stop the robot
10 delay(1000);
11 Robot.motorsWrite(255,-255);//Make the robot rotate right, full speed
12 delay(1000);
13 Robot.motorsWrite(0,0); //Slow stop the robot
14 delay(1000);
15}

Note

You can as well stop the motors by calling Robot.motorsWrite(0,0). Difference is, after the later is called, the motors may still move a little due to momentum(so called slow stop). Robot.motorsStop() will stop the motors and make them stiff, so stop instantly.


turn()

Description

Make the robot turn a certain number of degrees from its current orientation. The current position is derived from the onboard compass.

Syntax

1Robot.turn(degrees)

Parameters

degrees:-180 to 180. Positive number for turning right, negative number for turning left.

Returns

none

Note

Magnetic objects in the surrounding may disrupt the compass module. Keep magnets, such as strong speakers, away from the robot.

Examples

1#include <ArduinoRobot.h>
2
3void setup(){
4 Robot.begin();
5}
6void loop(){
7 Robot.turn(90); //Make the robot turn 90 degrees right
8 delay(1000);
9}

pointTo()

Description

Make the robot point in a particular direction. pointTo() makes the robot face an absolute direction based on the compass.

Syntax

1Robot.pointTo(degrees)

Parameters

degrees:0 to 359.

Returns

none

Note

Magnetic objects in the surrounding may disrupt the compass module. Keep magnets, such as strong speakers, away from the robot.

Examples

1#include <ArduinoRobot.h>
2
3void setup(){
4 Robot.begin();
5 Robot.pointTo(90); //The robot will turn to 90, by the value of compass
6}
7void loop(){
8}

beginSpeaker()

Description

Initializes the speaker and sound libraries. Must be included in setup().

Syntax

1Robot.beginSpeaker()

Parameters

none

Returns

none

Examples

1#include <ArduinoRobot.h>
2
3void setup(){
4 Robot.begin();
5 Robot.beginSpeaker();//Initialize the sound module
6}
7
8void loop(){
9 char aTinyMelody[] = "8eF-FFga4b.a.g.F.8beee-d2e.1-";// This is what we will play
10 Robot.playMelody(aTinyMelody);// Play the melody
11
12}

playMelody()

Description

Plays a melody according to a string of music notes. The input string also contains information about note duration, as well as silences. Must be preceded by Robot.beginSpeaker() in setup().

NB : when a melody is playing, all other processes stop

Syntax

1Robot.playMelody(melody)

Parameters

melody: A string of notes to be played and their duration.

The string may contain following chars: Notes

  • c
    : play "C"
  • C
    : play "#C"
  • d
    : play "D"
  • D
    : play "#D"
  • e
    : play "E"
  • f
    : play "F"
  • F
    : play "#F"
  • g
    : play "G"
  • G
    : play "#G"
  • a
    : play "A"
  • A
    : play "#A"
  • b
    : play "B"
  • -
    : silence

Duration

  • 1
    : Set the following as full notes
  • 2
    : Set the following as half notes
  • 4
    : Set the following as quarter notes
  • 8
    : Set the following as eight notes
  • .
    : Set the note duration as its duration plus an half of its duration (Example 1/4 + 1/8)

Returns

none

Examples

1#include <ArduinoRobot.h>
2
3void setup(){
4 Robot.begin();
5 Robot.beginSpeaker();//Initialize the sound module
6}
7
8void loop(){
9 char aTinyMelody[] = "8eF-FFga4b.a.g.F.8beee-d2e.1-";// This is what we will play
10 Robot.playMelody(aTinyMelody);// Play the melody
11
12}

beep()

Description

Make a short beeping sound. Must be preceded by Robot.beginSpeaker() in setup().

NB : when a beep is playing, all other processes stop

Syntax

1Robot.beep(beep_length)

Parameters

beep_length: Any of the const below indicating type of beep sound.

  • BEEP_SIMPLE: a short beep
  • BEEP_DOUBLE: double beep
  • BEEP_LONG: a longer beep

Returns

none

Examples

1#include <ArduinoRobot.h>
2
3void setup(){
4 Robot.begin();
5 Robot.beginSpeaker();//Initialize the sound module
6}
7
8void loop(){
9 Robot.beep(BEEP_SIMPLE);//Make a single beep sound
10 delay(1000);
11}

playFile()

Description

Play a .sqm music file stored on a SD card. Robot.beginSpeaker() and Robot.beginSD() are both required in setup().

Unlike Robot.playMelody() and Robot.playBeep(), playFile() does not halt other processes while playing. However, you cannot load new images on the LCD screen when playFile() is in use.

Valid files for playback are generated/converted by the sound library Squawk. See the library README for details on how to create your own music.

Syntax

1Robot.playFile(filename)

Parameters

filename: file name of the music to be played

Returns

none

Examples

1#include <ArduinoRobot.h>
2
3void setup(){
4 Robot.begin();
5 Robot.beginSpeaker();//Initialize the sound module
6 Robot.beginSD();//Initialize the sd card
7 Robot.playFile("melody.sqm");//Play the original music come with the robot.
8}
9
10void loop(){
11 //do other stuff here
12}

tuneWrite()

Description

When playing a music file through playFile(), this will change the pitch of the sound. The larger the value, the higher the pitch.

Syntax

1Robot.tuneWrite(pitch)

Parameters

pitch: float, indicating the pitch of the sound currently playing. 1.0 is the baseline value.

Returns

none

Examples

1#include <ArduinoRobot.h>
2
3void setup(){
4 Robot.begin();
5 Robot.beginSpeaker();//Initialize the sound module
6 Robot.beginSD();//Initialize the sd card
7 Robot.playFile("melody.sqm");//Play the original music come with the robot.
8 Robot.tuneWrite(1.4);//40% higher than default
9}
10
11void loop(){
12
13}

tempoWrite()

Description

When playing a music file with playFile(), this will change the tempo, or speed of the playback. The larger the value, the quicker the sound will play back. Smaller values will slow the playback.

Syntax

1Robot.tempoWrite(speed)

Parameters

speed: int, the tempo. Default is 50.

Returns

none

Examples

1#include <ArduinoRobot.h>
2
3void setup(){
4 Robot.begin();
5 Robot.beginSpeaker();//Initialize the sound module
6 Robot.beginSD();//Initialize the sd card
7 Robot.playFile("melody.sqm");//Play the original music come with the robot.
8 Robot.tempoWrite(70);//20 higher than default
9}
10
11void loop(){
12
13}

beginTFT()

Description

Initialize the TFT module. All general TFT functions are dependent on this.

Syntax

1Robot.beginTFT()
2Robot.beginTFT(foreGround, backGround)

Parameters

foreGround: set a universal foreground color. Default is black. backGround: set a universal background color. Default is white.

Returns

none

Examples

1#include <ArduinoRobot.h>
2
3void setup(){
4 Robot.begin();
5 Robot.beginTFT();//Initialize the TFT module
6}
7
8void loop(){
9 Robot.fill(255,255,255);
10 Robot.text("Hello World",0,0);
11 delay(2000);
12
13 Robot.fill(0,0,0);
14 Robot.text("Hello World",0,0,false);//It's necessary to erase the old text, before showing new text
15
16 Robot.fill(255,255,255);
17 Robot.text("I am a robot",0,0);
18 delay(3000);
19
20 Robot.fill(0,0,0);
21 Robot.text("I am a robot",0,0);
22}

text()

Description

Write some text to an attached TFT.

When updating the screen, remember to erase the text before writing new text on the same place, or the new/old text will be overlapping each other.

The screen is only 128 pixels tall and 160 pixels wide. It's recommended to use small values for x and y, or text may be cropped/invisible in unpredictable ways.

Syntax

1Robot.text(toWrite, x, y, writeOrErase)

Parameters

toWrite: text/value to be written on the LCD. Can be a string, an int or a long.

x: x axis of starting position on the screen.

y: y axis of starting position on the screen.

writeOrErase: specify whether to write the text or erase the text. Use true to write and false to erase.

Returns

none

Examples

1#include <ArduinoRobot.h>
2
3void setup(){
4 Robot.begin();
5 Robot.beginTFT();//Initialize the TFT module
6}
7
8void loop(){
9 Robot.text("Hello World",0,0,true);
10 delay(2000);
11
12 Robot.text("Hello World",0,0,false);//It's necessary to erase the old text, for showing new text
13 Robot.text("I am a robot",0,0,true);
14 delay(3000);
15
16 Robot.text("I am a robot",0,0,false);
17}

beginBMPFromEEPROM()

Description

After beginBMPFromEEPROM() is called, drawBMP() will look for images from the EEPROM, until endBMPFromEEPROM() is called.

Images stored in EEPROM are accessed more slowly than from an SD card.

If drawBMP() cannot find images from EEPROM with the given file name, no image will be rendered on screen, even if a bmp with the same file name is stored on a SD card.

Call endBMPFromEEPROM() after drawBMP() if you want to get images from a SD card afterwards.

Syntax

1Robot.beginBMPFromEEPROM()

Parameters

none

Returns

none

Example

1#include <ArduinoRobot.h>
2
3void setup(){
4 Serial.begin(9600);
5 Robot.begin();
6 Robot.readyLCD();
7
8 //The image is pulled from EEPROM
9 Robot.beginBMPFromEEPROM();
10 Robot.drawBMP("inicio.bmp",0,0);
11 Robot.endBMPFromEEPROM();
12
13}
14void loop(){
15}

endBMPFromEEPROM()

Description

Stops drawBMP() from pulling images in EEPROM. Used in conjunction with beginBMPFromEEPROM().

Syntax

1Robot.endBMPFromEEPROM()

Parameters

none

Returns

none

Example

1#include <ArduinoRobot.h>
2void setup(){
3 Serial.begin(9600);
4 Robot.begin();
5 Robot.readyLCD();
6
7 //The image is pulled from EEPROM
8 Robot.beginBMPFromEEPROM();
9 Robot.drawBMP("inicio.bmp",0,0);
10 Robot.endBMPFromEEPROM();
11
12}
13
14void loop(){
15}

drawDire(direction)

Description

A helper function for drawing a compass on the LCD screen

Parameters

direction: an int between 0 and 359, indicating where the compass should be pointing at. Typically it's one get from Robot.compassRead().

Returns

none

Example

1#include <ArduinoRobot.h>
2void setup(){
3 Robot.begin();
4 Robot.readyLCD();//Initialize the LCD module
5}
6void loop(){
7 int dire=Robot.compassRead();
8 Robot.drawDire(dire);
9}

drawBMP()

Description

Display a bmp file on the LCD screen. The bmp file should be stored in sd card. BMP format should be 24-bit color, and no bigger than 128*160. If an image dimensions exceed the size of the screen, it will be cropped.

To use this method, you must initialize the SD card by calling Robot.beginSD() in setup().

Syntax

1Robot.drawBMP(filename, x, y)

Parameters

filename: name of the bmp file to be displayed. x: x-axis of starting position on the screen. y: y-axis of starting position on the screen.

Returns

none

Examples

1// Draws an image named "intro.bmp" from the SD card
2
3#include <ArduinoRobot.h>
4
5void setup(){
6 Robot.begin();
7 Robot.readyTFT();
8 Robot.beginSD();
9
10 //The image is pulled from sd card
11 Robot.drawBMP("intro.bmp",0,0);
12}
13
14void loop(){
15 // nothing happening here
16}

debugPrint()

Description

Print and refresh a value to the LCD screen. You need to first initialize the LCD screen in setup() by calling Robot.readyLCD(). If no starting point is defined, text defaults to starting at 0,0, the top left of the screen.

Syntax

1Robot.debugPrint(toPrint)
2Robot.debugPrint(toPrint, x, y)

Parameters

toPrint: value to be printed. Must be int or long. x: x axis of starting position on the screen. y: y axis of starting position on the screen.

Returns

none

Examples

1#include <ArduinoRobot.h>
2
3void setup(){
4 Robot.begin();
5 Robot.readyTFT();//Initialize the TFT module
6}
7
8void loop(){
9 int val=Robot.analogRead(TK0); //Get analog value from port TK0 on top board.
10 Robot.debugPrint(val); //No need to erase the old value
11 delay(100);
12}

clearScreen()

Description

Fill the entire screen with the background color. Default is black.

Syntax

1Robot.clearScreen();

Parameters

none

Returns

none

Examples

1#include <ArduinoRobot.h>
2
3void setup(){
4 Robot.begin();
5 Robot.beginTFT();//Initialize the TFT module
6}
7
8void loop(){
9 Robot.text("Hello World",0,0,true);
10 delay(2000);
11
12 Robot.clearScreen();//empty the screen
13 delay(2000);
14}

displayLogos()

Description

A helper function for displaying an opening sequence in some of the examples.

displayLogos() draws "lg0.bmp" and "lg1.bmp" from an attached SD card to the screen, with 2 seconds of delay between the first and second image. There is a 2 second delay after "lg1.bmp", for a total of 4 seconds.

You need to initialize both the LCD and SD card, and have "lg0.bmp" and "lg1.bmp" on the card (they are installed by default).

Syntax

1Robot.displayLogos();

Parameters

none

Returns

none

Examples

1#include <ArduinoRobot.h>
2
3void setup(){
4 Robot.begin();
5 Robot.beginTFT();//Initialize the TFT module
6 Robot.displayLogos();//Show the opening sequence
7}
8
9void loop(){
10 Robot.text("Hello World",0,0,true);
11 delay(2000);
12
13 Robot.text("Hello World",0,0,false);//It's necessary to erase the old text, for showing new text
14 Robot.text("I am a robot",0,0,true);
15 delay(3000);
16
17 Robot.text("I am a robot",0,0,false);
18}

drawCompass()

Description

A helper function for displaying the compass on the TFT. Relies on Robot.beginTFT(). drawCompass() uses debugPrint(), which can't be used in the same sketch.

Mind where you draw text and other graphic elements when using drawCompass() so that you don;t overlap elements.

Syntax

1Robot.drawCompass(degrees);

Parameters

degrees: int between 0 and 359. Typically it's determined by Robot.compassRead().

Returns

none

Examples

1#include <ArduinoRobot.h>
2
3int compassValue;
4
5void setup(){
6 Robot.begin();
7 Robot.beginTFT();//Initialize the TFT module
8}
9
10void loop(){
11 compassValue=Robot.compassRead();
12 Robot.drawCompass(compassValue);//draw the compass
13}

beginSD()

Description

Initialize the SD card for use. Functions that read data from a SD card like drawBMP() and playFile() are dependent on this.

NB : This function uses a lot of memory, and may leads to undefined results if used in a complex sketch. It's recommended to not use this unless you are using the SD card.

Syntax

1Robot.beginSD()

Parameters

none

Returns

none

Examples

1#include <ArduinoRobot.h>
2
3void setup(){
4 Robot.begin();
5 Robot.readyTFT();
6 Robot.beginSD();//Initialize the sd card
7
8 Robot.drawBMP("inicio.bmp",0,0);//draw an image from the sd card
9
10}
11
12void loop(){
13}

userNameRead()

Description

Read the name stored in EEPROM. The name is set by userNameWrite(). EEPROM is not erased when the robot is turned off and can be read anytime after being set.

Syntax

1Robot.userNameRead(container)

Parameters

container: a char array with 8 elements.

Returns

none

Examples

1#include <ArduinoRobot.h>
2
3void setup(){
4 Serial.begin(9600);
5 Robot.begin();
6}
7
8void loop(){
9 Robot.userNameWrite("Aaa");
10 Robot.robotNameWrite("The Robot");
11 Robot.cityNameWrite("Malmo");
12 Robot.countryNameWrite("Sweden");
13
14 char container[8];
15 Robot.userNameRead(container)
16 Serial.println(container);
17
18 Robot.robotNameRead(container)
19 Serial.println(container);
20
21 Robot.cityNameRead(container)
22 Serial.println(container);
23
24 Robot.countryNameRead(container)
25 Serial.println(container);
26}

userNameWrite()

Description

Store your name into EEPROM. EEPROM is always saved, even when the power is switched off.

Syntax

1Robot.userNameWrite(name)

Parameters

name: string to be stored

Returns

none

Examples

1#include <ArduinoRobot.h>
2
3void setup(){
4 Serial.begin(9600);
5 Robot.begin();
6}
7
8void loop(){
9 Robot.userNameWrite("Aaa");
10 Robot.robotNameWrite("The Robot");
11 Robot.cityNameWrite("Malmo");
12 Robot.countryNameWrite("Sweden");
13
14 Serial.println(Robot.userNameRead());
15 Serial.println(Robot.robotNameRead());
16 Serial.println(Robot.cityNameRead());
17 Serial.println(Robot.countryNameRead());
18}

RobotNameRead()

Description

Read the robot name stored in EEPROM. This can be set by robotNameWrite().

Syntax

1Robot.RobotNameRead(container)

Parameters

container: a char array with 8 elements.

Returns

none

Examples

1#include <ArduinoRobot.h>
2
3void setup(){
4 Serial.begin(9600);
5 Robot.begin();
6}
7
8void loop(){
9 Robot.userNameWrite("Aaa");
10 Robot.robotNameWrite("The Robot");
11 Robot.cityNameWrite("Malmo");
12 Robot.countryNameWrite("Sweden");
13
14 char container[8];
15 Robot.userNameRead(container)
16 Serial.println(container);
17
18 Robot.robotNameRead(container)
19 Serial.println(container);
20
21 Robot.cityNameRead(container)
22 Serial.println(container);
23
24 Robot.countryNameRead(container)
25 Serial.println(container);
26}

robotNameWrite()

Description

Store the robot's name into EEPROM.

Syntax

1Robot.robotNameWrite(name)

Parameters

name: string to be stored

Returns

none

Examples

1#include <ArduinoRobot.h>
2
3void setup(){
4 Serial.begin(9600);
5 Robot.begin();
6}
7
8void loop(){
9 Robot.userNameWrite("Aaa");
10 Robot.robotNameWrite("The Robot");
11 Robot.cityNameWrite("Malmo");
12 Robot.countryNameWrite("Sweden");
13
14 Serial.println(Robot.userNameRead());
15 Serial.println(Robot.robotNameRead());
16 Serial.println(Robot.cityNameRead());
17 Serial.println(Robot.countryNameRead());
18}

cityNameRead()

Description

Read your city's name stored in EEPROM. This can be set by cityNameWrite().

Syntax

1Robot.cityNameRead(container)

Parameters

container: a char array with 8 elements.

Returns

none

Examples

1#include <ArduinoRobot.h>
2
3void setup(){
4 Serial.begin(9600);
5 Robot.begin();
6}
7
8void loop(){
9 Robot.userNameWrite("Aaa");
10 Robot.robotNameWrite("The Robot");
11 Robot.cityNameWrite("Malmo");
12 Robot.countryNameWrite("Sweden");
13
14 char container[8];
15 Robot.userNameRead(container)
16 Serial.println(container);
17
18 Robot.robotNameRead(container)
19 Serial.println(container);
20
21 Robot.cityNameRead(container)
22 Serial.println(container);
23
24 Robot.countryNameRead(container)
25 Serial.println(container);
26}

cityNameWrite()

Description

Store your city's name into EEPROM.

Syntax

1Robot.cityNameWrite(name)

Parameters

name: string to be stored

Returns

none

Examples

1#include <ArduinoRobot.h>
2
3void setup(){
4 Serial.begin(9600);
5 Robot.begin();
6}
7
8void loop(){
9 Robot.userNameWrite("Aaa");
10 Robot.robotNameWrite("The Robot");
11 Robot.cityNameWrite("Malmo");
12 Robot.countryNameWrite("Sweden");
13
14 Serial.println(Robot.userNameRead());
15 Serial.println(Robot.robotNameRead());
16 Serial.println(Robot.cityNameRead());
17 Serial.println(Robot.countryNameRead());
18}

countryNameRead()

Description

Read your country's name stored in EEPROM. This is set by userNameWrite().

Syntax

1Robot.countryNameRead(container)

Parameters

container: a char array of 8 elements.

Returns

none

Examples

1#include <ArduinoRobot.h>
2
3void setup(){
4 Serial.begin(9600);
5 Robot.begin();
6}
7
8void loop(){
9 Robot.userNameWrite("Aaa");
10 Robot.robotNameWrite("The Robot");
11 Robot.cityNameWrite("Malmo");
12 Robot.countryNameWrite("Sweden");
13
14 char container[8];
15 Robot.userNameRead(container)
16 Serial.println(container);
17
18 Robot.robotNameRead(container)
19 Serial.println(container);
20
21 Robot.cityNameRead(container)
22 Serial.println(container);
23
24 Robot.countryNameRead(container)
25 Serial.println(container);
26}

countryNameWrite()

Description

Store the user's country name into EEPROM.

Syntax

1Robot.countryNameWrite(name)

Parameters

name: string to be stored

Returns

none

Examples

1#include <ArduinoRobot.h>
2void setup(){
3 Serial.begin(9600);
4 Robot.begin();
5}
6void loop(){
7 Robot.userNameWrite("Aaa");
8 Robot.robotNameWrite("The Robot");
9 Robot.cityNameWrite("Malmo");
10 Robot.countryNameWrite("Sweden");
11
12 Serial.println(Robot.userNameRead());
13 Serial.println(Robot.robotNameRead());
14 Serial.println(Robot.cityNameRead());
15 Serial.println(Robot.countryNameRead());
16}

RobotMotor Class


RobotMotorBoard()

Description

The constructor is empty, as the methods can be accessed through Robot object directly, you don't need to call the constructor.

Parameters

none

Returns

none

Examples

1#include <ArduinoRobotMotorBoard.h>
2void setup(){
3 //methods can be accessed directly through RobotMotor
4 RobotMotor.begin();
5 RobotMotor.motorsWrite(255,255);
6}
7void loop(){
8}

begin()

Description

Initializes the robot motor board. Must be called in setup() to use Robot-specific features. This can only be called on the Motor Board processor.

Syntax

1RobotMotor.begin()

Parameters

none

Returns

none

Examples

1#include <ArduinoRobotMotorBoard.h>
2
3void setup(){
4 RobotMotor.begin();
5}
6
7void loop(){
8 //The robot motor board core routine
9 RobotMotor.parseCommand();
10 RobotMotor.process();
11}

process()

Description

Carry out different actions according to the mode Robot is in. It's part of Robot motor board's core routine. If you want to extend it, see this document.

This can only be called from the Motor Board processor.

Syntax

1RobotMotor.process()

Parameters

none

Returns

none

Examples

1#include <ArduinoRobotMotorBoard.h>
2void setup(){
3 RobotMotor.begin();
4}
5void loop(){
6 //The robot motor board core routine
7 RobotMotor.parseCommand();
8 RobotMotor.process();
9}

parseCommand()

Description

Receive commands from Robot Control Board, and carry them out accordingly. It's part of Robot motor board's core routine. If you want to extend it, see this document.

This can only be called from the Motor Board processor.

Syntax

1RobotMotor.parseCommand()

Parameters

none

Returns

none

Examples

1#include <ArduinoRobotMotorBoard.h>
2void setup(){
3 RobotMotor.begin();
4}
5void loop(){
6 //The robot motor board core routine
7 RobotMotor.parseCommand();
8 RobotMotor.process();
9}

motorsWrite()

Description

Control the robot's wheels speed and direction from the Motor Board processor. It's different from motorsWrite() of the control board. This one drives the motors directly, while the former sends signals to the motor board. So don't mix them in usage.

Syntax

1RobotMotor.motorsWrite(speedL, speedR)

Parameters

speedLeft: controls the speed of left wheel.

speedRight: controls the speed of right wheel.

Both values can be from -255 to 255. If the value is bigger than 0, the wheel turns forward. Smaller than 0, the motor turns backwards.

Returns

none

Examples

1#include <ArduinoRobotMotorBoard.h>
2
3void setup(){
4 RobotMotor.begin();
5}
6
7void loop(){
8 RobotMotor.motorsWrite(255,255);
9 delay(1000);
10 RobotMotor.motorsWrite(0,0);
11 delay(1000);
12}

IRread()

Description

Get the reading from a specific IR sensor. This can only be called from the Motor Board processor. To read the IR sensors from the Control Board, use updateIR().

Syntax

1RobotMotor.IRread(num)

Parameters

num: 1 to 5, corresponding to sensors 1 to 5.

Returns

int : 0 to 1023

Examples

1#include <ArduinoRobotMotorBoard.h>
2void setup(){
3 Serial.begin(9600);
4 RobotMotor.begin();
5}
6void loop(){
7 Serial.println(RobotMotor.IRread(1));
8 delay(10);
9}

Suggest changes

The content on docs.arduino.cc is facilitated through a public GitHub repository. If you see anything wrong, you can edit this page here.

License

The Arduino documentation is licensed under the Creative Commons Attribution-Share Alike 4.0 license.