Studuino Library Reference
Studuino Library Reference
Function Reference
Published 2014/11/01
Revised 2018/02/01
Version History
Date Content
2014/11/01 First version
2017/01/16 Updated for new Studuino website
2017/08/16 Changed Stduino.h to Studuino.h in program examples
2018/02/01 Revised text
1
Index
1. Getting Started ....................................................................................................... 3
2. Functions ............................................................................................................... 3
2.1. Initialization Functions ............................................................................................. 3
2.2. DC Motor Functions ................................................................................................ 7
2.3. Servomotor Functions ........................................................................................... 10
2.4. Buzzer Functions................................................................................................... 12
2.5. LED Functions ....................................................................................................... 14
2.6. Input Functions ...................................................................................................... 15
2.7. Timer Functions..................................................................................................... 22
2.8. Studuino mini Functions ........................................................................................ 23
2.9. Constants .............................................................................................................. 28
3. Programming ....................................................................................................... 31
3.1. The Arduino Language.......................................................................................... 31
3.2. Studuino Objects ................................................................................................... 31
3.3. Including Header Files .......................................................................................... 31
3.4. Sample Programs.................................................................................................. 32
3.4.1. DC Motors...................................................................................................... 32
3.4.2. Servomotors .................................................................................................. 33
3.4.3. Buzzers .......................................................................................................... 35
3.4.4. LEDs .............................................................................................................. 36
3.4.5. Sensors .......................................................................................................... 37
A. Connecting DC Motors to Studuino ...................................................................... 42
2
1. Getting Started
This manual covers the Studuino Function Library used to describe programs made for
your Studuino in Arduino IDE. The Library contains functions used to control ArtecRobo
electronic parts including DC Motors and Servomotors, allowing you to use these functions
to program your parts.
The information in this manual is subject to revision at any time.
2. Functions
Descriptions of functions will be in the following format:
Function name: (Function name)
Argument (Type) (Variable name) (Value) (Description)
Return value (Type) (Description)
Notes
Find descriptions of each function below.
3
Function name SetServomotorCalibration
Argument char[8] offsets -15 ~ 15 Offset values
Return values None
Use this function only to adjust a Servomotor’s initial angle.
This function adjusts a Servomotor’s angle. Change the values of the arguments in offsets
[0] ~ [7] to specify the angle for the corresponding Servomotor on D2 ~ D12.
(Example)
// Specify a Servomotor connected to D9 ~ D12
byte calib[] = { 0, 0, 0, 0, -6, 0, 12, 3 }; // Angles: D9(-6°), D10(0°), D11(12°), D12(3°)
SetServomotorCalibration(calib); // Servomotor speed calibration setting
4
Function name InitServomotorPortForLED
Argument byte connector PORT_D9 Connector
PORT_D10
PORT_D11
Return values None
Initializes Servomotor ports D9, D10, or D11 for use with an LED. Use this function to
initialize the port before adjusting the brightness of an LED on D9, D10, or D11.
(Example)
// Use this function to initialize the port before running the Gradation function
InitServomotorPortForLEDPORT_D9); // Initialize port D9 for use with an LED
Gradation(PORT_D9, 128);
5
Function name InitSensorPort
Argument byte connector1 See * 4 Connector
byte connector2 See * 4 Connector
byte pid See * 5 Parts
Return values None
This function initializes ports for an Ultrasonic Sensor. Use this function to initialize ports
before using them with an Ultrasonic Sensor.
(Example)
InitSensorPort(PORT_A0, PORT_A1, PIDULTRASONICSENSOR); // Initialize port A0 and
A1 for use with an Ultrasonic Sensor
6
2.2. DC Motor Functions
This section covers the functions used to control DC Motors.
Function name Move
Argument byte direct FORWARD Go forward
BACKWARD Go backwards
FORWARD_RIGHT Right turn (F)
FORWARD_LEFT Left turn (F)
BACKWARD_RIGHT Right turn (B)
BACKWARD_LEFT Left turn (B)
CLOCKWISE Turn clockwise
COUNTERCLOCKWISE Turn
counterclockwise
byte pace 0 ~ 255 Speed (steps)
ulong duration 0 ~ 2^32-1 Time (msec)
byte brake BRAKE Use brakes
COAST Don’t use brakes
Return value None
This function is used to control the movements of a car that uses two DC Motors. The DC
Motors will need to be attached to the board in a specific way in order to use it. See
Connecting DC Motors to Studuino to learn how to build this car.
(Example)
Move (FORWARD, 10, 1000, BRAKE); // Car drives forward at speed 10 for one second
before stopping
7
Function name DCMotor
Argument byte connector PORT_M1 Connector
PORT_M2
byte rotation NORMAL Forward
REVERSE Backward
byte pace 0 ~ 255 Speed (steps)
ulong duration 0 ~ 2^32-1 Time (msec)
byte brake BRAKE Use brakes
COAST Don’t use brakes
Return value None
This function controls a single DC Motor.
(Example)
// Make a DC Motor on M1 rotate at speed 10 for one second and stop
DCMotor (PORT_M1, NORMAL, 10, 1000, BRAKE);
8
Function name DCMotorControl
Argument byte connector PORT_M1 Connector
PORT_M2
byte rotation NORMAL Forward
REVERSE Backward
BRAKE Use brakes
COAST Don’t use brakes
Return value None
This function controls a DC Motor’s rotation.
(Example)
// Make a DC Motor on M1 rotate at speed 10 for one second and stop
DCMotorPower(PORT_M1, 10); // Set the speed of the DC Motor on M1
DCMotorControl(PORT_M1, CLOCKWISE); // Set the DC Motor on M1 to clockwise
Timer(1000); // Count one second
DCMotorControl(PORT_M1, BRAKE); // Stop the DC Motor on M1
9
2.3. Servomotor Functions
This section covers the functions used to control Servomotors.
Function name Servomotor
Argument byte connector See * 1 Connector
byte degree 0 ~ 180 Servomotor Angle
Return value None
Sets an angle for one Servomotor. The next process in the program will run as the
Servomotor is rotating.
(Example)
// Set the Servomotor on D2 to 90 degrees
Servomotor (PORT_D2, 90);
10
Function name SyncServomotors
Argument byte[] connector See * 1 Arrangement of connectors
byte[] degree 0 ~ 180 Angle for each Servomotor
byte number 1~8 Number of Servomotors
byte time 3 ~ 255 Turning time per degree (ms)
Return value None
Sets angles for multiple Servomotors. The program will wait until all Servomotors rotate to
the specified angles before running other processes. Make your Servomotors rotate more
slowly by increasing the value of time. Be aware that the maximum speed per degree is
three milliseconds, which means that setting time to any number under three will still make
your Servomotors rotate at this speed.
(Example)
// Set the Servomotors on D2, D9, and D10 to 90, 180, and 45 degrees
byte myConectors[] = { PORT_D2, PORT_D9, PORT_D10 };
byte myDegrees[] = { 90, 180, 45};
SyncServomotor (myConectors, myDegrees, 3, 5);
11
2.4. Buzzer Functions
This section covers the functions used to control Buzzers.
Function name Buzzer
Argument byte connector See * 3 Connector
word pitch See * 6 Notes
ulong duration 0 ~ 2^32-1 Play time
(msec)
Return value None
Plays the note from the Buzzer for the specified period of time.
(Example)
Buzzer (PORT_A0, BZR_C4, 1000); // Use Buzzer A0 to play the note “Do” for one second
12
Function name Melody
Argument byte connector See * 3
word[] pitches See * 6 Note
float[] beats 0~ Beat
byte number Melody number Number of notes
byte tempo TEMPO60 Tempo
TEMPO90
TEMPO120
TEMPO150
Return value None
Uses the Buzzer to play a melody.
(Example)
// Use Buzzer A0 to play Do, Re, Mi, Fa, Mi, Re, Do.
word myPitches[] = { BZR_C3, BZR_D3, BZR_E3, BZR_F3,
BZR_E3, BZR_D3, BZR_C3 };
float myBeats[] = { 1, 1, 1, 1, 1, 1, 1 };
byte num = 7; // Number of elements
Melody (PORT_A0, myPitches, myBeats, num, TEMPO90);
13
2.5. LED Functions
This section covers the functions used to control LEDs.
Function name LED
Argument byte connector See * 3 Connector
boolean onoff ON LED ON/OFF
OFF
Return value None
Turns the LED on or off.
(Example)
LED (PORT_A0, ON); // Turn an LED on A0 on
14
2.6. Input Functions
This section covers functions used for Push-buttons and sensors.
Function name GetPushSwitchValue
Argument byte connector See * 2 Connector
Return value byte 0: Pressed, 1: Released
Retrieves the state of a Push-button.
(Example)
// Get the value of a Push-button on A0
byte val = GetPushSwitchValue (PORT_A0);
15
Function name GetIRPhotoreflectorValue
Argument byte connector See * 4 Connector
Return value int 0 ~ 1023
Retrieves the value of an IR Photoreflector.
(Example)
// Get the value of an IR Photoreflector on A0
int val = GetIRPhotoreflectorValue (PORT_A0);
16
Function name GetUltrasonicSensorValue
Argument byte trigger See * 4 Connector
byte echo See * 4 Connector
Return value unsigned long Time it takes to pickup ultrasonic waves (in
microseconds)
Retrieves the value of an Ultrasonic Sensor. It returns the amount of time (in
microseconds) it takes for the ultrasonic waves emitted by the triggerPin to be picked up by
the echoPin.
(Example)
unsigned long val = GetUltrasonicSensorValue(PORT_A0, PORT_A1); // Get the value of
the Ultrasonic Sensor
double dist = val / 58.0; // Convert distance to cm
58 = 29[us/cm] * 2: Multiplies the amount of time (in microseconds) it takes for sound to
travel one centimeter by two (making one round-trip)
17
Function name GetIRReceiverValue
Argument None
Return value unsigned long IR Signal value
Retrieves the value of an IR Receiver.
(Example)
unsigned long val = GetIRReceiverValue(); // Get the value of the IR Receiver
18
Function name GetColorSensorValue
Argument byte axis VALUE_RED Composition of
VALUE_GREEN measured color
VALUE_BLUE
VALUE_CLEAR
Return value Unsigned int Composition of detected color
Retrieves the value of a Color Sensor. Returns the color composition of detected light by
using red, green, blue, and clear filters (filterless).
(Example)
unsigned int sv = GetColorSensorValue(VALUE_RED); // Get the composition of red
detected by the Color Sensor
19
Function name GetColorCode
Argument None
Return value byte COLOR_UNDEF Undefinable color
COLOR_RED Red
COLOR_GREEN Green
COLOR_BLUE Blue
COLOR_WHITE White
COLOR_YELLOW Yellow
COLOR_BROWN Brown
COLOR_BLACK Black
Determines whether the Artec Block is red, green, blue, white, yellow, brown, or black and
returns the corresponding code.
(Example)
int sv = board.GetColorCode(); // Return the color code of the Artec Block
20
Function name GetBTCommandIDState
Argument byte id BT_ID_01 ~ BT_ID_10, BT_ID_ACC
Return value boolean Check whether ID and accelerometer are enabled
Retrieves the state of the specified command ID from the value of UpdateBluetooth.
Target ID Return Value
On-screen Button BT_ID_01 ~ BT_ID_10 TRUE: ON
FALSE: OFF
Accelerometer BT_ID_ACC TRUE: Enabled
FALSE: Disabled
(Example)
board.UpdateBluetooth();
boolean fID1 = board.GetBTCommandIDState(BT_ID_01); // Check whether the button
assigned to ID01 in the application is pressed
if(fID1 == true) {
// If button is pressed
}
21
2.7. Timer Functions
This section covers functions that wait for a specified time.
Function name Timer
Argument unsigned long time 0 ~ 2^32-1 Time (msec)
Return value None
Make the process stop for the specified amount of time.
(Example)
Timer(1000); // Stop for one second.
22
2.8. Studuino mini Functions
The following functions can only be used with Studuino mini.
Function name InitClock
Argument None
Return value None
Initializes the port for the LCD Clock.
23
Function name setBackLight
Argument byte red 0 ~ 15 16 levels from 0 [dark] to 15 [bright]
byte green 0 ~ 15 16 levels from 0 [dark] to 15 [bright]
byte blue 0 ~ 15 16 levels from 0 [dark] to 15 [bright]
Return value None
Changes the color of the LCD Clock’s backlight.
(Example)
board.setBackLight(15, 10, 5); // Set red to 15, green to 10, and blue to five
★ The clock will turn on using the color last specified in setBackLight.
24
Function name GetHour
Argument None
Return value int Hour
Retrieves the hour from the LCD Clock.
25
Function name GetAlarmHour
Argument None
Return value int Alarm hour
Retrieves the alarm hour from the LCD Clock.
TRUE FALSE
pitches See * 3 ・Always False
・Current time doesn’t match alarm time
On ・Current time matches alarm time
・STOP button is pressed when True
(Example)
for(;;) {
if(board.isAlarmTime()) {
board.clockBuzzer(BZR_CS4, 2000);
}
}
26
Function name sleep
Argument None
Return value None
SLEEP_MODE_PWR_SAVE will activate the clock’s power-saving mode.
27
2.9. Constants
28
*4 Analog Port Values
Value Port
PORT_A0 A0
PORT_A1 A1
PORT_A2 A2
PORT_A3 A3
PORT_A4 A4
PORT_A5 A5
PORT_A6 A6
PORT_A7 A7
*5 Part IDs
Value Part
PIDOPEN Disconnected
PIDLED LED
PIDBUZZER Buzzer
PIDLIGHTSENSOR Light Sensor
PIDSOUNDSENSOR Sound Sensor
PIDIRPHOTOREFLECTOR IR Photoreflector
PIDACCELEROMETER Accelerometer
PIDTOUCHSENSOR Touch Sensor
PIDPUSHSWITCH Push-button
PIDIRRECEIVER IR Receiver
PIDGYROSCOPE Gyroscope (*)
PIDTEMPERATURESENSOR Temperature Sensor
PIDULTRASONICSENSOR Ultrasonic Sensor
PIDCOLORSENSOR Color Sensor (*)
(*): I2C device
*6 Note Values
Value Note Hz Value Note Hz Value Note Hz
BZR_C3 Do 130 BZR_C5 Do 523 BZR_C7 Do 2093
BZR_CS3 Do # 139 BZR_CS5 Do # 554 BZR_CS7 Do # 2217
BZR_D3 Re 147 BZR_D5 Re 587 BZR_D7 Re 2349
BZR_DS3 Re # 156 BZR_DS5 Re # 622 BZR_DS7 Re # 2489
BZR_E3 Mi 165 BZR_E5 Mi 659 BZR_E7 Mi 2637
BZR_F3 Fa 175 BZR_F5 Fa 698 BZR_F7 Fa 2794
BZR_FS3 Fa # 185 BZR_FS5 Fa # 740 BZR_FS7 Fa # 2960
BZR_G3 So 196 BZR_G5 So 784 BZR_G7 So 3136
BZR_GS3 So # 208 BZR_GS5 So # 831 BZR_GS7 So # 3322
BZR_A3 La 220 BZR_A5 La 880 BZR_A7 La 3520
BZR_AS3 La # 233 BZR_AS5 La # 932 BZR_AS7 La # 3729
BZR_B3 Ti 247 BZR_B5 Ti 988 BZR_B7 Ti 3951
BZR_C4 Do 262 BZR_C6 Do 1047 BZR_C8 Do 4186
BZR_CS4 Do # 277 BZR_CS6 Do # 1109 BZR_S Silence 0
BZR_D4 Re 294 BZR_D6 Re 1175
BZR_DS4 Re # 311 BZR_DS6 Re # 1245
BZR_E4 Mi 330 BZR_E6 Mi 1319
BZR_F4 Fa 349 BZR_F6 Fa 1397
BZR_FS4 Fa # 370 BZR_FS6 Fa # 1480
BZR_G4 So 392 BZR_G6 So 1568
BZR_GS4 So # 415 BZR_GS6 So # 1661
BZR_A4 La 440 BZR_A6 La 1760
BZR_AS4 La # 466 BZR_AS6 La # 1865
BZR_B4 Ti 494 BZR_B6 Ti 1976
30
3. Programming
You’ll have to keep the points in these sections in mind when using the Studuino Function
Library to create a program for your Studuino.
// Called once at the start of the program. Primarily used for initialization.
void setup() {
// Uses initialization functions to initialize Studuino ports with parts connected
}
31
3.4. Sample Programs
The following sections contains example programs for each part.
3.4.1. DC Motors
Using A. Connecting DC Motors to Studuino as a reference, connect DC Motors to M1 and
M2 on your Studuino and load the following program using the Arduino IDE.
The car will move forward for one second then reverse for one second.
// Called once at the start of the program. Primarily used for initialization.
void setup() {
// Use initialization functions to initialize Studuino ports with parts connected
board.InitDCMotorPort(PORT_M1); // Initializes port M1 for use with a DC Motor.
board.InitDCMotorPort(PORT_M2); // Initializes port M2 for use with a DC Motor.
}
for (;;) {} // Infinite loop to keep program from starting over from the top
}
32
3.4.2. Servomotors
Connect Servomotors to D10, D11, and D12 on your Studuino and load the following
program using the Arduino IDE. All Servomotors will initialize at 90°. The program will wait
three seconds before simultaneously turning all three Servomotors to 90°, 180°, and 0°. It
will then wait three more seconds before turning Servomotor D10 to 180°.
// Called once at the start of the program. Primarily used for initialization.
void setup() {
// Use initialization functions to initialize Studuino ports with parts connected
board.InitDCMotorPort(PORT_D10); // Initialize port D10 for use with a Servomotor
board.InitDCMotorPort(PORT_D11); // Initialize port D11 for use with a Servomotor
board.InitDCMotorPort(PORT_D12); // Initialize port D12 for use with a Servomotor
}
// This function runs an infinite loop. Main process.
void loop() {
// Initialize Servomotor at 90 degrees
byte connector[] = { PORT_D10, PORT_D11, PORT_D12 };
byte degree[] = { 90, 90, 90 };
byte number = sizeof(connector) / sizeof(byte); // Number of ports for which angles will
be set
// Set Servomotors connected to ports D10, D11, and D12 to 90, 180, and 0 degrees
degree[0] = 90;
degree[1] = 180;
degree[2] = 0;
// Servomotors will have reached their target angle once this function finishes running
33
board.Timer(1000);
for (;;) {} // Infinite loop to keep program from starting over from the top
}
34
3.4.3. Buzzers
Connect a Buzzer to A0 on your Studuino and load the following program using the Arduino
IDE. This program plays “Do” for one second and “So” for one second before playing
Twinkle, Twinkle, Little Star.
// These functions are run once at the start of the program. Primarily used for initialization.
void setup() {
// Use initialization functions to initialize Studuino ports with parts connected
board.InitDCMotorPort(PORT_A0 ,DC ); // Initialize port A0 for use with a Buzzer
}
for (;;) {} // Infinite loop to keep program from starting over from the top
}
35
3.4.4. LEDs
Connect LEDs to A1 and D9 on your Studuino and load the following program using the
Arduino IDE. LED A1 will blink three times before LED D9 slowly turns on.
// Called once at the start of the program. Used primarily for initialization.
void setup() {
// Use initialization functions to initialize Studuino ports with parts connected
board.InitDCMotorPort(PORT_A1 ,DC );// Initialize port A0 for use with an LED
board.InitDCMotorPort(PORT_D9); // Initialize port D9 for use with an LED
}
for (;;) {} // Infinite loop to keep program from starting over from the top
}
36
3.4.5. Sensors
① Regular Sensors
Connect a Touch Sensor to A1, a Sound Sensor to A2, an IR Photoreflector to A3, an
Accelerometer to A4/A5, and a Light Sensor to A6 on your Studuino and load the following
program using the Arduino IDE. Once you’ve loaded the program, go to Tools in Arduino
IDE and choose Serial Monitor to open the Serial Monitor. The Serial Monitor shows you the
value of each sensor.
// Called once at the start of the program. Used primarily for initialization.
void setup() {
// Use initialization functions to initialize Studuino ports with parts connected
board.InitSensorPort(PORT_A0, PIDPUSHSWITCH);
board.InitSensorPort(PORT_A1, PIDTOUCHSENSOR);
board.InitSensorPort(PORT_A2, PIDSOUNDSENSOR);
board.InitSensorPort(PORT_A3, PIDIRPHOTOREFLECTOR);
board.InitSensorPort(PORT_A4, PIDACCELEROMETER);
board.InitSensorPort(PORT_A5, PIDACCELEROMETER);
board.InitSensorPort(PORT_A6, PIDLIGHTSENSOR);
37
Serial.print("y:"); Serial.print(yVal); Serial.print("\t");
Serial.print("z:"); Serial.print(zVal); Serial.print("\t");
Serial.print("light:"); Serial.print(lVal); Serial.println();
board.Timer(100);
}
}
// Called once at the start of the program. Used primarily for initialization.
void setup() {
// Use initialization functions to initialize Studuino ports with parts connected
board.InitSensorPort(PORT_A0, PORT_A1, PIDULTRASONICSENSOR);
board.InitSensorPort(PORT_A2, PIDTEMPERATURESENSOR);
board.InitI2CPort(PIDGYROSCOPE);
38
Serial.print("gy:"); Serial.print(gyVal); Serial.print("\t");
Serial.print("gz:"); Serial.print(gzVal); Serial.println();;
board.Timer(100);
}
// Called once at the start of the program. Used primarily for initialization.
void setup() {
// Use initialization functions to initialize Studuino ports with parts connected
board.InitSensorPort(PORT_A0, PIDIRRECEIVER); // Sensor input setting
39
④ Optional Parts: Color Sensors
Connect a Color Sensor to A4/A5 on your Studuino and load the following program using
the Arduino IDE. Once you’ve loaded the program, go to Tools in Arduino IDE and choose
Serial Monitor to open the Serial Monitor. The Serial Monitor shows you the value of each
sensor.
// Called once at the start of the program. Used primarily for initialization.
void setup() {
// Use initialization functions to initialize Studuino ports with parts connected
board.InitI2CPort(PIDCOLORSENSOR); // Start Color Sensor
40
⑤ Optional Parts: Bluetooth Module
Without connecting anything, load the following program using the Arduino IDE. Once it’s
loaded, plug the Bluetooth communication pins on D0 and D1 into the power supply of any
open sensor port from A0-A7. Open the application, connect your Studuino, and send
values to turn your Studuino’s onboard LED on pin 13 on and off.
// Called once at the start of the program. Used primarily for initialization.
void setup() {
// Use initialization functions to initialize Studuino ports with parts connected
board.InitBluetooth();
pinMode(13, OUTPUT);
}
41
A. Connecting DC Motors to Studuino
(4) Now plug your DC Motors and Battery Box into your Studuino.
(5) Set your Battery Box in your Studuino mount to keep it in place.
42