FEZ Panda & PS3 Controller
NB: The newest source code can now be found at github.
As Thomas origanally posted, the FEZ Panda can actually be used as a USB-Host: Fez Panda And USB Host. I have for long time wanted to use my PS3 DualShock 3 controllers for something useful (besides playing Playstation of course), therefore I thought it would be interesting to connect it to the FEZ Panda.
I used a FEZ Panda II for the project, which is an enhanced version of FEZ Panda (the first one) with on-board microSD socket, Real Time Clock, and an easily accessible 40-pin female header that exposes the extra IOs. For more information see the original website: FEZ Panda II.
But before you can use the FEZ Panda’s USB-Host functionality, you have to make a special USB-Host cable. See Thomas’ previous post for information: Fez Panda And USB Host. If you are new to FEZ see The Beginner Guide ebook.
Like many other USB joysticks the PS3 Controller uses the HID Protocol, but it has a lot of advanced functions, like built in 3-axis accelerometer, single axis gyro, rumble, LED status, and more.
It features two analog joysticks, triggers and a lot of buttons. The unique thing about PS3 controllers is that almost all the buttons can be read either as analog values or digital, directly from the controller. Another feature is the ability to communicate over either USB or Bluetooth. I have only enabled USB communication, but I will work on implementing Bluetooth as well.
After some Googling I discovered that the PS3 Controller is a bit different from ordinary joysticks. One example is that you have to send a special command, to request the PS3 controller to fx send button presses back:
//request the PS3 controller to send button presses etc back
//Host to device (0x00) | Class (0x20) | Interface (0x01), Set Report (0x09), Report Type (Feature 0x03) - Report ID (0xF4), Host to device (0x00) - Endpoint 0 (0x00), data, dataoffset, datalength
raw.SendSetupTransfer(0x21, 0x09, 0x03F4, 0x0000, buf, 0x00, 0x04);
For information about the HID protocol used by the program, see the following link page 48. See under “Get_Report Request” and ” Set_Report Request” which are the commands used for the PS3 controller. For further details see this link at “9.3 USB Device Requests”.
For more information, see the code at the bottom of this post.
The program has lot of inspiration from the following guide for the Arduino USB Host shield.
You should also check out GHIElectronics wiki I contributed to.
The following video demonstrates all the futeres:
When reading the PS3 Controller, it will send out a bunch of bytes. To see these bytes, use the following program (works with both Linux, Max, and Windows – see the folder “testgui”). Some people has reported that it does not work under windows. Alternative see the following program instead (Windows only): SimpleHIDWrite.
For information about the protocol used by the PS3 Controller, see the following link.
For more information about the USB Protocol and how it works see the following links:
A simple intro to USB
A lot of information and good programs for both windows, linux and mac
If you use a Fez Panda like me, you will recieve the following error: “An unhandled exception of type ‘System.InvalidOperationException’ occurred in GHIElectronics.NETMF.USBHost.dll”, you can just press “Continue” – it just can’t find the USB host, because the USB plug is used by the USB client. You have to make a speciel USB host cable see this guide for further details: FEZ Panda and USB Host (http://blog.tkjelectronics.dk/2011/03/fez-panda-and-usb-host/).
Furthermore you have to connect the Mode pin (labeled MOD) to ground using a wire, to enabled debugging through COM1. Also the RX (COM1 In), are not allowed to float, so you have to use a pullup resistor, or connect it to a USB-Serial adapter. You can also use the USB-Serial adapter to program it via the serialport, to do so go to “Properties -> .NET Micro Framework” and change “Transport” to “Serial”, and “Device” to your USB-Serial adapter’s COM-port.
All the code is licensed under a Creative Commons Attribution Noncommercial Share-Alike license, see this link for details: http://creativecommons.org/licenses/by-nc-sa/3.0/