Electronic – arduino – Reading data from 3.5mm audio jack

arduinoaudiomodem

I wonder if it'd be a relatively straightforward exercise to read data from a 3.5mm audio jack using an Arduino and a raspberry pi. The communication will be one-way only: raspberry pi transmits data to Arduino, so the Arduino will do the reading. Does anyone know how this could be accomplished without using a modem?

Best Answer

The other answers seem to involve using 3.5 mm jacks and an audio cable just to carry a typical serial digital signal from the Raspberry Pi GPIO ports: e.g. wiring asynchronous serial, SPI or I2C to a dedicated external 3.5 mm jack which is not the audio jack on the Pi.

I interpreted the question more along the lines "can I transmit digital data to a microcontroller using the Raspberry Pi audio output"


Yes, but it gets more complicated. The raspberry pi audio output looks like this:

Two pulse-width modulated (PWM) square waves are produced by the Broadcomm SoC (off screen), and are then low-pass filtered (to produce an analog waveform) and fed into the 3.5mm jack. DC blocking capacitors ensure that the output has no DC offset. The diodes protect against voltage transients.

The audio output is (capacitively) AC coupled; The DC blocking capacitors together with the load and source impedance will act as a high pass filter, blocking frequencies below a few tens of Hertz. Thus you cannot use DC-imbalanced signals to communicate.

You have to encode or modulate the digital data somehow, so that you can pass it trough an AC coupled line. There are many suitable encoding schemes, most notably manchester coding, 8b/10b encoding or 4b/5b encoding. Such signals can then be decoded at the arduino end by feeding the signal to the analog comparator input, feeding the comparator output to the Timer 1 input capture unit (so that every reveived rising and falling edge gets a timestamp), and then decoding the stream in software. As the audio output is designed with the human hearing range in mind, I wouldn't expect a bitrate greater than about 10 kbps (probably much less, depending on the encoding scheme used).

There are also various simple modulation schemes such as Frequency Shift Keying, Phase Shift Keying, Pulse Position Modulation and On-Off Keying which can be demodulated relatively easily with just the analog comparator and a hardware timer.

If you want to go grazy you can also synthesize a digitally modulated analog waveform at the raspberry pi end, sample it with the arduino ADC and demodulate in the digital domain. With something like quadrature amplitude modulation you could get a fairly respectable data rate even with the limited bandwidth and processing power available, at the cost of more software complexity.

Modulation differs from encoding in that you modify properties of a constant repeating waveform with the data being transmitted instead of modifying the signal itself. Modulation permits transmitting a signal of a certain frequency range at a different frequency range, which is crucial for e.g. radio communication but isn't needed in this case as your original signal (baseband) is already in the frequency range of the communication channel, so encoding without any modulation can be used. Combining encoding and modulation is also possible.