PS3 controller using USB Host

I had an extra look at the examples and this is what I came up with:


using System;
using System.Threading;

using Microsoft.SPOT;
using Microsoft.SPOT.Hardware;

using GHIElectronics.NETMF.FEZ;

using GHIElectronics.NETMF.System;
using GHIElectronics.NETMF.USBHost;

using PS3ControllerUSB;

namespace PS3_Controller
{
    public class Program
    {
        static PS3Controller PS3;
        public static void Main()
        {
            Debug.Print("Initialize...");
            USBHostController.DeviceConnectedEvent += DeviceConnectedEvent;
            Thread.Sleep(Timeout.Infinite);
        }

        static void DeviceConnectedEvent(USBH_Device device)
        {
            Debug.Print("Joystick Connected");
            PS3 = new PS3Controller(device);
            // Read the analog hat switch
            Debug.Print("LH " + PS3.GetAnalogHat(PS3Controller.AnalogHat.LeftHatX) + " " + PS3.GetAnalogHat(PS3Controller.AnalogHat.LeftHatY));
            // Read digital switch
            if (PS3.GetButton(PS3Controller.Button.CROSS))
                Debug.Print("CROSS");
        }

    }
}

But it stills gives me an error in the source code. If your look in line 43:

USB_Descriptors.ConfigurationDescriptor cd = raw.GetConfigurationDescriptors(0);

It says “The type or namespace name ‘USB_Descriptors’ could not be found (are you missing a using directive or an assembly reference?” I have tried including “Microsoft.SPOT.Hardware.UsbClient;”, but it is still not working. Alternative I changed it to:

USBH_Descriptors.Configuration cd = raw.GetConfigurationDescriptors(0);

But then it gives me the following error when I try to compile:
“An unhandled exception of type ‘System.InvalidOperationException’ occurred in GHIElectronics.NETMF.USBHost.dll” in this regard to this line:

USBHostController.DeviceConnectedEvent += DeviceConnectedEvent;

Your issue is that you haven’t identified the namespace correctly. Until you do that, your code is not expected to work.

Changing something that is documented (and therefore expected to work) is the wrong approach. Sort out a working example with a keyboard or mouse and you’ll see what references you need to add and what USING statements you need. Then go back and try these more advanced devices.

Learning the simple stuff before you try to jump in the deep end is important.

I tried adding all these:


using System;
using System.IO;
using System.IO.Ports;
using System.Text;
using System.Threading;
using System.Runtime.CompilerServices;

using Microsoft.SPOT;
using Microsoft.SPOT.Hardware;
using Microsoft.SPOT.IO;
using Microsoft.SPOT.Messaging;
using Microsoft.SPOT.Hardware.UsbClient;

using GHIElectronics.NETMF.System;
using GHIElectronics.NETMF.Hardware;
using GHIElectronics.NETMF.FEZ;
using GHIElectronics.NETMF.IO;
using GHIElectronics.NETMF.USBHost;
using GHIElectronics.NETMF.USBClient;

But it still gives he same error:
“The type or namespace name ‘USB_Descriptors’ could not be found (are you missing a using directive or an assembly reference?”

The reason why I tried changing it, was because ConfigurationDescriptor is not a valid command.

Have you added Microsoft.SPOT.Hardware DLL to the projects references.

small steps padawan…

You should go back and use the tutorials; as Mike points out (and as I kind of mentioned) you need to not only add a USING statement but add the REFERENCE.

[quote]The reason why I tried changing it, was because ConfigurationDescriptor is not a valid command.
[/quote]
It is valid, it’s just unknown in your project. Adding the reference and then adding an appropriate USING will enable VS to resolve what you are talking about. That’s my point, someone else has this working therefore it must be working, and you have something else wrong…

This is already explained in the book BTW

@ Mike and Brett:
I am not a totally noob :wink:
I have already added them to the references. Take a look at a screenshot of the Solution Explorer:
https://lh3.googleusercontent.com/-dZSA0bmiq6Y/Th-aa1fonHI/AAAAAAAAAHI/aHH2W89QBGw/s800/Fez%252520Panda%252520help.jpg
I have done all the basic examples, but I really bought it to use it as a USB Host.
Thanks for the help guys :slight_smile:

Panda, right?

Are you debugging using serial and made the needed hardware changes?

@ Gus
Yes I use a Panda II.
Yes I already made a special USB Host cable (TKJ Electronics » FEZ Panda and USB Host) and succesfully connected it to a terminal through a usb to serial converter (http://cgi.ebay.com/ws/eBayISAPI.dll?ViewItem&item=190405467837&ssPageName=STRK:MEWNX:IT). I have already succesfully made a program for a VERY old joystick I had laing around (http://www.ntrautanen.fi/computers/other/images/sidewinder_ff_pro.jpg), and it works perfectly :slight_smile:
But as you can see I can not get the PS3 Controller working.

I will make a project for you but you promise to update the wiki with more details? :slight_smile:

You did everything correctly but the code is too old and needed a little fix. You best friend is the GHI documentation http://www.ghielectronics.com/downloads/NETMF/Library%20Documentation/Index.html

If you look under USB Host you will see USBH_Descriptors but the code uses USB_Descriptors and then the class doesn’t have “Configuration Descriptor” but it has “Configuration”.

Basically

USB_Descriptors.ConfigurationDescriptor cd = raw.GetConfigurationDescriptors(0);

becomes

USBH_Descriptors.Configuration cd = raw.GetConfigurationDescriptors(0);

Have fun!

Now, can you please try it then update the wiki with details and updated code?

Yeah thats exactly what I did (see reply 20). I will play around with it, and then I will update the wiki. I am thinking of enabling the rumble function as well, but that might take a bit of work :slight_smile:

I have now updated the wiki: [url]http://wiki.tinyclr.com/index.php?title=PS3_Controller[/url] . I updated the code to work with NETMF 4.1 and also enabled Rumble and fixed some other minor bugs.
I will keep updating it and maybe write some further details about the protocol used by the PS3 Controller :slight_smile: I will upload a videoclip in the following week.

Very nice, looking forward to see the video.

I have updated the library, so it now enables anglemeasurement using the accelerometers and status. Bluetooth is still to come - I am still waiting for my Bluetooth dongle to arrive - but I have implemented set and get Bluetooth address, which is needed for bluetooth connection.
See the wiki for more details.

I worked with the PS3 controller over bluetooth in the past; issue is if you actually have a PS3 it will beat out the cobra on response time and the controller will end up talking to the PS3 instead of the Cobra.

This is not a problem, you just have to use the setBT function, as this will set internally into the controller, which address to look for!

I finally recorded a video, so go to the wiki and check it out ;D

Nice work!

Thanks for sharing

Just wanted to let you know, that bluetooth is now working - finally!!! :slight_smile:
I just have to clean up the code, and then I will update the wiki :smiley: