Reference for Uduino's Arduino library.


Constructor

Description
Create an uduino object. The can be only one Uduino object per script.
Parameters
NameDescription
boardName const char*Board name, as it will be detected by Unity
Example
#include<Uduino.h>
Uduino uduino("boardName");
Description
Create an uduino object with a custom separator. By default, the separator is the space character. If you change this value, don't forget to edit the Uduino settings in Unity
Parameters
NameDescription
boardName const char*Board name, as it will be detected by Unity
separator const char*Separator
Example
#include<Uduino.h>
Uduino uduino("boardName", "|"); // Set the character | as separator

Custom commands

Description
Register a command that can be triggered by Unity
Parameters
NameDescription
commandName const char*Command Name
function void*Function to trigger when the command is received
Example

Arduino

void Setup()
uduino.addCommand("commandName",MyFunction);
}

void MyFunction() {
// code
}

Unity

UduinoManager.Instance.sendCommand("commandName");
Description
Add a function to launch when a board is detected by Unity
Parameters
NameDescription
function void*New function when the board is connected
Description
Add a function to launch when a board is disconnected from Unity
Parameters
NameDescription
function void*New function when the board is disconnected
Description
Add a default function when
Parameters
NameDescription
function voidFunction
Example
void setup() {
uduino.addDefaultHandler(DefaultFunction);
}
void DefaultFuntion() {
// default function
}

Parsing parameters in commands

Description
Get the number of parameters in a callback function
Returns
NameDescription
NumberOfParameters intNumber of parameters
Example

Unity

UduinoManager.Instance.sendCommand("myCommand", 10, 3);

Arduino

void setup() {
uduino.addCommand("myCommand", Command);
}

void Command() {
int parameters = uduino.getNumberOfParameters(); // returns 2
if(parameters > 0) {
int valueOne = uduino.charToInt(uduino.getParameter(0)); // returns 10
int valueTwo = uduino.charToInt(uduino.getParameter(1)); // returns 3
}
}
Description
Get the paramater value at a specific index
Parameters
NameDescription
index unsigned shortParameter index
Returns
NameDescription
Parameter value char*Value as text
Example

Unity

UduinoManager.Instance.sendCommand("myCommand", 10, 3);

Arduino

void setup() {
uduino.addCommand("myCommand", Command);
}

void Command() {
int parameters = uduino.getNumberOfParameters(); // returns 2
if(parameters > 0) {
int valueOne = uduino.charToInt(uduino.getParameter(0)); // returns 10
int valueTwo = uduino.charToInt(uduino.getParameter(1)); // returns 3
}
}
Description
Get the next parameter
Returns
NameDescription
Parameter value char*Value as text
Example

Unity

UduinoManager.Instance.sendCommand("myCommand", 10, 3);

Arduino

void setup() {
uduino.addCommand("myCommand", Command);
}

void Command() {
int value;
char *arg = NULL;
arg = uduino.next();
if (arg != NULL) {
value = atoi(arg); // returns 10
}
int valueTwo;
arg = uduino.next();
if (arg != NULL) {
valueTwo = atoi(arg); // returns 3
}
}

Loop functions

Description
Update uduino. This function needs to be in the main loop.
Example
void loop() {
uduino.update();
}
Description
Detect if a board is connected. To optimize the code, put the main function in this condition
Returns
NameDescription
isConnected boolReturns true if a board is connected
Example

Arduino

void loop() {
uduino.update();
if(uduino.isConnected()) {
//..code
}
}

Utils

Description
Custom delay function. Using the default delay() function will break the reading of the incomming messages.
Parameters
NameDescription
duration unsigned intDuration of the delay in milliseconds
Description
Convert a char* to an int
Parameters
NameDescription
arg char* intDuration of the delay in milliseconds
Example

Unity

void setup() {
uduino.addCommand("myCommand", Command);
}

void Command() {
int value;
char *arg = NULL;
arg = uduino.next();
if (arg != NULL)
value = atoi(arg);
}

Uduino.h library defines

These settings can be changed in the Uduino.h main file. This file is located under /documents/Arduino/libraries/Uduino.h

Description
Maximum number of commands
Parameters

There is a fixed limit of commands a user can register using uduino.addCommand("") function. By default, this setting is set to 16, including 3 default commands. If you want to use more custom commands, this setting needs to be increased.

Important: This will increase the memory footprint of the sketch.

NameDescription
Example
// file Uduino.h, ligne ~47

#define MAX_COMMANDS 30
Description
Maximum length of a command name
Parameters

There is maxium length of a commands name. By default, it is possible to add commands of 16 characters longuduino.addCommand("") function.

If you want to use longer custom commands names, this setting needs to be increased.

Important: This will increase the memory footprint of the sketch.

NameDescription
Example
// file Uduino.h, ligne ~46

#define MAX_COMMAND_NAME 30
// sketch

void setup () {
//...
uduino.addCommand("ThisIsALongCommandNameVeryLong", myFunction);
//...
}

Deprecated

Description
Internal call to `update()` function
Parameters
NameDescription
name intdesc
Example

Use uduino.update() instead.

Description
Internal call to `isConnected()` function
Parameters
NameDescription
name intdesc
Example

Use uduino.isConnected() instead.

Description
Internal call to `nextParameter()` function
Parameters
NameDescription
name intdesc
Example

Use uduino.nextParameter() or uduino.getParameter( int index)