Notifications
Clear all

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


Alex UK
(@alex-uk)
Active Member
Joined: 4 weeks ago
Posts: 8
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:

7C06

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("7C06"); //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)
Reputable Member
Joined: 3 months ago
Posts: 368
 

@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.


ReplyQuote
Alex UK
(@alex-uk)
Active Member
Joined: 4 weeks ago
Posts: 8
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)
Reputable Member
Joined: 3 months ago
Posts: 368
 

@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.


ReplyQuote
Alex UK
(@alex-uk)
Active Member
Joined: 4 weeks ago
Posts: 8
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("7C02");
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)
Reputable Member
Joined: 3 months ago
Posts: 368
 

@alex-uk 

In the example at the URL you specified is the line

Ps3.begin("0106"); 

where "0106" 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.


ReplyQuote
Alex UK
(@alex-uk)
Active Member
Joined: 4 weeks ago
Posts: 8
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 "xxxx" 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
(@alex-uk)
Active Member
Joined: 4 weeks ago
Posts: 8
Topic starter  

It did it again! Please ignore "XXXX" format

Alex


ReplyQuote
Will
 Will
(@will)
Reputable Member
Joined: 3 months ago
Posts: 368
 

@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.


ReplyQuote
Alex UK
(@alex-uk)
Active Member
Joined: 4 weeks ago
Posts: 8
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