Monday, December 10, 2012

3-3. Basic Programming of the Android Controller/Camera Part III

Finally, we get to the actual image capture for the Android brain!  After getting the default camera app working, my goal was to be able to get preview frame captures from the camera at a decent frame rate (at least a couple times a second) into a RGB pixel array.  In order to achieve this goal, I needed to be able to write and deploy a new Android app to the i.MX53. Google has a lot of tools to help a developer test his Android app, but figuring it out for the i.MX53 took a bit of head-scratching.  I basically followed these steps.



Micro USB port on the i.MX53 QSB
  1. Connect a micro-USB to USB cable between the QSB and your development machine (this is very important because it won't work over the port you used for boot-loading).
  2. Install Android SDK on your development machine.
  3. Install the Google Android USB driver.
  4. Generate a configuration ini file by typing 'android update adb' in the <android-sdk>/tools directory.  This file will be created in your .android directory and will be called adb_usb.ini.  Open this file and enter the Freescale device ID '0x15a2' on the last line.
  5. Start up communication between the QSB and development machine by going to <android-sdk>/platform-tools and typing 'adb devices'.  This will start up the Android Debugging Server and try to connect to the i.MX53.  You should see the device listed.
If this sounds painful, it was.  Each one of these steps I had to research came from a different source.  The most difficult one to figure out was the micro USB port step (#1).  This was confusing because the i.MX53 has so many different USB ports you can use so it was hard to figure out which port supported what.  Once I got hooked up, I was able to fire up the Eclipse IDE and install the Android plugin for it.  Included in the Android SDK is a sample Camera preview (<android-sdk>/samples/android-16/ApiDemos/src/com/example/android/apis/graphics/CameraPreview.java).  In order to get a preview image in an RGB array, we can take this code as a base and add a PreviewCallback object, according to this blog.  Installing your application onto the i.MX53 is simply done through running the Eclipse project.  The android plugin will automatically try to connect to a specified attached device and install the application.  It will also try to run it; so you can see the results of the logs on the i.MX53 in the logcat viewer.