In this post we will learn how to start programming with RoboBoard X4. Aside from simply controlling with a smartphone, you can write a code to tell the robot what to do. It can be programmed to interact with sensors or do certain tasks when button is pressed in the App.

 

About RoboBoard X4

It’s our latest control board containing powerful processor and motor drivers. Just plug in battery, motors and everything will work without any soldering or customization. Look bellow for a brief list of available functionality. For more information on each subject read X4 features reference.

• ESP32 240Mhz processor
• 3 Servo channels
• 4 DC channels
• 4 GPIO channels
• 4 RGB LED
• Totem BUS expansion
• MEMS sensor
• USB port
• Wireless connectivity
• User LED & button
• On/off switch
• DC & battery input

Connecting with smartphone

RobotBoard X4 is designed to run user programmed code while still maintain controlling with a smartphone. Connection is similar as with Totem Mini Control Board X3:

  1. Run Android | iOS Totem app.
  2. Connect battery (or DC adapter) to X4 and set power switch to on.
  3. Click Connect button and select “Totem X4” from the list.

Now, you can control your robot right away. If you bought one of the kits, you will find it in the list of Totem App menu. In case of making your own robot – click + button to create a new model. You can follow tutorial Setting up Totem robot controls to learn creating custom controls in Totem App.

 

Programming X4

 

 

To start programming, you need to install Arduino environment on your PC. It will help to write a code, compile it and upload to X4 board. Follow tutorial Arduino setup to do so. In this guide we will use Arduino IDE as example.

By following setup tutorial, you should have working X4 board with blinking LEDs. If something doesn’t work, create a topic at forum.totemmaker.net and we will help you to resolve the issue.

 

 

Writing our own program

Lets write a simple program to jump LEDs between red, green, blue colors. The code required to do so:

#include <Totem.h>
// Arduino setup function.
void setup() {
    // Initialize X4 module
    Totem.X4.begin();
}
// Arduino loop function
void loop() {
    Totem.X4.write("rgbAll", 255, 255, 0, 0);
    delay(700);
    Totem.X4.write("rgbAll", 255, 0, 255, 0);
    delay(700);
    Totem.X4.write("rgbAll", 255, 0, 0, 255);
    delay(700);
}

Take a look at each line:

#include <Totem.h>

Including Totem Library into code. By doing this, we tell compiler what to to with Totem.X4 functions. For all available functions read TotemModule reference.

void setup() {

Arduino initialization function. This code block will only run once, after each powerup or reset of the X4 board. After finishing, it goes to loop().

Totem.X4.begin();

Function required to initialize RoboBoard X4. It starts Totem Library and background processes required for the Totem.X4.write function to work.

void loop()

Arduino processing function. It executes code inside this block infinitely until board is powered off. If loop() reaches end of the block, it repeats again from the top (line 9).

Totem.X4.write("rgbAll", 255, 255, 0, 0);

Function to set value of RGB LED.
Totem.X4.write – function to send a command to X4 board.
"rgbAll" – command to change color of all 4 RGB LED. For the list of all available commands look X4 module reference.
255, 255, 0, 0 – parameters setting LED brightness and color. Values 0-255 corresponds to 0-100%. The meaning is in order: Brightness, Amount of Red color, Amount of Green color, Amount of Blue color.

delay(700);

loop() runs very fast. This function waits 700 milliseconds until next line of code is executed. In case of missing this line of code – colors would change so fast we couldn’t even see.

Now paste code example to Arduino IDE and press Upload.

LEDs should start blinking. You can try changing parameters and see what happens.