Skip to content

Arduino remote interface

void setup() {
  Totem.BLE.begin(); // Initialize Bluetooth Low Energy interface
}

Wireless interface to control X3 and X4 boards over BLE connection. It contains features like: finding Totem robots, connecting, sending and receiving commands. Totem boards are able to represent themselves as "robot", providing: name, color, model (type of robot). This information is available before BLE connection is established. Same information and functionality is available when using Totem App.

Install library

This functionality requires Totem Arduino Library. Install it before using in a project.

  1. Select SketchInclude LibraryManage libraries..
  2. In search field type in totem.
  3. Click Install and wait for it to complete.
  4. Close Library Manager window.
    Arduino IDE Library install

Code examples

Connect and control motor (click to expand)
// Include Totem Library
#include <Totem.h>
// Declare communication with any connected Totem module
TotemModule module(0);
// Arduino initialization function
void setup() {
  Serial.begin(115200);
  Totem.BLE.begin(); // Start Bluetooth Low Energy interface
  Serial.println("Searching for Totem robot...");
  // Wait until connected to first found Totem robot
  TotemRobot robot = Totem.BLE.findRobot();
  // At this point further execution of setup() is blocked
  // until library connects to the robot
  Serial.print("Connected to: ");
  Serial.println(robot.getName());
  // Continue to loop()
}
// Arduino infinite loop function
void loop() {
  // Control motor of connected robot
  module.write("motorA", 100); // Set motor A channel to 100% power
  delay(1000); // Wait 1 second
  module.write("motorA", 0); // Stop motor on A channel
  delay(1000); // Wait 1 second
}
Connect and control MiniTrooper (click to expand)
// Include Totem library
#include <Totem.h>
// Use MiniTrooper as example robot
TotemMiniTrooper mini;
// User defined function that receives all discovered Totem robots
void onFoundRobot(TotemRobot robot) {
  // Check each found robot and connect to only whose name is "MyRobot"
  // For String reference check: https://www.arduino.cc/reference/en/language/variables/data-types/stringobject/
  if (robot.getName().compareTo("MyRobot") == 0) {
    // Start BLE connection to selected robot.
    if (robot.connect())
      Serial.println("Robot connected");
    else
      Serial.println("Robot connection failed");
    // After successfully connected, findRobot(onFoundRobot) will unblock and application proceeds
  }
}

void setup() {
  // put your setup code here, to run once:
  Totem.BLE.begin(); // Initialize Bluetooth Low Energy interface
  // Totem.BLE.findRobot(); // Optional: automatically connect to first discovered Totem robot
  Totem.BLE.findRobot(onFoundRobot); // Start searching over BLE. This function will block until connected to any 
                                     // Totem robot. After connection is successful, loop() will be executed.
                                     // onFoundRobot will list every discovered robot.
}

void loop() {
  // put your main code here, to run repeatedly:
  // Example to open and close flipper on MiniTrooper
  mini.flipperOpen();
  delay(1000);
  mini.flipperClose();
  delay(1000);
}

Additional classes

  • ModuleData - Object containing data received from module.
  • MotorDriver - Object helping to control DC and Servo motors.
  • TotemModule - Instance of Totem module, allowing to send and receive commands.
  • TotemRobot - Instance of connection to a wireless or remote access capable Totem module.

Functions

Totem.BLE.begin()

Initialize Bluetooth Low Energy interface. Must be executed inside setup() function before using library.
void setup() {
  Totem.BLE.begin(); // Initialize Bluetooth Low Energy interface
}

(TotemRobot) Totem.BLE.findRobot()

(TotemRobot) Totem.BLE.findRobot(RobotReceiver)

Start searching for available Totem robots over Bluetooth Low Energy. This function will block until connection to any robot is established.
On successful connection find process will be stopped. Additionally it can be stopped with call to stopFind().
RobotReceiver is a user defined function to get all discovered robots.
Format: void onFoundRobot(TotemRobot robot). Robot information can be accessed trough TotemRobot parameter. By calling robot .connect() user can decide which robot to select.
Parameter:
() - automatically connect to first discovered Totem robot.
RobotReceiver - discovered robot connect function onFoundRobot.
Returns: TotemRobot.
void onFoundRobot(TotemRobot robot) {
  // Totem robot discovered
  robot.connect();
}
void function() {
  Totem.BLE.findRobot(); // Automatically connect to first discovered Totem robot
  Totem.BLE.findRobot(onFoundRobot); // List result in onFoundRobot before connecting to Totem robot
}

Totem.BLE.findRobotNoBlock()

Totem.BLE.findRobotNoBlock(RobotReceiver)

Start searching for available Totem robots over Bluetooth Low Energy. This function does not block main program execution. All connection process will be done in background.
After connection is established, this process will be stopped. Additionally it can be stopped with call to stopFind().
RobotReceiver is a user defined function to get all discovered robots.
Format: void onFoundRobot(TotemRobot robot). Robot information can be accessed trough TotemRobot parameter. By calling robot .connect() user can decide which robot to select.
Parameter:
() - automatically connect to first discovered Totem robot.
RobotReceiver - discovered robot connect function onFoundRobot.
void onFoundRobot(TotemRobot robot) {
  // Totem robot discovered
  robot.connect();
}
void function() {
  Totem.BLE.findRobotNoBlock(); // Automatically connect to first discovered Totem robot
  Totem.BLE.findRobotNoBlock(onFoundRobot); // List result in onFoundRobot before connecting to Totem robot
}

(bool) Totem.BLE.isFinding()

Check if findRobot() or findRobotNoBlock() was called and process is active.
Returns: discovery process is active [true:false].
void function() {
  if (Totem.BLE.isFinding())
    Serial.println("Robot find is active");
  else
    Serial.println("Robot find is inactive);
}

Totem.BLE.stopFind()

Stop searching for robot and unblock findRobot(). Only used when required to stop this process manually. After connection, the search process is stopped automatically and calling this function is not required.
void function() {
  Totem.BLE.stopFind(); // Stop searching for robot over Bluetooth Low Energy
}

Totem.BLE.attachOnConnect(RobotReceiver)

Register function that will be called when findRobot() process connects to a robot. This is handy when using non-blocking find process and we don't know when connection is established.
RobotReceiver is a user defined function to connected robot event.
Format: void onConnectedRobot(TotemRobot robot). Robot information can be accessed trough TotemRobot parameter.
Parameter: RobotReceiver - connected robot event function onConnectedRobot.
void onConnectedRobot(TotemRobot robot) {
  // findRobotNoBlock connected to robot in background and ended find procedure
  Serial.print("Connected robot: ");
  Serial.println(robot.getName());
}
void function() {
  Totem.BLE.findRobotNoBlock(); // Automatically connect to first discovered Totem robot
                                // Code execution continues with active find procedure
}

(int) Totem.BLE.getConnectedCount()

Count of currently connected Totem robots.
Returns: connected robots count [0:20]
void function() {
  Serial.print("Currently connected robots count: ");
  Serial.println(Totem.BLE.getConnectedCount());
}

(TotemRobot) Totem.BLE.getConnectedLast()

Get last connected robot.
If no connection was made before, this function returns a dummy object that isn't connected.
Returns: TotemRobot.
void function() {
  TotemRobot robot = Totem.BLE.getConnectedLast();
  Serial.print("Is last connected robot still connected: ");
  Serial.println(robot.isConnected() ? "Yes" : "No");
}

(TotemRobot[]) Totem.BLE.getConnectedList()

Get list of connected robots.
Returns: TotemRobot[].
void function() {
  for (auto robot : getConnectedList()) {
    Serial.print("Connected robot: ");
    Serial.println(robot.getName());
  }
}