Interfacing android and arduino through an audio connection.

Thursday, 3 November 2011

Androino is already Playing!!!









Next Step: Link Android & TicTacToe using Jack modem for Android

Tuesday, 27 September 2011

Finally it worked!

Finally I could establish Serial Communication using audio between Arduino and an Android device.  This can be done thanks to the FSK modulation, when the data '0 'is a low frequency carrier, when the data '1' will send a high-frequency carrier.


The communication is biderectional, it can go from the Arduino to the Android device and vice versa. When you start the application, it is ready to be sent and received in ASCII mode. The data received is stored in a buffer and then will appear on the screen, there is no real-time display.
After stablishing the communication in both ways, I decided to obtain real data from real world, so I decided to measure the temperature of my workroom.
I connected a thermistor to one of the Analog input pin in the arduino and using the data it obtains I am able to read them in my Andorid device through the audio port. The speed of communication I get is around 315 bps, it is not to much, but for the moment it is enough for the data I'm testing. In a future I will try to increase the amount of data I can send.



Monday, 12 September 2011

Demodulation in Android device (II): Reading sound.

After being ablo to record sound with the LG-GT540, I needed to read the data that I obtained from the MIC.

In order to do this, I used the ByteBuffer class:

public ByteBuffer wrap (byte [] array, int start, int byteCount)

Creates a new byte buffer by wrapping the given byte array.
The new buffer's position will be start, limit will be start + byteCount, capacity will be the length of the array.
 
Parameters
array the byte array which the new buffer will be based on.
start the start index, must not be negative and not greater than array.length.
byteCount the length, must not be negative and not greater than array.length - start.
Returns 
     The created byte buffer.
 

public abstract short  getshort()

Returns the short at the current position and increases the position by 2.
The 2 bytes starting at the current position are composed into a short according to the current byte order and returned.
Returns
      the short at the current position.
ByteOrder class:

public static final ByteOrder LITTLE_ENDIAN

Little endian means that the first byte (lowest address) is the least significant, and the last byte (highest address) is the most significant.

With all these classes and functions, I was able to analyze what I recorded.



Friday, 2 September 2011

They are here!!

After one month waiting for it, I already have here my Audio Jack modem for Android (and iPhone).   
   
                                                 



With this board, data communication between Arduino and Android become possible . The communication speed is 1225bps. It is suitable for a small amount of data communication like switch inputs and sensor information.

The audio jack is included in this kit but not pre-soldered. Also, you may need a pin header or a pin socket to this board. But neither pin header nor pin socket is included, so you have to prepare it by yourself. 

Disclaimer

* Because data communications with this device uses audio, data corruption may occur sometimes. I consider incorporating checksum processing and retrying.
* Please set the device's volume maximum.

Connection

Please use gold plated shielded cables. The shorter the cable, the better. In order to minimize the communications error


Connect to Arduino as follows (right side is the Arduino's pin.)
FSKOUT → D3
GND → GND
VCC → VCC
FSKIN → D6
AIN1 → D7

Volume Adjustment

Measure the voltage on AIN1 with tester to make it (VCC / 2) + 300mV.
5V VCC: 2.7V AIN1
3.3V VCC: 1.95V AIN1

Thursday, 1 September 2011

LG GT540 is alive!!!

After trying to use LG official software in order to upgrade my GT540, I had some problems as I already wrote down here. That's why I decided to use the KDZ UPDATER, in the next lines I will explain how I could make it:

Issues to consider:
  • I will NOT take responsibility for possible errors that could affect the device.
  • I suggest to back up every app, docs, contacts...
Steps:
  1. Download the firmware, you can choose from this list. I used and suggest: V20A
  2. Download and extract the KDZ UPDATER ENGLISH.
  3. Download and install the LG GT540 driver from offical website.
  4. LG GT540 -> Settings->Applications->Development-> Enable USB debugging.
  5. Settings->SD card & phone storage->Disable Mass storage only.
  6. Connect your LG to your computer with the USB link.
  7. Execute KDZ_FW_UPD.exe and select 3GQCT.
  8. Look for the archive KDZ that we previously downloaded and press the long button down there.
  9. The GT540 will star a process that might take for 5 minutes, the device will be set up in Emergency Mode several times, but don't worry about that. You don't need to do anything. DON'T TRY TO DISCONNECT THE DEVICE, DON'T INTERRUPT THE PROCESS, DON'T SHUTT IT OFF. Once it finishes the proecces it will be restarted by default. It will be like the first time you used it, like if it were recently made.
  10. KDZ Updater will anounce that the process is over, so here is when we can disconnect the GT540,
Links:
  1. lg.clubmobile.es
  2. android.modaco.com

Wednesday, 31 August 2011

Upgrading LG gt540

As I wrote before, I had some problems during the upgrading of my LG gt540, while I was updating it my computer stuck and then I couldn't restart the device.
One solution for this trouble:

1. Unplug USB
2. Remove the battery
3. Hold the volume down button (LHS of phone) and reinsert USB lead at the same time
4. I then re-ran the update program.

LG Program Download
USB Driver Download

When you install the update be patient!!!!!! It takes forever

Wednesday, 24 August 2011

Demodulation in Android device (I): Recording sound.

First of all, what I have to say is not everything goes ok at the first attempt, I'm telling this because I decided to upgrade my LG gt540 to 2.1 Android version, but something went wrong during the process :(

While I was updating it, my computer stuck so I had to restart it. Then I tried to power on my LG device and never came back on again, I could only see the LG logo. That's why I need to reboot my device, but I don't think this take my long time because there is a lot of information about it on the internet.

Well, while I try to fix this accident I'm working on how to demodulate the signals from the arduino in an Android device.

I'm trying some classes in API Level 3:
1. AudioRecord:
The AudioRecord class manages the audio resources for Java applications to record audio from the audio input hardware of the platform. This is achieved by "pulling" (reading) the data from the AudioRecord object. The application is responsible for polling the AudioRecord object in time using one of the following three methods: read(byte[], int, int), read(short[], int, int) or read(ByteBuffer, int). The choice of which method to use will be based on the audio data storage format that is the most convenient for the user of AudioRecord.
Upon creation, an AudioRecord object initializes its associated audio buffer that it will fill with the new audio data. The size of this buffer, specified during the construction, determines how long an AudioRecord can record before "over-running" data that has not been read yet. Data should be read from the audio hardware in chunks of sizes inferior to the total recording buffer size.

public AudioRecord (int audioSource, int sampleRateInHz, int channelConfig, int audioFormat, int bufferSizeInBytes)

int audioSource: MIC
int sampleRateInHz: he sample rate expressed in Hertz. 44100Hz is currently the only rate that is guaranteed to work on all devices
int channelConfig: CHANNEL_IN_MONO is guaranteed to work on all devices.
int audioFormat: the format in which the audio data is represented. PCM 16 bit per sample. Guaranteed to be supported by devices.
int bufferSizeInBytes: getMinBufferSize
1a. getMinBufferSize

public static int getMinBufferSize (int sampleRateInHz, int channelConfig, int audioFormat)

Returns the minimum buffer size required for the successful creation of an AudioRecord object. Note that this size doesn't guarantee a smooth recording under load, and higher values should be chosen according to the expected frequency at which the AudioRecord instance will be polled for new data.
  1. AudioTrack
The AudioTrack class manages and plays a single audio resource for Java applications. It allows to stream PCM audio buffers to the audio hardware for playback. This is achieved by "pushing" the data to the AudioTrack object using one of the write(byte[], int, int)and write(short[], int, int) methods.

public AudioTrack (int streamType, int samplieRateInHz, int channelConfig, int audioFormat, intBufferSizeInBytes, int mode)

int streamType: STREAM_MUSIC
int samplieRateInHz: 44100
int channelConfig: CHANNEL_IN_MONO
int audioFormat: PCM 16 bit
int bufferSizeInBytes: getMinBufferSize
int mode: MODE_STREAM