📜 ⬆️ ⬇️

About data transmission via audio jack

One of the important interfaces on mobile devices and tablet computers is the headphone / microphone jack. But do not think that it is intended only for speakers, headphones, microphone - it can be used including for data transmission. About this today and talk.



Alternative ways to use the audio connector to connect third-party devices are constantly updated. Peripherals, such as the iHealth Lab blood glucose meter (which determines blood sugar levels), the Irdroid — the IR remote control for remote control of the TV, consoles, and sound components — and the Flojack — an NFC reading device (organizing radio communication between nearby mobile devices) - all this has become possible due to the presence of the audio connector.

Since the mobile and peripheral market has a large number of potential customers, I believe that the headphone jack will be the main port for transmitting information in a short time. In this article I will discuss in more detail about this function.
')

Introduction


The audio interface has two standards: OMTP and CTIA . OMTP is an international standard; ATIS - American standard used in devices such as the Apple iPhone and iPad. They are distinguished by a V-microphone as well as a grounding arrangement; The differences are shown below:

image
OMTP and CTIA

How data is transmitted


When we send 0x00FF data, the first step is to convert digital data to analog. Therefore, you need to modulate the data value. As a rule, a sinusoidal wave carrier for the analog signal is used for this.

image
FSK signal modulation

The second step in Android devices is the call to the audioTrack API , the function used to play. 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); } 

Data acquisition


In the receiver, you need to convert the analog signal to the data value, demodulate the signal in order to remove the incoming signal, and decode the data according to the protocol. The protocol can be in the format of publicly available data or private.

image
Signal demodulation

On Android systems, we use the audioRecord API sound recording function:

 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 extract the energy of sound signals


Obviously, a certain amount of power is required to accumulate on the power supply for peripheral devices. For example, the L-channel transmits data. The R-channel sends a steady square or sine signal. These signals can be converted by an MCU (Micro Controller Unit) and several sensors.

Success Story: IR Peripherals


Androlirc is a Github-based project. Its functions can be used to send an infrared audio connector to an application. You can study this project to understand the process of exchanging data through the audio jack. Androlirc uses the LIRC library to create a record in the data buffer. This library is an infrared library for Linux, which supports several types of interfaces, such as USB, audio jack, etc. Androlirc allows you to use the LIRC library to accumulate data. You can find many infrared coding types on the market, such as the RC-5 and RC-6 protocols. In the example above, we use the RC-5 protocol to control the TV. First, we must modulate the data value using a 38k sine wave signal to generate buffer data. Then we use the Android audio API to play the sound from the data buffer. At the same time, we use one of two channels to reproduce a sine or square power signal on peripheral equipment.

Success Story: Sound Connector for Developers


A new solution from NXP Semiconductors, Quick-Jack is a device based on a prototype called Hijack. Hijack is a project of students at the University of Michigan. The Hijack platform allows you to create a new class of compact, cheap, phone-oriented peripheral sensors with support for plug-and-play operations. You can use NXP Quick-Jack cards to create a prototype.

Below is a smartphone that displays the temperature of the room using a temperature sensor based on the audio jack. Through it, the LED indicator of peripheral devices is controlled using an Android-based application.

imageimage
The temperature value obtained using the Quick-Jack; through it control of the LED indicator is exercised

Free information


Wearable devices with the ability to connect peripherals are increasingly appearing in the consumer market. The audio connector as a data transfer function is increasingly being used by ODM manufacturers. Perhaps in the future, the data transfer function through this connector will be supported by mobile operating systems by default.

about the author


Liang Li received a master's degree in signal studies and data processing at Changchun University of Technology. He joined Intel in 2013 as an Android engineer in the Chinese division. Now he is creating features that would allow Android to gain competitive advantages (for example, displaying multiple application windows at the same time and so on).

Related Links


Source: https://habr.com/ru/post/258495/


All Articles