Modules on TotemBUS has 2 identifiers: module number (which is 11 for distance sensor) and module serial (15 bit unique identifier). You can communicate with modules only by using number (where all modules on TotemBUS responds) or number and serial (where only specific module responds).
This way all modules respond to commands:
Module11 sensor; // Control all modules with number 11
void setup() {
sensor.rgb.on(); // Will turn LED on for all connected modules with number 11
}
Module11
object actually has a constructor to accept serial number Module11(uint16_t serial = 0)
, so you can can declare object referencing specific module.
This will control modules individually:
Module11 sensor1(9724); // Init module 11 with serial 9724
Module11 sensor2(9740); // Init module 11 with serial 9740
void setup() {
sensor1.rgb.color(255, 0, 0); // Set red color for number 11 serial 9724
sensor2.rgb.color(0, 255, 0); // Set green color for number 11 serial 9740
sensor1.distance.getMM(); // Get distance of module with serial 9724
sensor2.distance.getMM(); // Get distance of module with serial 9740
}
Arduino example of controlling multiple sensors (can also find in Arduino IDE Examples -> TotemBUS -> SameModules
): TotemArduinoBoards/SameModules.ino at master · totemmaker/TotemArduinoBoards · GitHub
Also this is mentioned in documentation: https://docs.totemmaker.net/modules/programming/#accessing-specific-module
Now tricky part to acquire this serial. You need to use X4.module
functionality ping modules and “discover” them. Run the code and connect module to TotemBUS. It will print its serial.
// Function called when ping response from module is received
void moduleDiscovered() {
int number = X4.module.getLastNumber();
int serial = X4.module.getLastSerial();
Serial.printf("Found. number: %d, serial: %d\n", number, serial);
}
void setup() {
Serial.begin(115200);
// Register module ping response event function
X4.module.addEvent(moduleDiscovered);
}
void loop() {
Serial.println("Scan...");
X4.module.ping(); // Ping all modules
delay(500);
}
Note: connect only one module at the time. This “ping” method doesn’t work reliably at the moment.
Example code: TotemArduinoBoards/ListConnectedModules.ino at master · totemmaker/TotemArduinoBoards · GitHub
Documentation: https://docs.totemmaker.net/roboboard-x4/module/