Showing posts with label android. Show all posts
Showing posts with label android. Show all posts

Sunday, September 5, 2010

Web-controlled watering can and vortex tube

UPDATE: Code added at the bottom of this post.


This is an interactive art project that I have been building for an upcoming exhibition. The idea for a web-controlled watering can come from the first "iphone watering can" that I helped build with a friend for Maker Faire a couple years ago. Search the internet/youtube for "iphone watering can" for details.





This new version uses a different drive mechanism and a PD control loop to make the watering can track the desired position in realtime. The interface works with any webkit browser. My collaborator and I have discussed using the iphone or android accelerometers to achieve control through phone tilting. I'm not sure if the tilt data is available to the web browser, though, and we are trying to make the interface run on as many platforms as possible. Any ideas?

The siteplayer webserver is extremely old technology and has many problems, but does work. I would explore using a hacked WRT router in the future for similar projects.






HTML file from Siteplayer webserver:
http://www.magconcept.com/watering/can.htm.txt

SPI file from Siteplayer webserver (simply to establish a server response):
http://www.magconcept.com/watering/serial.spi

Arduino code to get serial data from webserver and effect the PID control loop
http://www.magconcept.com/watering/watering_can.pde

Wednesday, December 9, 2009

More bluetooth a2dp debugging on Android Cyanogen

There are a few different failure modes that I have encountered, however these are the most obvious and annoying one:

12-09 17:56:53.949 D/BluetoothA2dpService( 944): state 00:02:76:64:F7:4A (/org/bluez/audio/device1) 0->1

12-09 17:57:01.453 E/BluetoothA2dpService.cpp( 944): onConnectSinkResult: D-Bus error: org.bluez.Error.Failed (Stream setup failed)
12-09 17:57:03.469 D/BluetoothA2dpService( 944): state 00:02:76:64:F7:4A (/org/bluez/audio/device1) 1->0




:10:40.214 D/BluetoothA2dpService( 99): state 00:02:76:64:F7:4A (/org/bluez/audio/device1) 0->1
12-11 18:10:40.214 E/BluetoothA2dpService.cpp( 99): onConnectSinkResult: D-Bus error: org.bluez.Error.Failed (%s)

12-11 18:10:50.574 D/BluetoothA2dpService( 99): state 00:02:76:64:F7:4A (/org/bluez/audio/device1) 1->0







12-22 14:48:39.111 D/AudioFlinger( 78): set output to A2DP
12-22 14:48:39.121 D/BluetoothA2dpService( 94): state 00:02:76:64:F7:4A (/org/bluez/audio/device0) 1->2
12-22 14:48:40.321 W/KeyCharacterMap( 148): Can't open keycharmap file
12-22 14:48:40.321 W/KeyCharacterMap( 148): Error loading keycharmap file '/system/usr/keychars/AVRCP.kcm.bin'. hw.keyboards.262149.devname='AVRCP'
12-22 14:48:40.321 W/KeyCharacterMap( 148): Using default keymap: /system/usr/keychars/qwerty.kcm.bin
12-22 14:48:40.391 W/Service ( 963): setForeground: ignoring old API call on com.android.music.MediaPlaybackService
12-22 14:48:41.403 W/AudioTrack( 78): obtainBuffer timed out (is the CPU pegged?) 0x58dd0 user=010c3b70, server=010c1370
12-22 14:48:41.403 E/A2dpAudioInterface( 78): a2dp_write failed err: -110
12-22 14:48:41.411 W/AudioFlinger( 78): write blocked for 1010 msecs
12-22 14:48:42.411 W/AudioTrack( 78): obtainBuffer timed out (is the CPU pegged?) 0x58dd0 user=010c4570, server=010c1d70
12-22 14:48:42.411 E/A2dpAudioInterface( 78): a2dp_write failed err: -110
12-22 14:48:42.421 W/AudioFlinger( 78): write blocked for 1010 msecs
12-22 14:48:43.431 W/AudioTrack( 78): obtainBuffer timed out (is the CPU pegged?) 0x58dd0 user=010c4f70, server=010c2770
12-22 14:48:43.431 E/A2dpAudioInterface( 78): a2dp_write failed err: -110
12-22 14:48:43.451 W/AudioFlinger( 78): write blocked for 1021 msecs
12-22 14:48:44.452 W/AudioTrack( 78): obtainBuffer timed out (is the CPU pegged?) 0x58dd0 user=010c5970, server=010c3170
12-22 14:48:44.462 E/A2dpAudioInterface( 78): a2dp_write failed err: -110
12-22 14:48:44.472 W/AudioFlinger( 78): write blocked for 1010 msecs
12-22 14:48:45.472 W/AudioTrack( 78): obtainBuffer timed out (is the CPU pegged?) 0x58dd0 user=010c6370, server=010c3b70
12-22 14:48:45.472 E/A2dpAudioInterface( 78): a2dp_write failed err: -110
12-22 14:48:45.482 W/AudioFlinger( 78): write blocked for 1009 msecs
12-22 14:48:45.721 D/dalvikvm( 938): GC freed 842 objects / 41408 bytes in 124ms
12-22 14:48:46.484 W/AudioTrack( 78): obtainBuffer timed out (is the CPU pegged?) 0x58dd0 user=010c6d70, server=010c4570

Debugging Bluetooth A2DP on Cyanogen G1

UPDATE: The connection problem turns out to be related to AVRCP, not A2DP. For some reason, the phone will connect to the A2DP device perfectly (with AVRCP) if the phone is awake when the A2DP device is powered on. If the phone is sleeping when the A2DP device is powered on, the connection process is different and AVRCP is lost. A2DP will be connected, though.

See this thread:
http://code.google.com/p/cyanogenmod/issues/detail?id=611



So, I'm still having problems with getting a reliable AVRCP and A2DP connection with Cyanogenmod 4.2.7.1 on my G1.

Here is a log from a successful connection:
12-09 09:52:36.660 I/BT Audio Gateway( 150): connect notification!
[[[ Setting up phone audio connection ]]]
12-09 09:52:41.730 D/BluetoothA2dpService( 99): Auto-connecting A2DP to sink 00:02:76:64:F7:4A
12-09 09:52:41.730 D/BluetoothA2dpService( 99): connectSink(00:02:76:64:F7:4A)
12-09 09:52:41.750 D/BluetoothA2dpService( 99): state 00:02:76:64:F7:4A (/org/bluez/audio/device1) 0->1
12-09 09:52:42.220 I/CheckinService( 99): Checkin success
12-09 09:52:42.280 W/GoogleHttpClient( 99): Blocked by block_crash_reports: http://android.clients.google.com/crash
12-09 09:52:42.280 I/CheckinService( 99): Crash report blocked
12-09 09:52:46.276 I/EventHub( 99): New device: path=/dev/input/event5 name=AVRCP id=0x10005 (of 0x6) index=6 fd=118 classes=0x1
12-09 09:52:46.286 I/EventHub( 99): New keyboard: publicID=65541 device->id=65541 devname='AVRCP' propName='hw.keyboards.65541.devname' keylayout='/system/usr/keylayout/AVRCP.kl'
12-09 09:52:46.286 I/KeyInputQueue( 99): Device added: id=0x10005, name=AVRCP, classes=1
12-09 09:52:46.286 I/WindowManager( 99): Config changed: { scale=1.0 imsi=0/0 loc=en_US touch=3 keys=2/1/2 nav=3 orien=1 layout=18}
12-09 09:52:46.946 D/A2dpAudioInterface( 83): setParameter a2dp_sink_address,00:02:76:64:F7:4A
12-09 09:52:46.965 D/AudioFlinger( 83): set output to A2DP
12-09 09:52:46.975 D/BluetoothA2dpService( 99): state 00:02:76:64:F7:4A (/org/bluez/audio/device1) 1->2
12-09 09:53:07.738 D/dalvikvm( 99): GC freed 18113 objects / 1104992 bytes in 206ms
12-09 09:53:07.798 D/OpenSSLSessionImpl( 99): Freeing OpenSSL session
12-09 09:53:07.948 I/ActivityManager( 99): Start proc com.android.music for broadcast com.android.music/.MediaButtonIntentReceiver: pid=1803 uid=10017 gids={3002, 3001, 3003, 1015}
12-09 09:53:07.948 I/ActivityManager( 99): processNextBroadcast: waiting for ProcessRecord{43e9d498 1803:com.android.music/10017}
12-09 09:53:07.988 I/ActivityManager( 99): processNextBroadcast: waiting for ProcessRecord{43e9d498 1803:com.android.music/10017}
12-09 09:53:08.038 I/ActivityManager( 99): processNextBroadcast: waiting for ProcessRecord{43e9d498 1803:com.android.music/10017}
12-09 09:53:08.068 I/ActivityManager( 99): processNextBroadcast: waiting for ProcessRecord{43e9d498 1803:com.android.music/10017}
12-09 09:53:09.108 D/A2DP ( 83): bluetooth_start
12-09 09:53:09.108 E/A2DP ( 83): BT_START failed : I/O error(5)
12-09 09:53:09.108 D/A2DP ( 83): bluetooth_configure
12-09 09:53:09.108 D/A2DP ( 83): bluetooth_a2dp_hw_params sending configuration:
12-09 09:53:09.108 D/A2DP ( 83): channel_mode: JOINT STEREO
12-09 09:53:09.108 D/A2DP ( 83): frequency: 44100
12-09 09:53:09.108 D/A2DP ( 83): allocation_method: LOUDNESS
12-09 09:53:09.108 D/A2DP ( 83): subbands: 8
12-09 09:53:09.108 D/A2DP ( 83): block_length: 16
12-09 09:53:09.108 D/A2DP ( 83): min_bitpool: 2
12-09 09:53:09.108 D/A2DP ( 83): max_bitpool: 32
12-09 09:53:09.118 D/A2DP ( 83): MTU: 895
12-09 09:53:09.118 D/A2DP ( 83): frame_duration: 2902 us
12-09 09:53:09.118 D/A2DP ( 83): allocation=0
12-09 09:53:09.118 D/A2DP ( 83): subbands=1
12-09 09:53:09.118 D/A2DP ( 83): blocks=3
12-09 09:53:09.118 D/A2DP ( 83): bitpool=32
12-09 09:53:09.118 D/A2DP ( 83): bluetooth_start
12-09 09:53:09.168 D/BluetoothA2dpService( 99): state 00:02:76:64:F7:4A (/org/bluez/audio/device1) 2->4
12-09 09:53:13.505 D/KeyguardViewMediator( 99): wakeWhenReadyLocked(82)
12-09 09:53:13.505 D/KeyguardViewMediator( 99): handleWakeWhenReady(82)
12-09 09:53:13.515 D/KeyguardViewMediator( 99): pokeWakelock(5000)
12-09 09:53:13.535 D/Sensors ( 99): sensors=00000001, real=00000001
12-09 09:53:13.535 D/AKMD ( 88): Compass OPEN
12-09 09:53:13.695 I/Bluetooth AT sent( 150): +CIEV: 5,5
12-09 09:53:13.765 D/SurfaceFlinger( 99): Screen about to return, flinger = 0xff388
12-09 09:53:14.455 D/KeyguardViewMediator( 99): pokeWakelock(5000)
12-09 09:53:15.795 D/A2DP ( 83): a2dp_stop
12-09 09:53:15.795 D/A2DP ( 83): bluetooth_stop
12-09 09:53:15.855 D/BluetoothA2dpService( 99): state 00:02:76:64:F7:4A (/org/bluez/audio/device1) 4->2




Here is the log from a connect-then-disconnect-then-reconnect (without AVRCP)
12-08 15:57:02.213 D/BluetoothA2dpService( 99): Auto-connecting A2DP to sink 00:02:76:64:F7:4A
12-08 15:57:02.213 D/BluetoothA2dpService( 99): connectSink(00:02:76:64:F7:4A)
12-08 15:57:02.223 D/BluetoothA2dpService( 99): state 00:02:76:64:F7:4A (/org/bluez/audio/device1) 0->1
12-08 15:57:02.553 I/ActivityManager( 99): Stopping service: com.android.calendar/.AlertService
12-08 15:57:02.593 I/ActivityManager( 99): Stopping service: com.android.mms/.transaction.SmsReceiverService
12-08 15:57:02.733 E/BluetoothA2dpService.cpp( 99): onConnectSinkResult: D-Bus error: org.bluez.Error.Failed (Stream setup failed)
12-08 15:57:03.393 I/BluetoothEventLoop( 99): Allowing incoming A2DP connection from 00:02:76:64:F7:4A
12-08 15:57:04.753 D/BluetoothA2dpService( 99): state 00:02:76:64:F7:4A (/org/bluez/audio/device1) 1->0
12-08 15:57:09.658 D/BluetoothA2dpService( 99): state 00:02:76:64:F7:4A (/org/bluez/audio/device1) 0->1
12-08 15:57:09.658 D/A2dpAudioInterface( 83): setParameter a2dp_sink_address,00:02:76:64:F7:4A
12-08 15:57:09.668 D/AudioFlinger( 83): set output to A2DP
12-08 15:57:09.718 D/BluetoothA2dpService( 99): state 00:02:76:64:F7:4A (/org/bluez/audio/device1) 1->2


Disabled phone audio, and now only have A2DP connection. AVRCP looks fine in log, but doesn't work at all:
12-09 09:57:51.661 I/BluetoothEventLoop( 99): Allowing incoming A2DP connection from 00:02:76:64:F7:4A
12-09 09:57:54.331 I/EventHub( 99): New device: path=/dev/input/event5 name=AVRCP id=0x10005 (of 0x6) index=6 fd=31 classes=0x1
12-09 09:57:54.341 I/EventHub( 99): New keyboard: publicID=65541 device->id=65541 devname='AVRCP' propName='hw.keyboards.65541.devname' keylayout='/system/usr/keylayout/AVRCP.kl'
12-09 09:57:54.341 I/KeyInputQueue( 99): Device added: id=0x10005, name=AVRCP, classes=1
12-09 09:57:54.351 I/WindowManager( 99): Config changed: { scale=1.0 imsi=0/0 loc=en_US touch=3 keys=2/1/2 nav=3 orien=1 layout=18}
12-09 09:57:54.551 D/dalvikvm( 99): GC freed 7743 objects / 388840 bytes in 208ms
12-09 09:57:58.261 D/BluetoothA2dpService( 99): state 00:02:76:64:F7:4A (/org/bluez/audio/device1) 0->1
12-09 09:57:58.371 D/A2dpAudioInterface( 83): setParameter a2dp_sink_address,00:02:76:64:F7:4A
12-09 09:57:58.381 D/A2DP ( 83): bluetooth_init
12-09 09:57:58.391 D/A2DP ( 83): bluetooth_configure
12-09 09:57:58.391 D/A2DP ( 83): bluetooth_a2dp_hw_params sending configuration:
12-09 09:57:58.391 D/A2DP ( 83): channel_mode: JOINT STEREO
12-09 09:57:58.391 D/A2DP ( 83): frequency: 44100
12-09 09:57:58.391 D/A2DP ( 83): allocation_method: LOUDNESS
12-09 09:57:58.391 D/A2DP ( 83): subbands: 8
12-09 09:57:58.391 D/A2DP ( 83): block_length: 16
12-09 09:57:58.391 D/A2DP ( 83): min_bitpool: 2
12-09 09:57:58.391 D/A2DP ( 83): max_bitpool: 32
12-09 09:57:58.421 D/A2DP ( 83): MTU: 895
12-09 09:57:58.421 D/A2DP ( 83): frame_duration: 2902 us
12-09 09:57:58.421 D/A2DP ( 83): allocation=0
12-09 09:57:58.421 D/A2DP ( 83): subbands=1
12-09 09:57:58.421 D/A2DP ( 83): blocks=3
12-09 09:57:58.421 D/A2DP ( 83): bitpool=32
12-09 09:57:58.421 D/AudioFlinger( 83): set output to A2DP
12-09 09:57:58.431 D/BluetoothA2dpService( 99): state 00:02:76:64:F7:4A (/org/bluez/audio/device1) 1->2

Tuesday, November 10, 2009

Rooting and modding an HTC Dream (Google G1)

This project all started with my plan to abandon music CDs and use my G1 phone to carry all of my music. Here's how my ideal situation would work: When I get in my car, I would like to press a button and hear a series of random songs from my music collection that is stored on my computer. Note that I didn't say anything about connecting wires, syncing, downloading, looking through settings or album lists, etc. In the ideal plan, the music would all be handled seamlessly without any thought on my mind except "play".

By the way, I have been using MediaMonkey to handle my music, and I really like it:
http://www.mediamonkey.com

The G1 is a very flexible device, so I figured this would be no problem. However, there are problems. First, the audio quality coming out of the usb->headphone jack adapter on the G1 is truly dreadful. I am not being a stuck-up about this. I mean it's just plain bad. The sound has no bass (it seems anything below 150Hz is completely gone). There are a lot of compression artifacts evident in cymbal sounds, and the high-mids are unusually harsh-sounding. Finally, the overall amount of signal coming out of the headphone jack is very low. Before anyone accuses me of using low-quality MP3, let me say that I made these MP3 myself from CDs and used 320kbit for some test files. They are good MP3 and sound perfectly fine on normal sound systems.

So, connecting the G1 to my car's sound system via a headphone jack, while slightly inconvenient may not work at all because of the low quality. This prompted me to wonder if the Android software had any control over the sound output. As a matter of fact. It does, and it's possible the designers purposefully cut everything below 150Hz for use with speech-only audio.
http://forum.xda-developers.com/showthread.php?t=517745&page=120
Ah, nothing like a 120-page thread. I'm sure it will only take a few hours to read it.

Anyway, the short story is that a developer named meltus has found three audio files in the system/etc directory of the android operating system that have some effect on the sound processing. I was intrigued and wanted to edit the files myself to see how much of the audio quality was dependent upon software. Unfortunately, the android system will not allow anyone to edit system files (even me, the owner of the damn phone). I instantly decided to "root" the phone so that I could investigate the full potential of the device.

Gaining root access is possible on the G1 by a few different ways, but the information available on the web is sketchy. There are only two groups of people who root their phones: 1. Serious developers who are so into Android, that they don't have time to explain the process to newbies 2. Newbies who want root access but don't know what it is. There is a major echo chamber on the web just filled with mindless stupid comments from people hacking away at their phones. I am not against hacking, I am only against repeating misinformation in forums and wasting bandwidth by repeating hearsay over and over again.

Anyway, I followed Cyanogen's instructions, and didn't have any problems at all:
http://wiki.cyanogenmod.com/index.php/Full_Update_Guide_-_G1/Dream_Firmware_to_CyanogenMod
This guy deserves major props for writing a clear, concise set of directions.

The process of downgrading to RC29 is not that hard, and the whole process took less than an hour.

So, here it is, and I know have complete control of my own phone.

The next steps will be to see how much better the audio quality can be made, testing bluetooth high-quality audio, syncing MP3 over Wifi, installing a bluetooth receiver in the car, etc.