Thursday, October 31, 2013

Setting up Platform for Project XiCam

I suppose the upside to the USB debacle is I now have a clean slate to start working on this project.  This isn't the most ideal starting point, but I now have an HP dv4 Notebook running the factory install of Windows Vista (circa 2008).  It has an Intel Core2 Duo 2.1GHz processor and 4GB RAM which should be good enough for my purposes here.  I have to remember how to get rid of the various annoying registration and update reminders which are all more or less pointless now, but I digress.

First step was install eclipse.  Went with the the standard version of the Kepler release, since I don't expect to do much outside of Java programming.  In fact, it probably would have made more sense to install the Java 7 SDK first, but it doesn't really make a difference.  Both installed and run without any problems.

Next step was to install VirtualBox so I have something to write lower level stuff in C/C++.  I used to use Cygwin, but that comes with some extra complications that I'd rather not deal with.  Running Linux in a VM not only gives you the desktop appearance but also adds a nice layer of protection to help keep you from doing anything really damaging to your computer (like muffing up your USB host controller).  I had intended to install Ubuntu 12.04 64-bit on the guest machine, but apparently 64-bit guests are not supported on this computer (it does, however work on 64-bit Windows 7 on the Intel quad-core I have at work, so I think this may be more an issue with the CPU on the notebook not supporting virtualization rather than an issue with VirtualBox).

Installed Ubuntu 10.04 for x86 architecture on the guest machine.  I may have to deal with the 800x600 screen, which actually isn't so terrible.  At least the USB 2.0 passthrough apparently works!
Ubuntu 10.04 running in VirtualBox with the mouse and camera showing up in lsusb.
Last, I installed the Android SDK plugin for Eclipse.  Release 19 (Kit Kat) is fairly recent and today is the first day I've noticed it in the SDK manager.  I would normally have installed the SDK for the last five or six releases so that I could check back-compatibility, but I just included this latest release for now.  I build a virtual device with the general specs of the ASUS tablet.  It runs pretty slow and takes several minutes to boot, so it may need some tweaking.
Tablet emulated using the Android SDK plugin in Eclipse.

XiCam Project on Hold until USB Issue is Solved

USB host controller on the HP appears to be broken.  From what I'm reading, the driver is owned by Microsoft, and resides on the chipset, which partially explains why reinstalling Ubuntu didn't solve the problem.  I have the recovery disks, so I'm going to try to do the recovery tonight.  If that works, then I'll install Ubuntu on a VM instead of having that as the main OS.  This might cause some difficulty passing USB connections through, but I'd rather deal with that than breaking the driver again, then having to go through this mess all over again.  Here's the details of what I've done so far:
  • SD card reader still worked, so I used the 8GB micro SD I found for the camera to save my latest work.
  • Did fresh install of Ubuntu.  This solved the infinite login loop problem, but not the USB issue.
  • Tried following the advice here (link), but that didn't work.  I did, however, notice that the system recognized a device was there, it just wasn't responsive.
  • I wanted to keep the 8GB card in the camera, so I used the card reader to move the saved data to the 32GB card in my phone and wiped the data from the 8GB card.

I did a full factory restore on the HP, but that still didn't fix the USB issue.  Plugged in the mouse and Windows said the device wasn't recognized.  Opened up the device manager and uninstalled all of the USB device drivers.  After hitting check for new devices, they all came back and no errors came up, but USB ports still didn't work.  The next step is to do a BIOS update.  After that, I'm not sure what else to do.


Project XiCam Back on Track

Well, it was quite a debacle, but I finally have the HP back in working condition.  The USB issue turned out to be a hardware-level problem and required a full BIOS update to fix.  Here's a summary of the problem I encountered and what it took to fix it:
  • Plugged my phone into one of the USB ports at which point the computer stopped responding to the mouse.  I thought the error might have come from a conflict after installing libusb-1.0-0 with its corresponding dev package.
  • Ran apt-get remove the packages I had just installed and it removed a whole bunch of critical packages that were reassigned as dependencies.  After install, it realized it needed to re-update them all so the whole thing was a mess.
  • Rebooted computer and found the OS in an infinite loop on the logon screen.  When I deliberately put in a wrong password, it indicated the bad password with a red "invalid password" message.  When I entered the correct one, the screen would flash an error for 1/2-second an return to the logon screen.  I tried to find a solution on-line.  The most common cause of the problem was an .Xauthority file getting set to the wrong permissions.  This was not the problem, though.
  • Found an old Ubuntu install disk and started the computer in live mode.  I had access to all the old directories and tried fixing the problem from there without any luck.  Eventually I resigned myself to reinstalling the OS so I backed everything up on a SD card (the USB ports were still not responding, which I think should have been a hint that an OS reinstall wouldn't help).
  • Reinstalled Ubuntu 12.04 but USB ports still didn't work.  Checked /var/log/syslog and there were repeated error messages.  The messages would change when I connected the mouse, but the system never responded to the mouse.  Did some more checking of the interwebs but none of the fixes I found worked in my case.  Checked HP support site and started researching USB host drivers, which apparently, for my computer, are owned by Microsoft, so I decided to restore the HP to factory default.
  • Reinstalled Windows Vista from the recovery disks.  This still didn't solve the problem.
  • As a last resort, I downloaded the BIOS update.  This required Windows to run the installer.  This finally worked!
Lessons learned:
  • Take extra care installing USB packages in Ubuntu.  If there's a conflict, you won't be able to remove them without affecting a lot of other critical software.
  • The USB drivers on HP notebooks are integrated as part of the motherboard chipset.  If something goes wrong with it, then you need to flash the BIOS.  In the case of this computer, this requires running from Windows (I've heard many complaints about Vista, but to be honest it's always worked well for me; I'm also a fan of Windows 7).

Tuesday, October 29, 2013

Project XiCam -- Part 1

Calling this project XiCam for lack of a better idea.  The concept is this:  Hack one of our old digital cameras so that I can control it from my Android tablet.  Why do this?  I'll let you know when I figure that out for myself.  My goal is to create some attachment mechanism so I can position the camera lens to the eyepiece of my telescope.  I'd like to see what options I can control over the USB port.  If I'm lucky, I might be able to manipulate settings beyond the controls provided by the on-board UI.

Samsung ST100 digital camera.
Here's what I'm working with:
  •  Samsung ST100 14.2 Mpx digital camera
    • 5x optical zoom
    • 8GB micro SD
  • ASUS TF201 Transformer prime
    • NVIDIA Tegra 3 quad-core CPU
    • 10.1" screen
    • Android Ice Cream Sandwich OS
    • ASUS  Tablet with keyboard dock.
      HP Pavilion dv4 notebook
    • 32GB micro SD
  • HP Pavilion dv4
    • Intel core 2 duo CPU
    • Ubuntu 12.04 LTS OS
    • Eclipse Juno IDE + Android SDK + ADK
Android has some good functionality for USB communication, unfortunately there's no good way to develop software on the tablet itself (I installed one of the free IDE's, which appeared to be inspired by eclipse, but there were limitations due to screen size, responsivity of keyboard, and other reasons which made that option impractical).  My general approach will be to develop some basic USB communication software on the notebook, using an emulated tablet as the target.  Once that's working, install it on the ASUS  and make sure the USB interface actually works.  Next, further develop the software to perform some basic control operations on the camera.  Then finish by adding some pretty GUI controls to control exposure and read image data into the tablet and present it on the screen.

Before I can do any of these things, I need to develop an understanding of USB protocol.  I spent the last couple of days researching this and the communication format doesn't seem terribly complicated.  However, many USB products, especially digital cameras, use proprietary formats which require their own drivers.

I ran into a big problem, likely due to installing libusb on the HP.  Mouse suddenly stopped working.  Thought it was the battery but it worked on another computer.  When I checked /var/log/syslog, it was getting overloaded with messages about not being able to enumerate the USB devices.  I tried removing libusb-1.0-0 and libusb-1.0-0-dev (the exact packages I installed), then the whole thing went to pot.  When the system rebooted after removing and updating the packages, it got stuck in some weird loop where the login screen would come up, I'd enter my password (I had setup the OS to not go to a login screen, so even that was weird), another screen would come up with error messages, but it only stayed for about 1/2 second, so I couldn't tell what the errors were, then went back to the login screen.

I couldn't find the install disk to run the live version and potentially fix the problem, but that was lost.  I found the ISO for 10.04 on an external drive, so I burned a new copy and am running that right now.  Even in "live" mode, the USB ports aren't working, so even though I can view my directories, I can't save the files to it.  Instead, I took the SD card from the camera and am tarballing the essential stuff and saving it to that.  Thankfully that works.

Eventually, I plan on doing this kind of work in a virtual machine running on Windows.  This way when I encounter big problems with the OS, I don't wind up losing everything.  Unfortunately, can't do that until I get a new computer.