Interfacing android and arduino through an audio connection.

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.
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.
     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.
      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. 


* 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.


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.)
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...
  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,