Notifications
Clear all

[Solved] Cannot get ESP32 NodeMCU to Bluetooth connect to PS3 Controller: Please help!

12 Posts
2 Users
0 Likes
4,092 Views
(@alex-uk)
Member
Joined: 3 years ago
Posts: 14
Topic starter  

Hi everyone.

This is my first time asking for help on here, just joined and I'm new to electronics. In at the deep end here, so will put in as much detail on the issue and what I've tried so far as possible. Very grateful for any help...

I am trying to get my ESP32 (specifically,  ESP32S Node MCU dev kit v1) to pair/connect with old Playstation3 (PS3) game console controller (I have 2 of these, specifically official Sony PS3 sixaxis dual shock), using the BT classic capability. From herein, I'll use the terms PS3controller and ESP32 to avoid any confusion over the term 'controller'.

This is so that I can then use it as a controller for robot car projects etc. In theory, this should be feasible with ESP32 and give inputs from all buttons/joysticks on the controller; here are some links to videos and tutorials (note there's some bad info in first one which will detail below), that come with all the code and instructions, and link to the software mentioned:

Page and video called 'PS3 Controller + esp32 + robotic arm = awesome! (Building a wireless esp32 powered robotic arm)' at these links:

https://www.anyonecanbuildrobots.com/post/esp32-ps3-controller-robotic-arm-awesome

Similar links showing same thing:

https://github.com/jvpernis/esp32-ps3

https://techtutorialsx.com/2020/02/16/esp32-connecting-a-ps3-controller/

https://www.dfrobot.com/blog-1513.html

I have tried sketches from all these sites, and also the simplest example, called 'Ps3Connect' that comes with the PS3Controller.h library (see below).

I'm working in the Arduino IDE as that's all I know how to use right now (conscious that ESP32 IDF software is also out there, perhaps might need to be part of solution...?). 

But it doesn't work! Can't connect the PS3 controllers to ESP...here's more detail and example code at the bottom:

Work to date:

I downloaded and successfully used the sixaxis pair tool software that reads/can rewrite the Bluetooth MAC address stored in the PS3controller, via plugging in USB micro B to PC (despite what it says in the robotic arm video, it seems that that is the address for the PS3 console itself which the PS3controller needs in order to connect/pair; this holds true in that if I change it, it won't pair to PS3 console, then it gets changed back (either in the software or by plugging PS3controller to console on USB to reset it) and works again). It would appear (unless I've got this wrong?) that we therefore need to give the PS3controller the ESP32's own BT MAC address using this rewrite software.

Accordingly, I discovered the ESP32's BT MAC address (one digit different from its wifi MAC address) using:

https://techtutorialsx.com/2018/03/09/esp32-arduino-getting-the-bluetooth-device-address/

This is the format it gives, and which I then rewrote into the PS3 controllers:

7C:9E:BD:47:94:06

Note : there's an interesting warning message that comes up in Serial Monitor when retrieving the MAC address. Line above the MAC says Failed to enable bluedroid. This might be relevant to the subsequent problem…

Note also that when inputting this to rewrite the MAC stored in PS3 controller, it 'corrects' any upper case letters into lower case (so when you check what's in there afterwards, it's 7c:9e... etc.). See below troubleshooting.

On the ESP32 side, I've downloaded the libraries and all the alternative codes from these sites into Arduino IDE.

Have also used the example sketch 'PS3Connect', that comes as part of the PS3 Controller library.

In theory, given PS3 controller now has the ESP's BT MAC written in, all I should need to do is write in the same matching MAC address (of the ESP, I presume, as that's what tutorials say and see above). Having written the BT MAC into the code and to the PS3 controller via the Sixaxis pairing tool, then successfully compiled and uploaded. Opening the Serial Monitor, when powered up/reset by the EN button, you see start up texts, ending in 'Ready'.

I then push the connect button on PS3 (tried momentary, holding down etc), the '1,2,3,4' LEDS on the PS3 controller fast flash as it tries to pair…but nothing then happens. LEDS keep flashing for a good minute, even if I hit reset on the ESP32, it does not pair (in the videos, you'll see the pairing is very fast). No error messages at this stage.

I have tried this with both PS3 Controllers I have and on different ESP32 (NodeMCU 32s)…many, many times!

Troubleshooting I've tried

To see if Bluetooth (classic) on the ESP32 worked at all, I've successfully ran the example sketches from ESP board manager/libraries for BT serial to serial connection with my Android phone (Serial Bluetooth Terminal App), exchanging messages from phone to ESP32. 

I've tried matching the case of MAC address put into the sketch to lower case only letters, in case (see bit above on pairing software) the PS3 Controller is only accepting it in this format.

And I know both PS3 Controllers can still pair with the PS3 Console when I reset the original BT MAC they held.

In summary, I can't tell whether:

-There's something wrong/incompatible with the ESP32 type  I have(I have tried this on all four identical Node MCU boards)

- It's because I'm not using the ESP32 IDF software

- There's some incompatibility with BT standards, or...

-I've just messed up somewhere along the line! (

It's frustrating because it looks like it should be so simple, on the face of it I have the same hardware (?) as in demos and I'm using code from those demos, literally only changing the MAC address.

I should add, I am a complete beginner, 2 weeks ago I was reading Getting Started with Arduino, so please...imagine you were explaining it to a slightly thick child and you'll have about my level 😉

I'd be extremely grateful for any help; I don't mind if the answer is 'it won't work with Node MCU', or even if I somehow have the wrong type of PS3 controller, I will happily go and get the right ones! I just want some PS3 or similar controller to BT connect with some ESP32 dev board!

Thanks to everyone if you've stuck with it and read this far, I knew it would need detail! 

Kind regards,

Alex

 

Code: Example 'Ps3Connect'

#include <Ps3Controller.h>

void setup()

{

    Serial.begin(115200);

    Ps3.begin("7C:9E:BD:47:94:06"); //this is the only part I have altered, putting in the BT MAC of my ESP32.

    Serial.println("Ready.");

}

void loop()

{

  if (Ps3.isConnected()){

    Serial.println("Connected!");

  }

  delay(3000);

}


   
Quote
Will
 Will
(@will)
Member
Joined: 3 years ago
Posts: 2507
 

@alex-uk

I don't know much about ESP32 and nothing about bluetooth, but in the sample code you don't ever seem to create the PS3Controller object PS3.

Anything seems possible when you don't know what you're talking about.


   
ReplyQuote
(@alex-uk)
Member
Joined: 3 years ago
Posts: 14
Topic starter  

@will Hi Will, thanks so much for your reply. I'll admit as a newcomer, I'm dimly aware of what an object is, but wouldn't know where to start in fixing/adding the correct code (whilst working on this project, I am trying to read up to educate myself, in parallel with a 'cut and paste' approach on other peoples' code that works. Any good tutorial suggestions on C programming that are beginner orientated would be appreciated).

Am I right in thinking that, as this code I've copied wholesale as a example sketch in the IDE, it must therefore work for some people and therefore I am perhaps missing some library, or other prerequisite in the IDE, which that 'PS3' is calling? (I do have the latest version Ps3Controller library installed, and have also tried regressing to previous versions of it, didn't work).

Do you know of any way to 'create the PS3Controller object PS3' (assuming that's not something it calls from the library?). 

I could also paste in here one of the alternative codes from the sites I posted links to, in case that makes an easier starting point.

Any suggestions (Will and anyone else) much welcomed, thanks all.

Regards

 

Alex


   
ReplyQuote
Will
 Will
(@will)
Member
Joined: 3 years ago
Posts: 2507
 

@alex-uk 

I Googled PS3Controller and it appears that the PS3 instance must be created byte library itself and then connected to the other device with the Ps3.begin() statement. Strange.

However, I thought that MAC is usually a 48 bit address, usually broken down into 6 hex byes values separated by colons. I don't know where your "7C06" came from, maybe you could check that part of the code next.

Anything seems possible when you don't know what you're talking about.


   
ReplyQuote
(@alex-uk)
Member
Joined: 3 years ago
Posts: 14
Topic starter  

Thanks Will. As to the MAC address 7C06, afraid that was just a typing error when I put the code into my post; what went into the sketch was a full MAC in the format you mentioned (I did just double check and try to run it again, wish that had been the problem!). Here's the code as copied from the sketch with the actual BT MAC address that I got from one of my ESP32s by running a Get BT MAC address sketch, and then also wrote onto the PS3 Controller using Sixaxis Pair Tool:

 

#include <Ps3Controller.h>

void setup()
{
Serial.begin(115200);
Ps3.begin("7C:9E:BD:48:BF:02");
Serial.println("Ready.");
}

void loop()
{
if (Ps3.isConnected()){
Serial.println("Connected!");
}

delay(3000);
}

 

The library is found at this link:

https://github.com/jvpernis/esp32-ps3

And I presume that's where Ps3.begin is...(defined? created? Sorry I don't know the correct term!). The rest of the code is known (and whether or not the if (Ps3.isConnected()){ works, if it paired I'd still see the PS3 Controller pairing LEDs stop flashing and one LED stay on).

Other than searching for zip libraries to download, I don't yet understand how to use GitHub, it may well be that the answer is in there somewhere, I just can't see it. The Readme talks about how the library reaches back into the 'IDF' (IoT Development Framework, seems to be the original software for ESP32), maybe something is not working here or I need some additional software/library...?

Does that get us any closer to figuring this out? Thank you for taking the time, I really appreciate it.

Alex

 


   
ReplyQuote
Will
 Will
(@will)
Member
Joined: 3 years ago
Posts: 2507
 

@alex-uk 

In the example at the URL you specified is the line

Ps3.begin("01:02:03:04:05:06"); 

where "01:02:03:04:05:06" is the MAC. Your code uses "7C02".

That's why I'm suggesting that you don't have a valid MAC to begin the PS3 controller. I'd start by examining whatever you did to get that address and by trying another way (or two) to determine the MAC address of whatever you're trying to link in.

Other than that, I have no ideas for you, sorry.

Anything seems possible when you don't know what you're talking about.


   
ReplyQuote
(@alex-uk)
Member
Joined: 3 years ago
Posts: 14
Topic starter  

I think there's something odd going on with the DBW forum and the way it format the code I'm putting into the posts...the original has the full "xx:xx:xx:xx:xx:xx" format, then when it appears in the post both my first code and the one I just did get cut off short to just the first two digits and the last (that's really odd, must be a security feature!), hence the 7C02 (it is in fact

image

. The same is happening for the the 'demo' MAC address used on github. 

To get around this, I've done a screenshot of both, see attachments. 

GitHubBTMACexample
SketchUsedPs3Connect

Will have a go again as you suggested of seeing if there's a different MAC (though it seems to be the expected wifi MAC +2 on the last digits), I have tried changing the MAC as there is code for this out there but it resets when powered off (and therefore has to be done is all sketches used). This didn't work last time so not optimistic.

If it just isn't a valid MAC, then that effectively makes my NodeMCUs incompatible, so I may need to buy a different dev board. Any recommendations?

Thanks for this, owe you a beer if you're ever in the Bristol area of the UK!

Alex

 

 


   
ReplyQuote
(@alex-uk)
Member
Joined: 3 years ago
Posts: 14
Topic starter  

It did it again! Please ignore "XXXX" format

Alex


   
ReplyQuote
Will
 Will
(@will)
Member
Joined: 3 years ago
Posts: 2507
 

@alex-uk 

Your code looks golden, I have no more ideas - sorry.

I hope somebody else here can move you forward on this.

 

I notice now that it did the same truncation on my reply. Perhaps it's something to do with the HTML representation.

Anything seems possible when you don't know what you're talking about.


   
ReplyQuote
(@alex-uk)
Member
Joined: 3 years ago
Posts: 14
Topic starter  

No problem, thanks for having a look Will. It must be some compatibility issue with the hardware, will try different controller type or ESP32 dev board. If/when I crack it I'll let you know and post it on here. 

Anyone else out there any experience with pairing this kind of hardware?

Thanks

Alex


   
ReplyQuote
(@alex-uk)
Member
Joined: 3 years ago
Posts: 14
Topic starter  

@will Hi Will and all. I thought you'd be interested to know, I've cracked the problem of connecting the Ps3 Controller over bluetooth to ESP32, and it works great. Many have struggled with this, Parvaiz Ahmad out in Pakistan found the solution for me. Hopefully many of you will find this interesting as I now have a massive selection of control options from the Ps3 controller (have got robot car handling beautifully using the analogue joystick) BUT do beware the 'old software version' element.

The MAC address conversation we were having was not the issue as it turns out. Thanks to everyone for their help, especially Will and of course Parvaiz.

Details below...(copied from my response on a youtube forum):

"I tried for ages to get this to work too, compiling but not connecting. Eventually someone figured out the issue; the Ps3 connection worked with old version 1.0.2 of the ESP32 board manager (in the arduino IDE, just go to board manager and search). Current version is 1.0.6 and it for whatever reason doesn't work anymore. You need to uninstall 1.0.6, then install 1.0.2. You also need to remove Ps3 controller library current version (I had 1.0.0) and install older 1.0.0.

If those two don't work, try completely removing the IDE and then install 1.8.15 (caveat, not sure if necessary but works for me). If so you have to remove the hidden cache files for the arduino app beforre install step, here's a link to how.

https://support.arduino.cc/hc/en-us/articles/360021325733-How-to-do-a-complete-uninstall-of-the-Arduino-IDE

Final couple notes...I don't know whether the cache removal is also needed to successfully revert to older ESP board manager, or just the ICE, I did both simultaneously to solve issue for me. Fiddle around with it? Thanks to Parvaiz Ahmad for finding a solution, he has made a YouTube video about it:

Also, if you're planning to use this code now merged with other code, you may have an issue whereby those other parts need up to date manager but mutually exclusive with Ps3 control needs."

 

Alex, UK


   
ReplyQuote
Will
 Will
(@will)
Member
Joined: 3 years ago
Posts: 2507
 

@alex-uk 

Excellent, I'm glad you finally got it working !!

Anything seems possible when you don't know what you're talking about.


   
ReplyQuote