Skip to main content

Remote Flying Fish Project Part 5: Motor Testing with Remote XY

In this chapter, we will build a simple mobile application to control the speed and rotation of motors.

To simplify the overall design and reduce the difficulty, RemoteXY is selected as the medium APP creator.

2019-08-11_%284%29_d84724ca3e555563765ebee169493327930532b0.png

Setup

To begin with, browse http://remotexy.com/en/editor/ and you will see an editor view displaying the layout of the mobile app.

2019-08-11_%288%29_92e7f1bb055c6184da488231ecd0a16952244bba.png

Firstly, click the 'Bluetooth' button on the right-hand side under 'Configuration', it can select the module of the Arduino board and Bluetooth. The following interface will be shown.

2019-08-11_%2810%29_8ca53931db337d27d0947546078cc9e9560875a5.png

Make sure that Bluetooth module HM-10 and Arduino board NANO are selected in the configuration panel.

2019-08-11_%2812%29_a3619053fe80c77ce563a33e090d9c6f2931c03b.png

Secondly, set the connection interface to Hardware Serial. Serial port and data transferring speed are left auto-configured.

2019-08-11_%2814%29_c5e65862cfc06c0926b6d121ce435256ca69ea09.png

After that, drag two Button and one Slider from the tool panel into the app area, you can adjust to the size at free will.

2019-08-16_%2812%29_3d51b21f250cf2cf741b5a0e0074727920d88768.png

Then, click the Buttons and select the pin number to Pin 7

2019-08-16_%2814%29_c65a5fb87cf24561aa8b6f1644f8298924cf1035.png

You can also add up to 5 elements in total for other control purposes. For elements more than 5, you will need to pay for the APP or get a limitation of use time of 30 seconds.

Run-Time

By then, click the green button Get source code to prepare the Arduino code for the controller programme. Log in is required before proceeding to the result page as shown below.

2019-08-11_%2820%29_e89102dbfce4560ebcef6b548ad75dac08d15752.png

Do not forget to download and install the latest library from http://remotexy.com/en/library/, otherwise, there will be an error during compiling.

Download the Arduino code by clicking 'Download code'. A zip file will be downloaded. Zip it and open the '.ino' file.

2019-08-16_%282%29_57692535a561189484f04b452b172d7a8366d090.png2019-08-16_%284%29_d1487fdd735678670f585e0e7b769b277938ca49.png

A simple Arduino code will be generated. However, it needs some changes in order to control the speed and the rotation of the motor. Please add the BOLD code in the Arduino program. Make sure you remove the connection of 'TX1' and 'RX1' Pins between the Arduino board and Bluetooth before uploading the code. Otherwise, an error will be shown.

/////////////////////////////////////////
// RemoteXY include library //
//////////////////////////////////////////////

// RemoteXY select connection mode and include library
#define REMOTEXY_MODE__HARDSERIAL

#include <RemoteXY.h>

// RemoteXY connection settings
#define REMOTEXY_SERIAL Serial
#define REMOTEXY_SERIAL_SPEED 9600


// RemoteXY configurate
#pragma pack(push, 1)
uint8_t RemoteXY_CONF[] =
{ 255,3,0,0,0,57,0,8,13,0,
4,128,20,50,64,9,2,26,129,0,
13,40,18,6,17,83,112,101,101,100,
0,1,0,16,16,12,12,2,31,67,
108,111,99,107,0,1,0,61,17,12,
12,2,31,65,110,116,105,45,99,108,
111,99,107,0 };

// this structure defines all the variables of your control interface
struct {

// input variable
int8_t slider_1; // =0..100 slider position
uint8_t button_1; // =1 if button pressed, else =0
uint8_t button_2; // =1 if button pressed, else =0

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

} RemoteXY;
#pragma pack(pop)

/////////////////////////////////////////////
// END RemoteXY include //
/////////////////////////////////////////////

#define PIN_BUTTON_1 7
#define PIN_BUTTON_2 7
#define PIN_SLIDER_1 9


void setup()
{
RemoteXY_Init ();

pinMode (PIN_BUTTON_1, OUTPUT);
pinMode (PIN_BUTTON_2, OUTPUT);
pinMode (PIN_SLIDER_1, OUTPUT);
// TODO you setup code

}

void loop()
{
RemoteXY_Handler ();

//digitalWrite(PIN_BUTTON_1, (RemoteXY.button_1==0)?LOW:HIGH);
//digitalWrite(PIN_BUTTON_2, (RemoteXY.button_2==0)?LOW:HIGH);

analogWrite(PIN_SLIDER_1, RemoteXY.slider_1*2.55);

if(RemoteXY.button_1==1){

digitalWrite(PIN_BUTTON_1, HIGH);

}

if(RemoteXY.button_2==1){

digitalWrite(PIN_BUTTON_2, LOW);

}


// TODO you loop code
// use the RemoteXY structure for data transfer


}

According to the code, we selected Pin 7 as the direction of the motor, and Pin 9 as the PWM/speed of the motor. The minimum and maximum value of PWM is 0 to 255, so we multiply the 'RemoteXY.slider_1' by 2.55. If the buttons are pressed, it will change the voltage into HIGH or LOW to change the direction.

Testing by Mobile

Download an application from APP Store or Play Store.

remotexy_download_b1496d8bcd07e5c79266ed3dad2eee5dbe3e11f5.jpg

Open the Application on your mobile or devices.

12312_554821b780ae1cb862b060697a191829c6789aa5.png

Press the '+' on the right upper corner to add a new device connection.

4124_dbb397665d41ccf1462a572103ee5ef6e5d5a3e5.pngSelect 'Bluetooth LE' and select your Bluetooth device.

1251_5916e44bf896bee255a1fc39abf01cb0de302360.png

It will automatically change into the interface you designed in RemoteXY. Now you can test the motor.

1616_24570045acfcf49dc7717d0014a06d60b49e3120.png

Demo

giphy_df9556118974b279b0ae273a26d1ba0497e89a85.gif

Now we can move on to the next chapter and start to design our own PCB :)

You can download the pdf version of this chapter in the Download section below.

 Parts in this series

lokit has not written a bio yet…
DesignSpark Electrical Logolinkedin