ESP32 Bluetooth BLE Remote Control - 8 Steps - Instructables
ESP32 Bluetooth BLE Remote Control - 8 Steps - Instructables
Download Favorite
(https://content
auto=webp&frame=1&fit=bounds&md=4ac1e1b9290c7239af1b358dd570f944)
instructables com/FR0/DBDL/JG2J0TW4/FR0DBDLJG2J0TW4 png?
(https://content
auto=webp&frame=1&fit=bounds&md=912d894cb438e97d2ed71db15a68532d)
instructables com/FLZ/96HD/JG2J0TXQ/FLZ96HDJG2J0TXQ png?
(https://content
auto=webp&frame=1&fit=bounds&md=f545562be9073643e37ec984c5d6155a)
instructables com/FS2/WO26/JG2J0TX3/FS2WO26JG2J0TX3 png? (https://content
auto=webp&frame=1&fit=bounds&md=a5e60aeb4206d4623c477aa386c37add)
instructables com/FJJ/FM5H/JG2J0TYE/FJJFM5HJG2J0TYE png?
(/member/BigjBehr/)
By BigjBehr
(/member/BigjBehr/) More by
the author:
Follow
About: I am a retired Embedded Systems Engineer. I enjoy playing around with microcontrollers, SBCs, 3D printing and
woodworking. More About BigjBehr » (/member/BigjBehr/)
The joystick that I used for this project is a Spektrum VR Control Bluetooth Remote
Controller. It is being marketed as working with Android and IOS tablets as a
joystick/mouse for use with VR headsets.
The VR Control Bluetooth Remote Controller has a single joystick with X and Y axis, two
trigger buttons in front and six buttons on the handle. Two of the buttons are for power
on/off and mode control. The other four buttons can be used for whatever you want. This
project is a skeleton or framework that handles all of the Bluetooth interfacing and decoding
of the buttons & joystick. All you have to do is add function calls to handle what you want
the buttons and joystick to do. You do not need to know anything about Bluetooth to use
this framework.
There are numerous web sites with detailed instructions for installing the Arduino IDE and
the ESP32 addon. I am not going to attempt to repeat that information here. Google it and
follow the directions.
The framework is an adaptation of a BLE client example published by IoT Sharing. You can
find it here (http://www.iotsharing.com/2017/07/how-to-use-arduino-esp32-ble-as-gatt-
client.html). You can study this code to get an idea of how BLE works. Expressif has a
complete example for a GATT BLE client and explains the operation in detail (not written
for Arduino IDE). You can get it here (https://github.com/espressif/esp-
idf/blob/9a98535/examples/bluetooth/gatt_client/tutorial/Gatt_Client_Example_Walkthrough.
md).
This is not a BLE tutorial. I will not be explaining how the code works in detail. I will use
BLE terminology to describe some of the features of the joystick. The part of the code that
you need to modify for your project will be explained in detail to help you to modify it. The
scope is limited to keep this Instructable short and focused on using the joystick.
The framework verifies that the server it finds has the BLE HID service and will then enable
Notifications on the three Report Characteristics that provide joystick and button state
information. Then, when a button is pressed or released or the joystick is moved, the
ESP32 receives a packet of data telling it what the new joystick position is and/or the state
of some buttons.
Add Tip Ask Question Comment Download
The end result is that the ESP32 will continue to scan for the joystick until it finds it. Once
the connection is made, if it is then lost, the ESP32 will reset itself and start scanning over
again. The ESP32 is reset because there are no ESP32 SDK functions to reset the
Bluetooth stack to restart scanning.
A FreeRTOS task is created to handle the data received by the notifications. One task for
the joystick and trigger buttons, one task for the A & B buttons and one task for the C & D
buttons. Each of these tasks has clearly marked areas where you should your add code to
do what you want with the event. Look for the "//===== add your code here ====="
comment in the body of the task and add your code after it. Each task has a comment
indicating what it is used for and uses a Serial.println() to print a message about the event
that occurred.
//===== if the task requires any one time initialization, put it here =====
while(true)
{
// give up the CPU, wait for new data
vTaskSuspend(NULL);
Holding the lower trigger button will prevent the server from detecting that the upper trigger
button has been pressed. Holding the upper trigger button and pressing the lower trigger
button results in the server sending a notification message that the lower trigger button is
pressed (the upper trigger button will be zero!). Releasing the lower trigger button will
cause the server to send a notification that the upper trigger button is pressed and the
lower trigger is released.
In other words, the lower trigger button is dominant over the upper trigger button and will
override it when both are pressed. You have to determine how to handle the case of both
buttons being pressed.
Step 8: Conclusion
The operation of the buttons is in my opinion a little wonky. The Framework provides for
places to put your code to act on when a button is pressed. If you also need to detect
button releases, that is left for you to figure out how to do.
It is entirely up to you to determine what you want each button to do and what moving the
joystick should do. How you handle the differences in the trigger, A & B and the C & D
buttons is up to you.
Look in the code for the; taskJoyStick(), taskButtonAB(), taskButtonCD() functions and add
your code after the "//===== add your code here =====" comment.
You will need up to four functions to handle the joystick (forward, backward, right & left)
and up to six functions to handle the various buttons. Implement them all or just what you
need. The choice is yours.
If you use this framework. I would love a shout out about what you used it for and if you
found it easy to use.
If you have questions about how it works or need help getting it to work, contact me.
Enjoy.
Add Tip Ask Question Comment Download
Participated in the
Microcontroller Contest View Contest
(/contest/microcontroller2018/)
a_abarghuee Ts´zul
(/member/a_abarghuee/) made (/member/Ts%25C2%25B4zul/)
it! made it!
I Made It!
Recommendations
(/contest/clocks23/) (/contest/cold/)
(/contest/baking2023/)
47 Comments
Reply Upvote
(/member/a_abarghuee/) a_abarghuee (/member/a_abarghuee/) 4 weeks ago
Hi BigJBehr,
When I use the code to connect to my joystick, I can find the device and connect to it but after connection,
receive some data and then get this error "Guru Meditation Error: Core 0 panic'ed (Unhandled debug
exception)" or this "lld_pdu_get_tx_flush_nb HCI packet count mismatch (0, 1)".
A few times I could connect to my joystick and receive data for a long time but generally, it does not work
properly and disconnects frequently and has ESP32 to reboot.
Do you know if the problem is with the ESP or the joystick?
Reply Upvote
(/member/ManojB14/) ManojB14 (/member/ManojB14/) 2 months ago
Boss, I have not read all you have written, but the link that you have provided with the code, has saved me
from giving myself the title of "loser". I almost lost it looking for help and I stumbled upon your article just
before trying to put myself to sleep. The next morning, I made it a point to try your suggestion and bang,
with a little more research, I could get the VR remote that I have, working.... from a point it was not getting
detected by standard examples to finding out why the application crashes, was a journey of a couple of
days. Many many thanks, I get my project underway now.... You are awesome (coming from the heart).
Thank you. I am not sure if you're still coding and looking at these messages, but if you do read this,
please rest assured you have one more fan in me.
2 replies
Answer Upvote
(/member/smallwire/) smallwire (/member/smallwire/) Question 3 years ago
Hi BigjBehr!
I need some help please. Scanning for devices works, as I can find things like my Fitbit or the BB-8, but I
cannot find the remote.
It looks almost like yours, but it's a different brand.
Best regards!
(https://content.instructables.com/FE3/BIW3/JU31TVNO/FE3BIW3JU31TVNO.jpg?
auto=webp&fit=bounds&frame=1&height=1024&width=1024)
5 answers
Answer Upvote
(/member/f_robo/) f_robo (/member/f_robo/) Question 1 year ago on Step 8
Hi BigjBehr,
I am late but hopefully not too late:
I got a VR Control which calls VR-PARK from CN. When I try explore it in the nRF Connect App it never
appears. But it is visible in the HC05 Terminal of my Android Phone. So my ESP32 never found VR-PARK
by its name or even by its MAC. My question now is: How can I find out, where to get a VR BOX which is
capable of BLE?
Reply Upvote
(/member/juniorradu/) juniorradu (/member/juniorradu/) 1 year ago
Hi BigjBehr! Thank you for this tutorial! I am looking for a way to use a commercial BLE remote control, for
example e presentation pointer or universal TV remote to control my ESP32 via Bluetooth BLE. Have you
ever tried any of this combinations? Where can I find information about the HID profile? Like default
commands codes.
I would prefere to find a customizable or programmable remote control with 7-8 buttons over BLE, but I've
not been able to find one in the market.
Thank you in advance.
3 replies
Reply Upvote
(/member/Amishai/) Amishai (/member/Amishai/) 1 year ago
Hi BigjBehr,
Thank you very much for this tutorial. My project includes strong torch light directed and controlled by
ESP32 and it seems that I've found at last the right and full information to go on with this plane of mine. My
VR Controller is almost like yours ("RoHS" brand) and give the name "VR-PARK" while trying to connect it
to my Mac computer (with BT)
I've changed the name in the Arduino code accordingly but for some reason the "serial monitor" showed
blank (as shown in the attached display snapped picture) and maintained indicating the last two lines on
and on.
Could you help me with this problem?
Thanks a lot
Amit
(https://content.instructables.com/FLY/2DFA/KMNGHO2N/FLY2DFAKMNGHO2N.png?
auto=webp&fit=bounds&frame=1&width=1024)
4 replies
Cooking
(/cooking/)
Terms of Service (http://usa.autodesk.com/adsk/servlet/item? Privacy Statement (http://usa.autodesk.com/adsk/servlet/item? Privacy settings | Legal Notices & Trademarks (http://usa.autodesk.com/legal-
siteID=123112&id=21959721) siteID=123112&id=21292079) Do not sell or share my personal information (https://www.autodesk.com/company/legal-notices-trademarks/ccpa-do- notices-trademarks/)
| | not-sell)
|
(http://www.autodesk.com)