Reference for Uduino's Arduino library.


Constructor

Description
Create an uduino object. The can be only one Uduino object per script.
Parameters
NameDescription
boardNameconst 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
boardNameconst char*Board name, as it will be detected by Unity
separatorconst 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
commandNameconst char*Command Name
functionvoid*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
functionvoid*New function when the board is connected
Description
Add a function to launch when a board is disconnected from Unity
Parameters
NameDescription
functionvoid*New function when the board is disconnected
Description
Add a default function when
Parameters
NameDescription
functionvoidFunction
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
NumberOfParametersintNumber 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
indexunsigned shortParameter index
Returns
NameDescription
Parameter valuechar*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 valuechar*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
isConnectedboolReturns 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
durationunsigned intDuration of the delay in milliseconds
Description
Convert a char* to an int
Parameters
NameDescription
argchar* 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
nameintdesc
Example

Use uduino.update() instead.

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

Use uduino.isConnected() instead.

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

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