Click here to Skip to main content
13,762,393 members
Click here to Skip to main content
Add your own
alternative version

Stats

8.4K views
16 bookmarked
Posted 1 May 2015
Licenced CPOL

Using the Audio Jack as Data Interface on Android Systems

, 1 May 2015
Rate this:
Please Sign up or sign in to vote.
As one of the interfaces on mobile devices and tablets, the key function of the audio jack is to play music. However, its other usage cannot be ignored—the audio jack can also be used to transmit data.

Editorial Note

This article is for our sponsors at CodeProject. These articles are intended to provide you with information on products and services that we consider useful and of value to developers

Intel® Developer Zone offers tools and how-to information for cross-platform app development, platform and technology information, code samples, and peer expertise to help developers innovate and succeed. Join our communities for Android, Internet of Things, Intel® RealSense™ Technology and Windows to download tools, access dev kits, share ideas with like-minded developers, and participate in hackathon’s, contests, roadshows, and local events.

Overview

As one of the interfaces on mobile devices and tablets, the key function of the audio jack is to play music. However, its other usage cannot be ignored—the audio jack can also be used to transmit data.

More usages of the audio jack to connect devices are being developed all the time. Peripherals like iHealth Lab’s Glucometer[1] (blood sugar calculator), the Irdroid[2] (provides infrared remote functions to control TVs, set-top boxes, and audio components), and Flojack*[3], an NFC reader (creates near-field-communications functionality for interaction with NFC tags or mobile devices) are made possible through audio jack connectivity.

Since wearable devices and peripherals have broad market prospects, I believe that the audio jack will be the prime data communication portal. In this article I will explain more details of this new feature.

Introduction

The audio jack interface has two standards: OMTP and CTIA[4]. OMTP is an international standard; ATIS is an American standard, which is used on the Apple iPhone* and iPad*. They are different with V-Mic and GND position, the difference are shown in Figure 1.

Figure 1. OMTP & CTIA

How to transmit data

When we send a 0x00FF data value, the first step is to convert the digital data value to an analog signal. We need to modulate the data value. Normally, we use a sine wave carrier for the analog signal.

Figure 2. FSK[5] modulation signal[6]

The second step, in Android systems, is to call the audioTrack API[7] function to play the buffer. The following code sends data to the buffer using the audioTrack function.

public void send(byte[] bytes_pkg) {
		int bufsize = AudioTrack.getMinBufferSize(8000,
				AudioFormat.CHANNEL_OUT_MONO,
				AudioFormat.ENCODING_PCM_16BIT);
		AudioTrack trackplayer = new AudioTrack(AudioManager.STREAM_MUSIC,
				8000, AudioFormat.CHANNEL_OUT_MONO,
				AudioFormat.ENCODING_PCM_16BIT, bufsize, 
AudioTrack.MODE_STREAM);
		trackplayer.play();
		trackplayer.write(bytes_pkg, 0, bytes_pkg.length);
	}

How to receive data

As a receiver, we need to translate the analog signal to a data value, demodulate the signal to remove the carrier signal, and decode the data by protocol. The protocol can be a public data format or private definition protocol.

Figure 3. Demodulate the signal6]

In Android systems, we use the audioRecord API[8] function to record the audio

public void receive(){
		int minBufferSize = AudioRecord.getMinBufferSize(AUDIO_SAMPLE_FREQ, 2,
				AudioFormat.ENCODING_PCM_16BIT);
		AudioRecord ar = new AudioRecord(MediaRecorder.AudioSource.MIC,
				AUDIO_SAMPLE_FREQ, AudioFormat.CHANNEL_IN_MONO,
				AudioFormat.ENCODING_PCM_16BIT, minBufferSize);
		ar.startRecording();
	   }

How to harvest energy from audio signals

Obviously, power is required to drive the circuit for audio jack peripherals. For example, the L-channel sends data information. The R-channel sends sustained square or sine waveforms. These waveforms can be transformed to power that enables the MCU (Micro Controller Unit) and several sensors.

Case study: infrared peripherals

Androlirc[9] is a Github-based project. Its function is to use the audio jack interface to send infrared commands. We can study this project to understand audio jack data communication. Androlirc uses the LIRC[10] library to create a data buffer. This library is a Linux* infrared library that supports several types of interfaces, for example: USB, audio jack, etc. Androlirc can use the LIRC library as a data encapsulation or data capsulation. Across the marketplace, you can find many infrared coding types, such as the RC-5 and RC-6 protocols. In the example, we use the RC-5 protocol to control a TV set. First, we need to modulate the data value using a 38k frequency sine waveform to generate buffer data; then we use the Android audio API function to play the audio buffer data. Meanwhile we can use one of two channels to play a sine or square waveform to power on the peripherals hardware.

Case study: audio jack development tools

NXP Semiconductors’ new smartphone solution, Quick-Jack*[11], is a tool/development board based on a prototype project called Hijack. Hijack[12] is a University of Michigan student project. The Hijack platform enables a new class of small, cheap, phone-centric sensor peripherals that support plug-and-play operations. We can use the NXP Quick-Jack developed board to help build our prototype product design. Figure 4 shows a smartphone displaying the indoor temperature from the audio jack-based peripheral temperature sensor.

Figure 4. Temperature value from Quick-Jack

Figure 5 shows how we can control the peripheral’s LED using an Android-based application.

Figure 5. Controlling the LED on the Quick-Jack

Summary

Wearables and smart device peripherals are becoming more prevalent in the consumer market. The audio jack as a data communication function is being adopted by more and more ODMs and iMakers. Perhaps in the future, audio jack data communication functions will be universally supported by smartphone OSs.

Reference

  1. http://www.ihealthlabs.com/glucometer/ihealth-align/
  2. http://www.irdroid.com/
  3. https://www.kickstarter.com/projects/flomio/flojack-nfc-for-ipad-and-iphone
  4. http://en.wikipedia.org/wiki/Phone_connector_(audio)
  5. http://en.wikipedia.org/wiki/Frequency-shift_keying
  6. http://www.maximintegrated.com/en/app-notes/index.mvp/id/4676
  7. http://developer.android.com/reference/android/media/AudioTrack.html
  8. http://developer.android.com/reference/android/media/AudioRecord.html
  9. https://github.com/zokama
  10. http://lirc.org
  11. http://www.nxp.com/news/press-releases/2014/05/nxp-unveils-smartphone-quick-jack-solution-transforming-audio-jack-into-multi-purpose-self-powered-data-port.html
  12. http://web.eecs.umich.edu/~prabal/projects/hijack/

About the Author

Li Liang earned his Master degree in signal and information processing from Changchun University of Technology. He joined Intel in 2013 as an application engineer in the Android mobile enabling team in China. He focuses on differentiation enabling on the Android platform, for example, multi-windows, etc.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

Share

About the Author

Intel Corporation
United States United States
You may know us for our processors. But we do so much more. Intel invents at the boundaries of technology to make amazing experiences possible for business and society, and for every person on Earth.

Harnessing the capability of the cloud, the ubiquity of the Internet of Things, the latest advances in memory and programmable solutions, and the promise of always-on 5G connectivity, Intel is disrupting industries and solving global challenges. Leading on policy, diversity, inclusion, education and sustainability, we create value for our stockholders, customers and society.
Group type: Organisation

members


You may also be interested in...

Pro
Pro

Comments and Discussions

 
-- There are no messages in this forum --
Permalink | Advertise | Privacy | Cookies | Terms of Use | Mobile
Web01-2016 | 2.8.181111.1 | Last Updated 1 May 2015
Article Copyright 2015 by Intel Corporation
Everything else Copyright © CodeProject, 1999-2018
Layout: fixed | fluid