Fixing (DualShock 3) Bluetooth Lag
-
A brief update. I've had no luck in finding a fix, but I do have a better tool to measure actual controller latency with.
With the controller off, run the following command
$sudo btmon -SThen turn the controller on. You should see a lot of output about the initial connection between the controller and the pie. This differs from controller to controller.
After that, you should see a long stream of text similar to the following. (You may need to hold down a button or waggle a stick to see these)ACL Data RX: Handle 12 flags 0x02 dlen 54 [hci0] 5.571498
Channel: 65 len 50 [PSM 0 mode 0] {chan 0}
a1 01 00 00 00 00 00 80 86 7d 7f 00 00 00 00 00 .........}......
00 00 00 00 00 00 00 00 00 00 00 00 00 00 03 05 ................
16 ff d0 00 00 33 3c 77 01 c0 01 fc 02 02 01 86 .....3<w........
01 ee ..The part you're actually interested in here is the [hci0] 5.571498. This gives the time in seconds after btmon was started when the data packet from the controller was received by the pi (I think).
For my PS3 controller, before the role switch to slave, these times increase unsteadily in intervals of about 30ms (0.03s). That's about 2 frames at 60fps. Once the role is switched to slave, the packets begin to arrive at steadier intervals of a consistent 11ms. I believe the PS3 controller is sending a packet every 11ms so I presume this is the maximum input lag as a result, presuming no computation delays within the controller itself. 1 frame is 1/60 of a second or about 16.67ms, so this is a major improvement.
The PS4 controller I have is a more interesting case.
By default, even when in slave mode, the PS4 controller seems to be sending packets of data every ~1.3ms . Even when switched to slave mode, this remains consistent. The ping times improve, but role switch seems to have no effect on the actual rate at which the device is sending packets of data. I think the PS4 controller should produce almost minimal input lag by default. Can anyone confirm this? (Edit: I should add. The PS4 controller tends to introduce a lot of "noise" which cause the PS3 controller to expierience quasi-regular lags.)I'm curious as to what the delay times are for the FC30 controllers. Canyou try running btmon -S for your controllers also. Also, btmon does report more useful information about the connection setup, but I don't know how to use this yet. The Bluez team may know more.
-
Damn good stuff, @ARoxdale .
So it sounds like the role switch to slave yields a measurable improvement. From your original thread, you give the command: sudo hcitool sr AA:BB:CC:DD:EE:FF slave , of course, filling in the variables per your instructions. And you say that the command needs to be executed every time the controller is re-connected. I take it that means, every time the Pi is shut down and turned back on? If so, I know there are "runbefore" options available at boot time, seems that command could simply be added there? But the question is, does the device's address change from boot to boot?
I'm without a PS3 controller temporarily to test this out myself... -
There is another factor to be taken into consideration: The difference in latency with the Dualshock 3 controller between master and slave mode probably exist only with the Bluetooth chip of the Raspberry Pi. I am using a Cambridge Silicon Radio Bluetooth USB dongle with my Pi and see absolutely no difference in latency between the DS3 in master or slave mode.
I don't think the Pi's Bluetooth is working well with the DS3 because I've seen lots of problems: connection failures, latency, high system load with the sixaxis driver, system log filled with Bluetooth errors etc. I'd recommend to buy a cheap compatible Bluetooth dongle (my recommendation goes to the CSR one) if one wants to use the DS3 instead of going off to a wild goose chase in the depths of Linux Bluetooth configuration.
-
After some reading using this as a reference.
Best Bluetooth Adapters 2017 : Complete GuidePlugable USB Bluetooth 4.0
Looks like it's compatible out of the box with Raspian.
I wonder if going for this one might solve the lag with the built-in BT.
-
I especially like the quote from elinux.org (your second link): "The best solution for these devices seems to be to return them or throw them away, and go with the ones with a genuine Cambridge Silicon Radio chipset."
Problem is: many Bluetooth adapters are sold by diffrend brands and seldom the original manufacturer of the Bluetooth chip used is named (and brands may change OEMs while still selling their product under the same name). My DS3 controllers work very well with CSR chips, other Bluetooth devices have no problems with the pi's builtin chip, so lag and other problems might be compatibility issues between the pi chipset/driver and Sony's DS3/4 controller.
-
@PET2001 So in other words go for a Bluetooth 4.0 CSR Dongel?
Do you know any good legit 4.0 csr dongels?
-
I bought some of these devices for my RetroPies: Amazon.de link (obviously a link to the german Amazon site).
Searching for "usb bluetooth csr" however should lead to multiple devices using the CSR chipset (at least it does for me).
-
I just tried turning wifi off in an attempt to reduce lag with my PS4 controller, however the monitor shows dropouts every half second or so of 40 ms or more inbetween many fast receipts with delays of 2 ms or so.
Since turning off wifi is not helping with the lag, I am trying to turn wifi back on.
However the recommended command
sudo iwconfig wlan0 txpower on
does result in an input/output error. Replacing "on" with "Auto" doesn't work either
The command
sudo iwconfig wlan0 txpower 31dbm
Works. But which is the default power? Is 31dbm correct?EDIT: I found it you have to enter "sudo iwconfig wlan0 txpower auto" TWO TIMES one after the other to turn wifi back on. The first time there's an input/output error response, but the second time it works.
EDIT2: I found the proper way to turn off wifi is to add the line dtoverlay=pi3-disable-wifi to /boot/config.txt . Disabling wifi this way reduced to ping round trip times for my DS4 controller from an average of around 40 ms with some high spikes >100 ms, to an average of around 10 ms. There's still an occasional spike to >40 ms which is very annoying. But this is definitely an improvement.
-
Huh.
I'm surprised I had never seen this, nor had I devoted much to it.
Still, I do confirm that at least the results for the controller Pings are indeed impressive, especially after turning off wifi (drop down to hover between ~11ms and ~30ms or so), and then making them slave to round it off and make it almost always around ~10ms to ~12ms.
Thank you!
I added two scripts to my RetroPie menu in ES to run this on demand - one to turn off wifi and make them slave, and the other to restore wifi.
https://retropie.org.uk/forum/topic/1498/solved-how-to-add-something-to-retropie-menu
I noticed that when I have two controllers paired, the ping performance is slightly worse, and the difference between master/master, slave/slave, or one master and one slave isn't as clear. They both hover between ~12ms and ~40ms when paired simultaneously.
However, still one order of magnitude lower than if with wifi on (it was common to find them having 100ms and above, with the two controllers paired). So thank you for this!
-
Yes the difference in ping times between Wi-Fi ON and Wi-Fi OFF with the Sony DS4 controller is huge! And it shows in regular games, too. After turning off Wi-Fi, I can now play Super Mario World quite well. Before turning off wi-fi, jumping accurately was really hard.
I am still waiting for my Sony DS4 USB dongle to try that out. I hope the dongle will make the controller even snappier and allow me to turn Wi-Fi back on. The problem with the Sony USB dongle is that it can only pair one controller. So for four players, I would need four dongles.
-
-
@rion I wouldn't know as I don't have one such controller. Still, the instructions are fairly simple and non-destructive - other than you having to explicitly turn on the WiFi if you want to revert it, everything else goes away with a reboot, so I'd recommend trying it out.
I don't see why it wouldn't help other Bluetooth controllers, though I can't confirm it would for sure. Let us know if you test it yourself!
-
@aroxdale Thanks for this article. I have SFC30 controllers, and was experiencing quite a bit of lag in certain games, such as Giga Wing and Air Gallet. It made the games unplayable and tweaking the configuration files didn't fix the problem. However, turning off the wifi seemed to help a ton! I found this link: https://raspberrypi.stackexchange.com/questions/43720/disable-wifi-wlan0-on-pi-3 and added to /boot/config.txt:
dtoverlay=pi3-disable-wifi
This disabled the wifi on boot and since then, problem games I've tested are playing perfectly (of course much more testing to do :)
Thank you again. This definitely leveled up my RetroPie experience.
-
I feel the official Sony USB Wireless Dongle reduced the lag even more. But two of them side by side causes interference and causes one of the two players to lag extremely.
I then moved the Sony dongles further apart using a powered USB 2.0 Hub, and now I can play two player games fine with wireless DS4 controllers without any lag.
Does internal WIFI or internal BT interfere with external BT? In other word shall I switch those things off, or can I switch them all on again?
-
Has anyone figured out a permanent solution for this yet? This works great but I'm hoping to make it permanent or automated so my family members can get the benefit without dropping to the command line.
-
i tried pi 3b+ without any issue, one usb arcade joystick, one xbox360 wireless controller with usb receiver, one ps3 wireless controller connected to pi's internal Bluetooth. all of them worked very well, no lag. the pi uses 5G wifi connected router all the time. maybe 5G wifi signal does not interfere with 2.4G bluetooth signal. i tested many arcade games which are more than 3 players, so ar so good.
-
If anyone has trouble turning your wifi back on after running:
$ sudo iwconfig wlan0 txpower offeven after running "sudo iwconfig wlan0 power on" (note, "power" not "txpower"), and rebooting, as I did, it may be because your wifi is is "soft blocked" (whatever that is). I fixed by running:
$ sudo rfkill unblock wifi
as in this thread:
https://askubuntu.com/questions/62166/siocsifflags-operation-not-possible-due-to-rf-kill -
Also, instead of turning off wifi, you can use a USB bluetooth dongle instead of the onboard bluetooth, as in this thread. You get much lower lag to your ps3 controllers and you can keep your wifi on:
-
@ARoxdale said in Fixing (DualShock 3) Bluetooth Lag:
https://github.com/retropie/retropie-setup/wiki/Setting-up-an-8bitdo-Bluetooth-controller
hi there im using fake ps3 controllers (shanwan) an I have a lot of lag on it the only way for me to pair is using ps3controller i cant connect using sixaxis or 8bitdo. i can´t make this any way of fixing it?
-
@marine88 Pleas open a new topic, this topic is 3 years old.
Contributions to the project are always appreciated, so if you would like to support us with a donation you can do so here.
Hosting provided by Mythic-Beasts. See the Hosting Information page for more information.