30

I was just stumbling around EE Stack and found this post: What protocol does a headphone jack use. And it sparked some curiosity in me, and I figure, if the iPhone can do it, I want to as well.

Does any one know of any projects that are doing this now or whether or not it's even possible?

UPDATE

RIP

ahodder
  • 11,353
  • 14
  • 71
  • 114
  • I'm confused, aren't these just analog signals down the cables? You can do whatever you want with them - only question is *what*? – Che Jami Oct 28 '11 at 16:04
  • Right, I know that. I'm wondering how do I read (or output) data? I haven't found anything in the documentation on handling TRS input (output). – ahodder Oct 28 '11 at 16:08
  • Can't we use a `MediaRecorder` and carry out signal processing? – Che Jami Oct 28 '11 at 16:27
  • If I read the documentation correctly, I don't think so. As far as I can tell `MediaRecorder` can only receive data from that camera and mic. Not the TRS socket. – ahodder Oct 28 '11 at 17:24
  • On that note, I think that `AudioRecord` may be the solution. I will look into it. – ahodder Oct 28 '11 at 17:28
  • @AedonEtLIRA were you able to do this? I'm facing a similar problem now, can you please share how you managed to read data using the headset jack? http://stackoverflow.com/questions/13594074/is-it-possible-to-detect-a-keyboard-pedal-press-plugged-in-the-headphone-microph – caiocpricci2 Nov 30 '12 at 08:56
  • @gameower I ended up dropping it. It was easier and cleaner to just use bluetooth. Wireless is also a plus. – ahodder Nov 30 '12 at 16:48
  • [I did not test, but is an interesting approach.](https://stackoverflow.com/questions/7931592/how-to-read-send-data-using-the-android-devices-3-5mm-headset-jack) – Marco Aurelio Silva Apr 12 '19 at 19:39
  • @ahodder Isn't Android TRRS? – TheRealChx101 Jan 22 '22 at 18:39

2 Answers2

42

You are basically asking how to turn the microphone input into a modem input. A variant of this clever technique is used commercially by Square for their magstripe readers on both iOS and Android devices.

To do so requires getting access to the raw PCM stream from Android and decoding the input. Luckily for you, someone has already done it and thrown the source out there. See this Hack a Day linked project for sample Arduino and Android code for transmitting only.

I couldn't find example Android code to receive, but there are rather extensive notes on doing FSK with iOS in this Arduino forum post.

(Though it wasn't your question, an easier way to get data in and out of an Android device is the new USB Host and Accessory support. It requires a newish phone and OS, so not as flexible as the audio route.)

Script Kitty
  • 1,737
  • 5
  • 27
  • 47
mik3y
  • 4,214
  • 1
  • 22
  • 29
  • That is interesting to output 9600 baud data, but it does not address the reception of data. – Tevo D Nov 01 '11 at 17:19
  • Good point, I updated the comment. I was confusing it with another project (added link), which has iOS libraries. – mik3y Nov 01 '11 at 17:41
  • Right, trust me, I definitely and heavily considered USB, but what I'm working on I would like to run on 1.6 or greater. Thanks for your input though, the article was good for the gander. – ahodder Nov 01 '11 at 19:59
  • @KonstantinPribluda Right, the vast majority are 2.2/2.3 (including my test device). But both of those versions lack the USB Capability. Further, as far as I know, every device will have a 3.5 jack; not all are guaranteed to have a compatible USB device. – ahodder Nov 07 '11 at 16:35
5

I've written a C library which can send and receive data through an audio cable at 64kbps. https://github.com/quiet/quiet

As far as modulation techniques, it supports a wide range, as it uses an SDR library to perform its modulation.

If you'd like to try it out, here's a live demo https://quiet.github.io/quiet-js/lab.html

Brian Armstrong
  • 326
  • 2
  • 14
  • Cool, Thanks : Just to note for the "loop-test" demo on Windows make sure you disable sound effects on the microphone otherwise feedback cancellation will inhibit the reception of what is being sent through the speakers. Control Panel→ Sound → Change Sound Settings → Recording –> Properties –> Enhancements –> Check Disable all sound effects. – Pau Coma Ramirez Apr 18 '16 at 23:26