Trying to use third party webcam with FEZ Spider (Gadgeteer) USB host module

Hello - I’m just getting my feet wet with my FEZ spider kit and I’m trying to use the camera class provided with the gadgeteer SDK to stream a bitmap from my third-party webcam to the included display.

I got the included camera to work just fine using the example included with the documentation, but i want to use my third party cam instead.

I have the USB host module hooked up with my webcam attached.

I can build and deploy my code, query the camera’s “ready” status (which returns “true”), but I can’t take a picture or stream a bitmap to the display.

When I take a picture using the joystick button, it does not show on the display. If I try to take another picture, and the debugger returns the message “camera is already taking a picture”

I can post my code, but I just like to know if what I’m doing is feasible.

Thanks very much.

The Gadgeteer Camera class provided in the GHI SDK is “tuned” for the camera they sell. I suspect there might be some issue with matching resolutions.

The GHI camera has three resolutions. The camera has a property CurrentResolution which determine the resolution that is to be used. Try changing the resolution to see if you can find one that matches.

If you can’t get it working, then do a search for Web Camera on the wiki. You should be able to get it working if go directly to NETMF bypassing the Gadgeteer layer.

This assume that your camera is compatible and has a resolution that is acceptable for fast USB.

Mike - thanks for the quick response.

I had already tried setting the resolution using:

 camera.CurrentPictureResolution = GTM.GHIElectronics.Camera.PictureResolution.Resolution320x240;

That was my first thought as well since the camera’s default res is 640x480. Also tried using the NETMF functions using the code http://www.ghielectronics.com/downloads/NETMF/Library%20Documentation/html/cb022f02-117b-f7dd-d85a-ff4e09751204.htm but get a message that says something along the lines of " use the gadgeteer.camera functions for USB Webcam support" and another message saying “USB device not supported”

Although, I haven’t tried setting the camera res using the NETMF functions. That might be worth a try. I guess the “device not supported” message is confusing me b/c I don’t believe there is anything really special about this webcam.

Here is a link to the http://www.bestofferbuy.com/Compact-Flexible-Neck-20MP-PC-USB-20-Webcam-p-63854.html?currency=USD&utm_source=gbase&utm_medium=cse&utm_campaign=gbase_usa camera I’m using

Not all cameras use standard video class and not all cameras work properly on full-speed USB (12mbps) found on FEZ Spider (EMX module)

640x480 is not possible anyways on full-speed USB, max is 320x240 IIRC

Thanks Gus.

Good to know, and yeah the T35 display supports 320x240 max anyway right.

Below are some specs on my camera, I’d like to know whether it’s a software or hardware issue since the only message I’m getting “USB device not supported” doesn’t give me any indication why it might not be supported. I’m using this camera for my project because of the form factor but I suppose I could replace with another if I had some way to know the replacement cam used standard classes and met the hardware requirements.

Device Type: Digital Camera
Manufacturer: Empia Technology
Model: Recognized as DEF-299B in XP hardware manager
Interface: USB

  • DSP: 2.0Mega Pixels, Effective 5.0Mega Pixels
  • Sensor: Compliant from 350k to 5000k
  • Form of the Video: 1280 x 960 pixels, with driver
  • Display: 640 x 480, 352 x 288, 320 x 240
  • Form of Output: YUY2
  • Frame Rate: CIF, 30 frame/sec
  • Lens focus: F6.0mm
  • Focus range: 20mm to infinity
  • White Balance: Automatic/Manual
  • Interface: USB 2.0

Thanks

Just tested the cam over a USB 1.1 hub connected to WinXP machine based on Gus’s comment. The resolution defaulted to 352x288 and the video was shown properly.

When you used it on windows, did windows ask for drivers?

In other words, when you look under the name of the driver vendor in device manager, is it Microsoft?

You can also use GHI libs to read the device class/subclass to determine of it is standard USB video compliant device…you camera is probably not. USB video device class - Wikipedia

Yes - it asked for drivers and the driver manufacturer listed in device manager is Empia Technology.

I went into device manager and rolled the driver from the Empia driver to one provided by Microsoft and the camera displays properly using the Microsoft driver.

So I guess I have some more testing to do.

If windows asked for drivers then this is not a standard USB class and so it will not work on your fez

Gus - Sorry for the confusion. Just plugged the cam into an instance of XP where I had not previously installed the included drivers for the camera and windows does not ask for any drivers. It simply loads the camera as a device in My computer and I’m able to double click and view camera video stream and take pictures.

With the camera attached to the USB module on my fez, I execute the following code:

void USBHostController_DeviceConnectedEvent(USBH_Device device)
        {
            Debug.Print("ID: " + device.ID + ", Interface: " +
                   device.INTERFACE_INDEX + ", Type: " + device.TYPE);
         } 

I get the following console output:

Using mainboard GHIElectronics-FEZSpider version 1.0
UsbHost ERROR : Use GTM.GHIElectronics.Camera for USB WebCamera support.
ID: 2699998812, Interface: 0, Type: 16
UsbHost ERROR : USB device not supported.
ID: 2699998812, Interface: 1, Type: 0

Thanks

Checking the GADGETEER library code, for the USB Host module, I see that a WebCamera is not one of the supported devices. That is why you are getting the unsupported device messages.

The solution is to lie. Tell the designer that you are using the WebCamera but plug in the USB Host module. If the camera is compatible it should work.

Thanks Mike. Yeah that is essentially what I’ve been trying. I am using the gadgeteer camera libs but with the USB module actually plugged into the fez board and my third party webcam attached to the USB module. The camera would connect and return a “ready” status. I would invoke camera.TakePicture() but the PictureCaptured event would never get raised. If I tried to invoke camera.TakePicture() again, I would get a console message saying that the camera was already busy taking a picture.

So it gets weirder now. I decided to try another webcam that I had laying around, a Logitech Pro 4000.

Using the same code, the logitech camera never even raises the cameraConnected event.

So one camera is recognized by the board and returns a ready status but I can’t take a picture and the other camera is not recognized at all.

I think I may just order a new camera off the list here:

That way I’m certain I’ve got a UVC-compatible camera

Here is my code for more clarity; note: the only reason I’m using NETMF.USBHost is to inspect the attached device. I’m using the gadgeteer camera class for communicating with the cam.

Program.cs


using System;
using Microsoft.SPOT;
using Microsoft.SPOT.Hardware;
using Microsoft.SPOT.Presentation;
using Microsoft.SPOT.Presentation.Controls;
using Microsoft.SPOT.Presentation.Media;
using GHIElectronics.NETMF.USBHost;

using GT = Gadgeteer;
using GTM = Gadgeteer.Modules;
using Gadgeteer.Modules.GHIElectronics;

namespace GadgeteerApp1
{
    public partial class Program
    {
      
        void ProgramStarted()
        {
            USBHostController.DeviceConnectedEvent += USBHostController_DeviceConnectedEvent;
            camera.CameraConnected += new Camera.CameraConnectedEventHandler(camera_CameraConnected);
            camera.PictureCaptured += new Camera.PictureCapturedEventHandler(camera_PictureCaptured);
            joystick.JoystickPressed += new Joystick.JoystickEventHandler(joystick_JoystickPressed);
            
            // Do one-time tasks here
            Debug.Print("Program Started");
        }

        void USBHostController_DeviceConnectedEvent(USBH_Device device)
        {
            Debug.Print("ID: " + device.ID + ", Interface: " +
                   device.INTERFACE_INDEX + ", Type: " + device.TYPE);

        }

        void camera_CameraConnected(Camera sender)
        {
            
            Debug.Print("Camera Status: " + camera.CameraReady);

            camera.CurrentPictureResolution = GTM.GHIElectronics.Camera.PictureResolution.Resolution320x240;

        }

        void joystick_JoystickPressed(Joystick sender, Joystick.JoystickState state)
        {
            Debug.Print("joystick pressed");
            camera.TakePicture();
        }

        void camera_PictureCaptured(Camera sender, GT.Picture picture)
        {
            Debug.Print("gotta picture");
            display.SimpleGraphics.DisplayImage(picture, 5, 5);
        }
    }
}

Program.generated.cs



//------------------------------------------------------------------------------
// <auto-generated>
//     This code was generated by the Gadgeteer Designer.
//
//     Changes to this file may cause incorrect behavior and will be lost if
//     the code is regenerated.
// </auto-generated>
//------------------------------------------------------------------------------

using Gadgeteer;
using GTM = Gadgeteer.Modules;

namespace GadgeteerApp1
{
    public partial class Program : Gadgeteer.Program
    {
        // GTM.Module defintions
		Gadgeteer.Modules.GHIElectronics.Display_T35 display;
		Gadgeteer.Modules.GHIElectronics.UsbClientDP usbClient;
		Gadgeteer.Modules.GHIElectronics.Camera camera;
		Gadgeteer.Modules.GHIElectronics.Joystick joystick;

		public static void Main()
        {
			//Important to initialize the Mainboard first
            Mainboard = new GHIElectronics.Gadgeteer.FEZSpider();			

            Program program = new Program();
			program.InitializeModules();
            program.ProgramStarted();
            program.Run(); // Starts Dispatcher
        }

        private void InitializeModules()
        {   
			// Initialize GTM.Modules and event handlers here.		
			usbClient = new GTM.GHIElectronics.UsbClientDP(1);
		
			camera = new GTM.GHIElectronics.Camera(3);
		
			joystick = new GTM.GHIElectronics.Joystick(9);
		
			display = new GTM.GHIElectronics.Display_T35(14, 13, 12, 10);

        }
    }
}


First web camera (Empia) returns:

Using mainboard GHIElectronics-FEZSpider version 1.0
Program Started
ID: 2700022344, Interface: 0, Type: 16
ID: 2700022344, Interface: 1, Type: 0
Camera Status: True
joystick pressed
joystick pressed
Camera ERROR : Unable to take picture. The camera is already busy taking a picture.

Second web camera (Logitech Pro 4000) returns:

Program Started
ID: 2700022344, Interface: 0, Type: 0
ID: 2700022344, Interface: 1, Type: 0
ID: 2700022344, Interface: 2, Type: 0
joystick pressed
Camera ERROR : Unable to take picture. Camera is not ready. Is the Camera connected?

After reading about the USB spec and downloading a USB snooper, I’m thinking I may use the USBRawdevice classes to write my own driver for the webcam. Anyone have any examples of using the USBRawDevice classes to communicate with an isochronous device? I’ve seen the driver example for the mouse using the these classes. I used that example to find the correct endpoint and inspect the device configuration but now I need to transfer some data!
Thanks