RemoteXY

Control your microcontroller remotely

RemoteXY

This page guides you through using RemoteXY to control your robot remotely.

Duration :
Difficulty :
Created by:  Adrien BRACQ & Rémi LACOMBE

About RemoteXY

RemoteXY is a platform for creating user interfaces to control microcontrollers (such as Arduino, ESP32, STM32 and so on) from mobile devices (smartphones or tablets). These interfaces can include buttons, sliders, joysticks, indicators and more.

RemoteXY thus makes it simple to create interactive applications without advanced mobile development skills.

  Warning

The RemoteXY application is free, but it is limited to a maximum of 5 elements. To add more elements, you will need to move to the Pro version, which is paid.

How it works

1. Generating the interface

With RemoteXY, you easily create a graphical user interface (GUI) by dragging and dropping elements such as buttons, sliders or gauges in its online builder. Once the interface is ready, preconfigured source code is generated, adapted to the microcontroller used (Arduino, ESP32 and so on).

2. Communication

RemoteXY connects the mobile application to the microcontroller over:

  • Bluetooth (classic or BLE),
  • Wi-Fi (ESP32, ESP8266),
  • or USB (wired connection).

3. Generated code

The generated code contains:

  • The handling of the interface elements.
  • The configuration of the chosen communication mode.
  • Tools to read/write data between the interface and the microcontroller.

4. Interaction

The microcontroller exchanges data with the mobile application:

  • It receives commands to carry out actions (e.g. turn on an LED, control a motor).
  • It sends information to update the interface (e.g. display a temperature).

    This makes it possible to develop interactive, scalable systems quickly.


Creating a simple interface

First, download the application to your phone, either from your mobile system’s app store or directly from the project web page.

Next, go to the interface editor page. You will find all the tools needed to design your interface there. To begin with, we will create a simple application to test a servo motor with a slider.

To do so, drag and drop a slider onto the interface and place it where you want. On your right, you will notice information about this slider, such as the variable name or graphical options.

Change the variable name to slider_servo_D7, then set the Center position option to Middle.

Under Configuration, at the top right, select Bluetooth. A window opens to guide you through the configuration of your project.

Under Board, select your board, here ESP32 based board. Under Module, choose Integrated Bluetooth.

Once these parameters are set, click Apply to confirm.

In the Settings tab, you can configure the connection parameters of your device. Here are the available options:

  • Device name in app: The name of your device as it will appear in the mobile application.
  • Access password: The access password. It is not mandatory, but strongly recommended to secure the connection.
  • Bluetooth name: The name of your device as seen when searching for Bluetooth devices.
  • Mode: The type of Bluetooth connection used, either classic or LE (Low Energy), depending on what your device supports.

Then click Get Source Code at the top right. A new page opens with code generated for your application. Click download code to download your code and open it in the Arduino IDE, or copy and paste your code into a new project.

Adapting the generated code

The code generated by RemoteXY already contains a lot of useful information. Before modifying it or adapting it to your needs, let us take the time to look at its structure and understand how it works, step by step.

Here is a detailed, line-by-line analysis to help you get to grips with each part of the code:

Detailed explanation of the code generated by RemoteXY

1. Enabling debug mode (optional)

//#define REMOTEXY__DEBUGLOG
  • This line, if uncommented, enables debug mode.
  • When debug mode is enabled, the program sends messages to the serial port at 115200 baud to help diagnose communication problems.

2. Selecting the connection mode and including the BLE libraries

#define REMOTEXY_MODE__ESP32CORE_BLE
#include <BLEDevice.h>
  • REMOTEXY_MODE__ESP32CORE_BLE: Configures RemoteXY to work in Bluetooth Low Energy (BLE) mode, which the ESP32 supports.
  • #include <BLEDevice.h>: Includes the library that handles BLE communication.

3. RemoteXY connection parameters

#define REMOTEXY_BLUETOOTH_NAME "Otto-BLE"
#define REMOTEXY_ACCESS_PASSWORD "**************"
  • REMOTEXY_BLUETOOTH_NAME: Sets the name of the device as it will appear in a Bluetooth search. Here, the device will be visible under the name “Otto-BLE”.
  • REMOTEXY_ACCESS_PASSWORD: Sets a password to secure access. This field is strongly recommended to avoid unauthorised connections.

4. RemoteXY interface configuration

#include <RemoteXY.h>
#pragma pack(push, 1)
uint8_t RemoteXY_CONF[] =   // 42 bytes
  { 255,1,0,0,0,35,0,19,0,0,0,79,116,116,111,45,71,114,111,117,
  112,101,32,48,50,0,31,1,106,200,1,1,1,0,4,45,37,13,100,32,
  2,26 };
#pragma pack(pop)
  • RemoteXY_CONF[]: An automatically generated configuration that defines the layout and properties of the elements of the graphical user interface (GUI).
    • Here, the configuration takes up 42 bytes.
    • It includes the details of the slider (position, type, value range and so on).
  • #pragma pack(push, 1): Ensures the data is aligned in memory in a way that optimises communication between the mobile device and the microcontroller.

5. RemoteXY data structure

struct {
    // input variables
  int8_t slider_servo_D7; // from -100 to 100

    // other variable
  uint8_t connect_flag;  // =1 if wire connected, else =0

} RemoteXY;
  • struct RemoteXY: A structure holding the variables tied to the interface elements:
    • slider_servo_D7: The variable for the position of the slider. It ranges from -100 to 100, which can be used to control a servo motor.
    • connect_flag: Gives the state of the Bluetooth connection:
      • 1: The device is connected.
      • 0: No device is connected.

6. The setup() function

void setup() 
{
  RemoteXY_Init (); 
  // TODO you setup code
}
  • RemoteXY_Init(): Initialises Bluetooth communication and sets up the GUI elements defined in RemoteXY_CONF[].
  • You can add extra configuration lines here to initialise other peripherals (such as a servo motor).

7. The loop() function

void loop() 
{ 
  RemoteXY_Handler ();
  // TODO you loop code
  // use the RemoteXY structure for data transfer
  // do not call delay(), use instead RemoteXY_delay() 
}
  • RemoteXY_Handler():
    • This function processes the data exchanged between the microcontroller and the mobile application.
    • It updates the values of the variables of the RemoteXY structure according to what the user does.
  • TODO comments: These sections are where you add your own instructions to work with the variables (for example, moving a servo motor according to the position of the slider).

Important: The classic delay() function is not compatible with RemoteXY, because it blocks operation. Use RemoteXY_delay() instead to handle delays.


Summary of how it works

  1. Configuration: The code initialises Bluetooth communication with the name and password defined.
  2. Graphical interface: A slider is configured to send values from -100 to 100.
  3. Data exchange:
    • The slider values are updated in the structure RemoteXY.slider_servo_D7.
    • You can use this variable to control a servo motor connected to pin D7.
  4. Customisation: The program is ready for features to be added in the setup() and loop() sections.

In general, if you modify the interface, you do not need to redo the whole code. Only the part related to the configuration of the graphical user interface (GUI) has to be updated to reflect the changes made.

// RemoteXY GUI configuration  
#pragma pack(push, 1)  
uint8_t RemoteXY_CONF[] =   // 42 bytes
  { 255,1,0,0,0,35,0,19,0,0,0,79,116,116,111,45,71,114,111,117,
  112,101,32,48,50,0,31,1,106,200,1,1,1,0,4,45,37,13,100,32,
  2,26 };
// this structure defines all the variables and events of your control interface 
struct {
    // input variables
  int8_t slider_servo_D7; // from -100 to 100
    // other variable
  uint8_t connect_flag;  // =1 if wire connected, else =0
} RemoteXY;   
#pragma pack(pop)

Modifying the code

To add control of a servo motor connected to pin D7 of an ESP32, using the value of the slider generated by RemoteXY, here are the lines to add or change in the code:


1. Include the Servo library

Add the ESP32Servo.h library at the top of the code to allow control of the servo motor.

#include <ESP32Servo.h>

2. Declare a Servo object

Declare an object to represent the servo motor and a constant for pin D7.

Servo servoD7; // Creates a Servo object
const int servoPinD7 = D7; // Defines pin D7

3. Initialise the servo motor in setup()

Add the instruction that attaches the servo motor to pin D7 in the setup() function.

void setup() 
{
  RemoteXY_Init();
  servoD7.attach(servoPinD7); // Attaches the servo motor to pin D7
  servoD7.write(90); // Moves the servo to the middle (90°) at start-up
}

4. Drive the servo motor in loop()

Add code to the loop() function to read the slider value and use it to control the servo motor. Convert the slider value (from -100 to 100) into an angle (from 0° to 180°).

void loop() 
{ 
  RemoteXY_Handler();
  // Convert the slider value (-100 to 100) into an angle (0° to 180°)
  int angle = map(RemoteXY.slider_servo_D7, -100, 100, 0, 180);
  // Drive the servo motor with the matching angle
  servoD7.write(angle);
}

5. Upload the program

Once the program is modified, you can upload the code to the board and start the application. Do not forget to install the RemoteXY library in the Arduino IDE.


Connecting with the application

On your phone, open the RemoteXY application. Tap + - Add new device, then select Bluetooth. Choose the Bluetooth technology that matches the one configured earlier in the editor (classic or BLE). Your device should appear in the list of Bluetooth connections. Tap its name to connect, then enter the password if needed.

Once connected, your application should appear on your phone. Try moving the slider: the servo motor should respond by following the movements of the slider, adjusting its position accordingly.


Receiving information

In the previous chapters, we saw how to get the distance from the ultrasonic sensor. Here we will adapt the interface to display this distance on your phone.

Add a Value element and name it distance_sensor.

Generate the code and copy only the parts concerned by the interface changes.

Add the lines of code needed to get the distance measured by the sensor. Make sure you replace delay() calls with RemoteXY_delay() where needed. Avoid using the serial link in this case. We will use the variable RemoteXY.distance_sensor.

Restart the application. You should see the distance measured by your sensor displayed below.


  To do
  • Create a program and an application to control the Otto
  • Adapt the Otto to the rules of the various competitions
Need help?