This project is similar to my previous work where I have used a joystick to control a PC cursor. The key difference is that I have created a smartphone application that contains 2 virtual joystick to move the cursor as well as scroll the screen and also does left and right click just like a regular trackpad.Working
The project involves a smartphone application that sends the joystick's x and y axis data, scroll status, left and right click status using bluetooth to the Arduino Uno connected to the HC-05 bluetooth module. These data upon reception to the Arduino is manipulated to make changes in the current cursor's position to obtain a new position. The resulting data along with scroll and button status is then printed as the output that is recognized to be read by the Python sketch. The Python sketch is made to execute mouse actions using the mouse module.
The smartphone application is created using the MIT-App Inventor. Creating the app is simple as you just need to add the desired blocks to build your required application.I have referred to the Tabletop robotics tutorial on making them. The main screen of the application is as follows-
Before sending the main information to the HC-05 module, the application first sends a one byte number(255) to denote the start of information. The sequence of data transfer is as follows-
1. Send '255' to denote start
2. Send 1 byte joystick x-axis value
3. Send 1 byte joystick y-axis value
4. Send status of left click, right click button and scroll status(1 byte).
The data from the application is sent every 20 milliseconds to the Arduino UNO.Arduino's Side
The data bytes from the Application is received by the Arduino with the help of HC-05 Bluetooth module. The Arduino contains the current coordinates of the cursor where The x coordinates range form 0 to 1279 and the y coordinates range from 0 to 799. I have obtained these extreme coordinates form the python function
mouse.get_position() that returns the coordinates when the cursor is moved (not used in the main sketch).
Based on the data received upon moving the joystick, the current cursor's position (x and y coordinates) is then added/subtracted with the data received by the application to move the cursor to the new desired coordinate. The final data is then printed on the Serial monitor in sequence given below.
The following data sequence is finally read by the python program to execute it. For this, we will need to download additional modules namely mouse and pyserial in the steps given below.Python Programming
The user must have python 3 installed on their laptop/computer. It can be downloaded from the here.
After installation, Copy the path of the python file location.
The following steps are to be performed on the command prompt. Open command prompt and enter the following-
cd <paste the path of the python file>
py –m pip install –-upgrade pip
py –m pip install mouse
py -m pip install pyserial
The mouse module is used to perform mouse actions and pyserial module is used to send/receive data from the arduino. I had already installed the necessary modules, so I got this
Install the Bluetooth Mouse Control app on your smartphone device.
Upload the Arduino sketch to your Arduino UNO and follow the circuit as given in the schematic.
Make sure the HC-05 Bluetooth module is already paired with your smartphone device, only then you can select it from the list of paired devices.
1. Copy paste the python code in a notepad file. Change the COM port to your Arduino UNO's COM port and save it as '.py'.
2. Open the python IDLE and open the notepad file form it.
3. Run the Sketch.
You will then be directed back to screen in fig 2.2.
Open the smartphone application and connect to the bluetooth module and you will notice the cursor movement upon changing the direction of the joystick.