Interfacing android and arduino through an audio connection.

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

Monday, 22 August 2011

Nice find: Getting source code from an APK file

Mr.Wizard and prankul garg:

"procedure to decoding .apk files---step wise method-->

step 1:

make a new folder and put .apk file (which you want to decode) now rename this .apk file with extension .zip (eg:rename from filename.apk to and save you get classes.dex files this stage you are able to see drawable but not xml and java cont...

step 2:

now extract this zip apk file in the same folder(in this eg or case NEW FOLDER). now dowmload dex2jar from this link and extract it to the same folder (in this case NEW FOLDER) open command prompt and reach to that folder (in this case NEW FOLDER)....after reaching write "dex2jar classes.dex" and press you get classes.dex.dex2jar file in the same download java decompiler from and now double click on jd-gui and click on open file then open classes.dex.dex2jar file from that you get class all these class file (click on file then click "save all sources" in jd-gui) src this stage you get source...but xml files are still cont...

step 3:

now open another new folder and put these files

  1. put .apk file which you want to decode

  2. download apktool using google and put in the same folder

  3. download framework-res.apk file using google and put in the same folder

  4. Open a command window

  5. Navigate to the root directory of APKtool and type the following command: apktool if framework-res.apk

  6. apktool d "fname".apk ("fname" denotes filename which you want to decode)

now you get a file folder in that folder and now you can easily read xml files also.

step 4:

it's not any step just copy contents of both folder(in this case both new folder)to the single one

and now enjoy wid source code... "

Video Tutorial APKtool

Found in:

Friday, 5 August 2011

System Architecture

This project aims to build an Arduino-powered interface to get data from any real-world, analog sensor into a smartphone (Android device) using the audio port as the communication channel between both platforms.

Sensor: obtain some values we want to know, they can be temperature, pressure, humidity, amount of light... These values are related to a voltage, a continuous value that is measured in certain periods of time.

We can measure current temperature of the environment using a simple temperature sensor LM335 and an Arduino with the help of a small circuit and a simple Arduino code.

Arduino: the values generated from the sensor are modulated by the microcontroller, using ADC. Using an Arduino library called SoftModem, I am able to configure the microcontroller in order to obtain a FSK modulation of the values. Wherein data bits are communicated by modulation and demodulation — basically encoding data in specific audio tones sent over an audio channel. Some of you oldsters might remember the weird sounds emanating from the early telephone modems? That was FSK

With this what we obtain is an analog signal related to the value from the sensor, this is the modulation part.

Now we want to work with this signal in our mobile device, as we already decided and commented here, this is going to be done through the audio port. That's why we need and are going to use the Softmodem board, which allows us to connect the arduino board and our mobile device with an audio jack cable.

Five terminals to connect to the Arduino (FSKOUT · GND · VCC · FSKIN · AIN) has been equipped with a pin jack plug into the 3.5mm plug 4 poles for connecting to a cellular phone.

Using compatible FSK libraries on both the Arduino side and the Android side, we can actually accomplish bi-directional communication between our sensor rig and our mobile device. The Arduino gives us the onboard computing power to be able to both write and read data using FSK. As a first example, we’ll try to establish a unidirectional connection, sending data from the sensor to de Android device only. Still, we need to do FSK on both the Arduino side (modulation, or encoding the sensor data as audio) and the Android side (Application) (demodulation, or decoding the audio as data). So, all the raw materials are here for a bi-directional connection.

We need to decide in which frequencies we are going to encode:

This library is setup to encode data in shifts between audio frequencies 4000Hz (LOW) and 8000Hz (HIGH).

First, you need the sensor, Arduino and supporting circuitry for gathering data. For this we connect the sensor which will feed the Arduino.

You will also need to build some simple circuitry and load some code onto the Arduino.

Final objective: Android device <- (softmodem)->Arduino<-(rs232) are communicating said configuration->PC.