Archive

Archive for the ‘USB’ Category

Xbox 360 controller support added to the USB Host Library

July 18th, 2012 90 comments

Update
A wireless Xbox 360 controller is now also supported via a Wireless receiver. For more information see the blog post.

Hi everyone. I just wanted to let you know, that I just added support for the Xbox 360 controller via USB to the USB Host Library. The code can as always be found at github: https://github.com/TKJElectronics/USB_Host_Shield_2.0.

Categories: Arduino, TKJ Electronics, USB Tags:

PS3 Controller BT Library for Arduino

January 16th, 2012 292 comments

I just finished porting the bluetooth library to Arduino. It’s based on the library for the USB Host Shield from Circuits@Home. It works exactly the same way as the class for the boards from GHIElectronics – FEZ Panda, FEZ Rhino etc. You should check out my other post, if you haven’t already: FEZ Panda & PS3 Controller, FEZ Panda & PS3 Controller via Bluetooth, and Demonstration of the PS3 Controllers in action.
To make it work, you’ll need a USB Host Shield or an Arduino ADK.

Update
I have now created another library that only supports the controller via USB. The source code for the USB library can be found at the github repository. An example can be found as well: PS3USB.ino.

Video Demonstration

The library can be found at our Github: https://github.com/felis/USB_Host_Shield_2.0. You should also see the Github wiki for more details.

Categories: Arduino, Bluetooth, TKJ Electronics, USB Tags:

Demonstration of the PS3 Controllers in action

January 10th, 2012 No comments

NB: The newest source code can now be found at github.

Playstation Navigation and Motion controller

Playstation Navigation and Motion controller

As some of you might have seen, my class for the development boards from www.ghielectronics.com, including FEZ Panda, FEZ domino, FEZ Rhino etc, now also works with the two other PS3 controller: the Navigation and the Motion controller. The Navigation controller works the exact same way as the original Dualshock 3 controller.
The Motion controller is a little different, as all of the commands sent to the controller are sent via the HID Interrupt channel, and not thru the HID Control channel as the Dualshock 3 and Navigation controller. It also use a DATA output request instead of a set output report request. For more information, see the source code and the wiki.

A great thing about the Motion controller is that it features a 3-axis accelerometer, 3-axis gyro, 3-axis magnetomer, a thermometer, and the shiny bulb on the top of course. All these peripherals can by controlled by the FEZ devices too.

 
Stay tuned as I have almost finished porting the code to Arduino – I will make a new post as soon as I’m finished.

 
Demonstration of the three controllers

The code used in the video: PS3BluetoothNXTVersion2

Categories: Bluetooth, TKJ Electronics, USB Tags:

FEZ Panda & PS3 Controller via Bluetooth

September 9th, 2011 39 comments

NB: The newest source code can now be found at github.

As you might have seen, I finally got the PS3 Controller working via Bluetooth. Before you read any further, you should read my previous post first and also see the wiki for more information.

Read more…

Categories: ARM, Bluetooth, Guides, USB Tags:

FEZ Panda & PS3 Controller

August 5th, 2011 14 comments

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.

PS3 DualShock 3 Controller


Read more…

Categories: ARM, Guides, USB Tags:

FEZ Panda and USB Host

March 24th, 2011 15 comments

As I promised in my previous post, I would show you how to get USB Host working on the FEZ Panda.

FEZ Panda - USB Host Cable


When I first glanced at the LPC2387 datasheet (the ARM on the Panda), I notice that it actually supported USB Host. Then I thought why it wasn’t possible to use USB Host on the Panda, and I quickly found out that it was because it required some hardware modifications.

USB Cable Wiring


The difference in the hardware between USB Client and USB Host is that the Host is powering the Client, and the Panda had a protection diode so no power would go “out” the USB port. Another thing to notice is that USB Host requires two 15K resistors to pull D+ and D- to ground.

FEZ Panda - USB Host cable wiring


SMD solution
So how did I do it? I didn’t want to modify the FEZ Panda board, as the USB port would then be a permanent USB Host port. Instead I thought it would be nice just to have a cable for the USB Host thing, which should include the two resistors, and a power wire for the +5V power supply.
The first image in this post is my cable, and the second image shows the connections, where there is soldered two 15K SMD 0805 resistors inside. This took a long time to make because it was so small, and SMD resistors can’t handle much force. On a longer term basis it would be better to make an adapter PCB instead.

USB Host cable Schematic

Above you can see the simple schematic of the changes that has to be made to the cable, including where to solder/connect the two 15K resistors.

Thru Hole solution
Instead of using SMD resistors I recommend you to use Thru Hole resistors, and they can handle a lot more force, and the joint will also be more reliable.

FEZ Panda - USB Host Cable


The assembly method is the same as with the SMD resistors. If you don’t have any 15K resistors in hand, we have also tested it with a 12K instead, and everything seems to be running fine with that too.

FEZ Panda - USB Host cable wiring


Oh, and please notice the USB Mini-B to USB Female A adapter at the end. This can be bought at Amazon for $1.87!

USB Connector Pinout


After I made the cable the last thing I had to do was to update the firmware on the FEZ Panda, as the firmware (USBizi) for the FEZ Panda, didn’t support USB Host until V4.1.5.0, though the processor did. After I uninstalled the old firmware/SDK, downloaded the new one, and installed it, I was ready to update the firmware. I just followed this simple Youtube guide:

After the firmware was updated, I connected a cable from the MODE pin to GND to enable Serial Port (COM1) debugging, as the USB port will now be used for USB Host functions.
Then I just followed the “USB Host – Mass Storage” chapter in the Beginners Guide to .NETMF.

To help you guys getting started, I used this code to test the USB Host function. The applications outputs which device is connected, and if a Mass Storage device is detected, the files- and folder tree is shown too.

using System;
using System.Threading;

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

using GHIElectronics.NETMF.FEZ;

using Microsoft.SPOT.IO;
using GHIElectronics.NETMF.IO;
using GHIElectronics.NETMF.USBHost;
using System.IO;

using System.IO.Ports;
using System.Text;


namespace FEZ_Panda_Application1
{
    public class Program
    {
        static bool ledState = false;
        static OutputPort led = new OutputPort((Cpu.Pin)FEZ_Pin.Digital.LED, ledState);

        static SerialPort UART = new SerialPort("COM2", 115200);


        // Hold a static reference in case the GC kicks in and disposes it
        // automatically, note that we only support one in this example!
        static PersistentStorage ps;

        public static void Main()
        {
            UART.Open();

            WriteSerial("Starting...");

            // Subscribe to RemovableMedia events
            RemovableMedia.Insert += RemovableMedia_Insert;
            RemovableMedia.Eject += RemovableMedia_Eject;

            // Subscribe to USB events
            USBHostController.DeviceConnectedEvent += DeviceConnectedEvent;
            USBHostController.DeviceDisconnectedEvent += DeviceDisconnectedEvent;
            // Sleep forever
            //Thread.Sleep(Timeout.Infinite);

            int read_count = 0;
            byte[] rx_byte = new byte[1];

            while (true)
            {
                // read one byte
                read_count = UART.Read(rx_byte, 0, 1);
                if (read_count > 0) // do we have data?
                {
                    //WriteSerial("I recieved: " + (char)rx_byte[0]);
                    switch ((char)rx_byte[0])
                    {
                        case 'W':
                            WriteSerial("Writing content to test file:");
                            WriteTestFile("Hello there!");
                            WriteSerial("   Hello there!");
                            break;
                        case 'R':
                            WriteSerial("Reading content from test file:");
                            WriteSerial("   " + ReadTestFile());
                            break;
                    }
                }
            }
        }

        static void DeviceConnectedEvent(USBH_Device device)
        {
            string USBDeviceType = "";

            switch (device.TYPE)
            {
                case USBH_DeviceType.HID:
                    USBDeviceType = "HID";
                    break;
                case USBH_DeviceType.Hub:
                    USBDeviceType = "Hub";
                    break;
                case USBH_DeviceType.Joystick:
                    USBDeviceType = "Joystick";
                    break;
                case USBH_DeviceType.Keyboard:
                    USBDeviceType = "Keyboard";
                    break;
                case USBH_DeviceType.MassStorage:
                    USBDeviceType = "Mass Storage";
                    break;
                case USBH_DeviceType.Mouse:
                    USBDeviceType = "Mouse";
                    break;
                case USBH_DeviceType.Printer:
                    USBDeviceType = "Printer";
                    break;
                case USBH_DeviceType.Serial_CDC:
                case USBH_DeviceType.Serial_FTDI:
                case USBH_DeviceType.Serial_Prolific:
                case USBH_DeviceType.Serial_Sierra_C885:
                case USBH_DeviceType.Serial_SiLabs:
                    USBDeviceType = "USB to Serial converter";
                    break;
                case USBH_DeviceType.Sierra_Installer:
                    USBDeviceType = "Sierra Installer";
                    break;
                case USBH_DeviceType.Unknown:
                    USBDeviceType = "Unknown";
                    break;
                default:
                    USBDeviceType = "Unknown";
                    break;
            }

            WriteSerial("USB Device connected: " + USBDeviceType);
            WriteSerial("ID: " + device.ID + ", Interface: " + device.INTERFACE_INDEX + ", Type: " + device.TYPE);

            led.Write(true);

            if (device.TYPE == USBH_DeviceType.MassStorage)
            {
                WriteSerial("Mounting Mass Storage...");
                ps = new PersistentStorage(device);
                ps.MountFileSystem();
            }
        }

        static void DeviceDisconnectedEvent(USBH_Device device)
        {
            WriteSerial("USB Device disconnected...");
            led.Write(false);
        }

        static void RemovableMedia_Insert(object sender, MediaEventArgs e)
        {
            WriteSerial("Storage "" + e.Volume.RootDirectory + "" is inserted.");
            WriteSerial("Getting files and folders:");
            WriteSerial("");
            if (e.Volume.IsFormatted)
            {
                WriteFilesAndFolders(e.Volume.RootDirectory, e);
            }
            else
            {
                WriteSerial("Storage is not formatted. Format on PC with FAT32/FAT16 first.");
            }
            WriteSerial("");
        }

        static void RemovableMedia_Eject(object sender, MediaEventArgs e)
        {
            WriteSerial("Storage "" + e.Volume.RootDirectory + "" is ejected.");
        }


        static string[] files, filesSub;
        static string[] folders, foldersSub;
        static void WriteFilesAndFolders(string path, MediaEventArgs e)
        {
            files = Directory.GetFiles(path);
            folders = Directory.GetDirectories(path);
            WriteSerial("Files available on " + path + ":");
            for (int i = 0; i < files.Length; i++)
                WriteSerial("   " + files[i]);

            WriteSerial("Folders available on " + path + ":");
            for (int i = 0; i < folders.Length; i++)
            {
                WriteSerial("   " + folders[i]);
                WriteSerial("");
                WriteSubFilesAndFolders(folders[i], e);
            }
        }

        static void WriteSubFilesAndFolders(string path, MediaEventArgs e)
        {
            filesSub = Directory.GetFiles(path);
            foldersSub = Directory.GetDirectories(path);
            WriteSerial("Files available on " + path + ":");
            for (int i = 0; i < filesSub.Length; i++)
                WriteSerial("   " + filesSub[i]);

            WriteSerial("Folders available on " + path + ":");
            for (int i = 0; i < foldersSub.Length; i++)
            {
                WriteSerial("   " + foldersSub[i]);
                WriteSerial("");
                WriteSubFilesAndFolders(foldersSub[i], e);
            }
        }

        static void WriteTestFile(string dataToWrite)
        {
            if (VolumeInfo.GetVolumes().Length < 1) return;
            // Assume one storage device is available,
            // access it through NETMF
            string rootDirectory = VolumeInfo.GetVolumes()[0].RootDirectory;
            FileStream FileHandle = new FileStream(rootDirectory + @"\hello.txt", FileMode.Create);
            byte[] data = Encoding.UTF8.GetBytes(dataToWrite);
            // write the data and close the file
            FileHandle.Write(data, 0, data.Length);
            FileHandle.Close();
        }

        static string ReadTestFile()
        {
            if (VolumeInfo.GetVolumes().Length < 1) return "No Mass Storage found!";
            // Assume one storage device is available,
            // access it through NETMF
            string rootDirectory = VolumeInfo.GetVolumes()[0].RootDirectory;
            if (!new FileInfo(rootDirectory + @"\hello.txt").Exists) return "File not found!";
            FileStream FileHandle = new FileStream(rootDirectory + @"\hello.txt", FileMode.Open, FileAccess.Read);
            byte[] data = new byte[100];
            // write the data and close the file
            int read_count = FileHandle.Read(data, 0, data.Length);
            FileHandle.Close();
            //Debug.Print("The size of data we read is: " + read_count.ToString());
            //Debug.Print("Data from file:");
            //Debug.Print(new string(Encoding.UTF8.GetChars(data), 0, read_count));
            return new string(Encoding.UTF8.GetChars(data), 0, read_count);
        }
        static void WriteSerial(string StringToWrite)
        {
            // convert the string to bytes
            byte[] buffer = Encoding.UTF8.GetBytes(StringToWrite + "\r\n");
            // send the bytes on the serial port
            UART.Write(buffer, 0, buffer.Length);
        }
    }
}

This video is just an example of what you can use the USB-host functionality for:

Update
Kristian has succesfully connected the PS3 Controller to the FEZ Panda, for more information, take a look at his post.

Categories: ARM, USB Tags: