PS4 Dual Shock connected to Teensy 4.0

PickyBiker

Well-known member
I'm working on a new project that needs lots of control switches and joysticks. I have read lots of articles about connecting a PS4 Bluetooth controller to the Teensy 4.0 but it looks like a work in progress, and I don't understand the HID stuff that is being discussed..

Is there currently a library for the Teensy that will support the PS4 controller using an HC-06 Bluetooth module or similar?

Thanks
 
@PickyBiker

While USBHost is a work in progress for several things the PS4 Bluetooth code works very well - used it for several things. This is a good example in the USBHost library examples folder: examples\Bluetooth\JoystickBT. The sketch is general and supports a few different ones but the section marked displayPS4Data shows how to access all the data associated with the PS4 controller (I use the dual shock).

As for a library that uses a hc-06 module - I am not aware of one.
 
Thank You!

Got the library and the JoystickBT example.

If the hc-06 BT module won't work with this, that what BT module should I try?

Think you have a bit of a misunderstanding. On the Teensy 4.0 there are 2 pins on the bottom side of the board marked D- and D+ on the pinout card. If you can use them in conjunction with a USB cable to connect a BT dongle.

On a T4.1 its much easier to use, all you would need to do is to solder a 5 pin header and use one of these: https://www.pjrc.com/store/cable_usb_host_t36.html.

I know there are a few breakout boards available that you give you access to those pins.

EDIT: Link to some breakouts: https://www.pjrc.com/breakout-board-for-teensy-4-0/
I would check this one out: https://www.tindie.com/products/loglow/teensy-40-breakout-revision-a/. Soldering connections for the sd card can be tricky but if you dont need that you can just not solder them on.
 
My Teensy 4.0 is on a socket on a PCB that connects it to a 3.5” TFT Display.
display.jpg

In my situation, it would be best to use one of these. I can easily solder wires to the D+ and D- and power pins on the Teensy 4.0 and the USB PCB.

USB PCB.jpg
Perhaps one of these would be good:
Dongle.jpg


Am I on the right track now?
 
Thank you mjs513! I was really confused about how to do this and you got me on the right track.

Much appreciated!
 
Almost there. Got a USB A and connected to the Teensy 4.0. Loaded the JoystickBT sketch, selected "BluetoothController bluet(myusb, true, "0000"); // Version does pairing to device" and the serial monitor shows:

USB Host Testing - Joystick Bluetooth
*** Device Bluet a5c:21e8 - connected ***
manufacturer: Broadcom Corp
product: BCM20702A0
Serial: 5CF3707F31BE
BDADDR: 5C:F3:70:7F:31:BE

I looked online for pairing a ps4 controller and what I found was:
"press and hold PS (Home?) and share at the same time". What I actually do is press home first to turn on the controller, and then I press and hold both buttons down. The PS4 dual shock controller light flashes for about 25 seconds or so and then turns off. Nothing changes on the Serial Monitor.

Thoughts?

UPDATE******************************************************************************************************
Just got a little further. This is what the screen now shows:
USB Host Testing - Joystick Bluetooth
CrashReport:
A problem occurred at (system time) 11:10:6
Code was executing from address 0x336E
CFSR: 82
(DACCVIOL) Data Access Violation
(MMARVALID) Accessed Address: 0x73656C9A
Temperature inside the chip was 51.50 °C
Startup CPU clock speed is 600MHz
Reboot was caused by auto reboot after fault or bad interrupt detected
*** Device Bluet a5c:21e8 - connected ***
manufacturer: Broadcom Corp
product: BCM20702A0
Serial: 5CF3707F31BE
BDADDR: 5C:F3:70:7F:31:BE


And now:
USB Host Testing - Joystick Bluetooth
BluetoothController::find_driver driver 20006238
*** Claimed ***
*** Device Bluet a5c:21e8 - connected ***
manufacturer: Broadcom Corp
product: BCM20702A0
Serial: 5CF3707F31BE
BDADDR: 5C:F3:70:7F:31:BE
*** BTHID Device Joystick1 0:0 - connected ***
product: Wireless Controller
Serial:


Moving the joysticks and pressing buttons does nothing on the Serial Monitor.

Does " *** Claimed ***" mean it is now paired???
 
Last edited:
Should be paired once you see joystick claimed but you should see additional info and when you move the joysticks you should see data streaming on the serial monitor.

To pair you need to just hold the press share and PS button. If you push the ps button first it thinks its already paired and does something else. Try share and ps button to pair only. After pairing then you only need to press the ps button
 
Okay, I just keep getting this crash report.
This is on a Teensy 4.0.

USB Host Testing - Joystick Bluetooth
CrashReport:
A problem occurred at (system time) 14:12:36
Code was executing from address 0x6DDE
CFSR: 82
(DACCVIOL) Data Access Violation
(MMARVALID) Accessed Address: 0xEDFFCDBC
Temperature inside the chip was 48.79 °C
Startup CPU clock speed is 600MHz
Reboot was caused by auto reboot after fault or bad interrupt detected
Breadcrumb #1 was 880284353 (0x347812C1)
Breadcrumb #2 was 854721041 (0x32F20211)
Breadcrumb #5 was 458279313 (0x1B50C991)
*** Device Bluet a5c:21e8 - connected ***
manufacturer: Broadcom Corp
product: BCM20702A0
Serial: 5CF3707F31BE
BDADDR: 5C:F3:70:7F:31:BE

The dongle I am using is several years old and only supports Bluetooth 4.0.
The one I ordered yesterday supports 5.3 and it should be here tomorrow. I'll try that and get back here.
 
THe crash report has me confused. Where you doing anything with the board before USBHost stuff that you had issues with?

The old dongles work, the BT5.x probably wont work or be recognized from what I remember.

Anyway on start up and pairing complete you should see on connection to the dongle:
Code:
USB Host Testing - Joystick Bluetooth
*** Device Bluet a5c:21e8 - connected ***
  manufacturer: Broadcom Corp
  product: BCM20702A0
  Serial: 001986000EE0
  BDADDR: 00:19:86:00:0E:E0

After pairing you will get this (hold share button down and press PS button):
Code:
JoystickController::claim_bluetooth - Class 2508 Wireless Controller
JoystickController::claim_bluetooth Interface
*** BTHID Device Joystick1 0:0 - connected ***
  product: Wireless Controller
Received Max Slot change Msg
*** First Joystick message 0:0 ***
  product: Wireless Controller
and it should start streaming data immediately:
Code:
LX: 128, LY: 128, RX: 130, RY: 129 
L-Trig: 0, R-Trig: 0
Buttons: 1100 Hat: 8
Battery Status: 80
Accel-g's: 0.020508, -0.980347, -0.025024
Gyro-deg/sec: 0.895247, 12.925122, 0.335717
Pitch/Roll: 88.537781, 320.664948

1100, 0, 0, 0
LX: 128, LY: 128, RX: 130, RY: 129 
L-Trig: 0, R-Trig: 0
Buttons: 1100 Hat: 8
Battery Status: 80
Accel-g's: 0.008057, -0.968018, -0.070679
Gyro-deg/sec: 1.398823, 9.903665, -0.279765
Pitch/Roll: 85.824028, 353.496948

Have you tried pairing after you got the dongle recognized message.
 
This is the display the Teensy is connect to:
https://learn.adafruit.com/adafruit-3-5-color-320x480-tft-touchscreen-breakout/overview

This Teensy has been working fine with a number of projects involving this display.

This is the way the Teensy 4.0 is wired up to the display:
View attachment 31611

As you can see here, only the display and USB Dongle are connected.
View attachment 31612

Here is a link to a video of what I am doing.
https://drive.google.com/file/d/114xzwZLIllikejopD_3liJ1-h2t-O_RZ/view?usp=drive_link
 
I unplugged the Teensy from the PCB and ran JoystickBT on just the teensy itself... Same result. So, it has nothing to do with the display.
 
I unplugged the Teensy from the PCB and ran JoystickBT on just the teensy itself... Same result. So, it has nothing to do with the display.

That is indeed strange. The only thing I can think of is to check your soldering to D+/D-. Assume you also have 5v and gnd on the T4 going to the to the dongle as well.

I can not get to the attachments getting an invalid link.
 
images of the top and bottom connections.

Bottom.jpg
Top.jpg

I'll wire up another Teensy 4.0 to eliminate the possibility of a damaged one.
 
Just a couple of things.
1. the gnd solder joint looks a bit flacky.
2. Looked at your pairing process. Looks right but unless you get a solid blue it means its still trying to pair.

a couple of things: do you have a link to your controller and you and try turning on debug in USBHost.h:
Code:
// Uncomment this line to see lots of debugging info!
//#define USBHOST_PRINT_DEBUG
its at about line 63 then post the results.

I think the issue is pairing not your wiring.

NOTE: some of the PS4 JT clones are not compatible - thats why I ask.
 
Last edited:
I uncommented the line, then saved the fie and recompiled. There is nothing new in the Serial Monitor., no debug info

// Uncomment this line to see lots of debugging info!
#define USBHOST_PRINT_DEBUG

// This can let you control where to send the debugging messages
//#define USBHDBGSerial Serial1
#ifndef USBHDBGSerial
#define USBHDBGSerial Serial
#endif



BTW: the file on my system is USBHost_t36.h, not USBHost.h. Could I have the wrong version?

This is the link to the PS4 controller: https://www.amazon.com/dp/B08L7T1VC7?psc=1&ref=ppx_yo2ov_dt_b_product_details
 
As @mjs513 mentioned not all clones are created equal.

Which BT adapter is that? Yes I see TP-Link, but not which one. We may not support all of the different ones out there. But the fact you said it only supports 4.0, my guess is that it should work.

Yes it is USBHost_t36.h - Which should give you information about the different things plugged in and the like.

In addition to this, the two source files bluetooth.cpp and BluetoothConnection.cpp have some additional defines:

Code:
//#define DEBUG_BT
//#define DEBUG_BT_VERBOSE

Likewise in Joystick.cpp
Code:
//#define DEBUG_JOYSTICK

I do have one of the Terrios controller (Blue), but I don't remember how well it worked.

Did you figure out where the fault was?
Code:
CrashReport:
A problem occurred at (system time) 14:12:36
Code was executing from address 0x6DDE
CFSR: 82
You can either use the addr2line exe, or most of the time I edit the list file generated and look at the address and see what is there.

Does the Joystick work at all if you simply plug it in to USB instead of using BT?
 
It's crashing when trying to print the serial number of the controller, it's definitely not a hardware/wiring issue.
 

Ok think I know the major issue. You are using the TERIOS Wireless Controller which we could never get working with USBHost so that is probably the major issue. Wired it should work. I forgot which ones work that I have - will have to pull them out of storage to check. The one I am currently using is a genuine PS4 controller from sony.

Edit: I just tested the Teiros again and yep does not connect. I also tried a Voyee Dual-Shock PS4 and that worked but dont see it available.

I can't remember if this one worked https://www.amazon.com/Controller【U...6e-9d40-32e7c76312ef&pd_rd_i=B07WG62V61&psc=1 and can not find it now
 
Last edited:
@PickyBiker - did you see my last post. The Teiros controller you are using does not work with USBHost. Do you have another controller you can try.
 
I do not have another PS4 controller.

If someone could share the type of controller they have that works and is still available, it would be much appreciated.
 
Again, just for completeness, I plugged the Terios controller directly into the port and it works just fine with the Joystick program.

Definitely some kind of BT incompatibility.
 
Back
Top