Serial audio to UART - Page 1
Forum section: electronics / beginners

author: unknowndomain
author_rank: Regular Contributor
timestamp: February 06, 2013, 08:59:27 pm
content: I am working on a project where we want to send serial data out of the audio port on a computer, I have managed to get this aspect working however I am unsure how to change the output to something that will be safe to connect to the UART of an Arduino or other Atmel ATmega or ATtiny chip.I have taken some measurements at the maximum volume level of my computer and found the signal has a slight DC offset (about -0.75V) and that the peak is only about 2.25V which isn't the 0/5 volt I would ideally see.I have been doing some research and I think I need a capacitor to ground to remove the DC offset and a op amp to boost the signal to 5V however I am not familiar with either of these approaches as I am a hobbyist.Another concern is that the output level may not be the same for every device. Can anyone help me to design a circuit which can correct the DC offset and the low peaks and also be flexible enough to work with different voltages, incase a different computer has a slightly higher or lower output.The picture attached shows the signal being generated by the computer's sound card, it is transmitting 00110000.

author: David_AVD
author_rank: Super Contributor
timestamp: February 06, 2013, 09:08:53 pm
content: A quick Google search for "audio to TTL" found this:http://robots-everywhere.com/re_wiki/index.php?title=Serial_on_Android_using_the_audio_portThat seems like a reasonable starting point.

author: unknowndomain
author_rank: Regular Contributor
timestamp: February 06, 2013, 09:14:43 pm
content: Hey David,I tried that circuit but I just seem to get the same level out as I get in, if I adjust the potentiometer it seems to invert the signal, but it doesn't adjust, it just suddenly flips over.

author: unknowndomain
author_rank: Regular Contributor
timestamp: February 09, 2013, 11:42:18 am
content: I went ahead and rebuilt the circuit from David's link again and I am still getting the same issue, the output level is lower than the input and it's also got a offset which means it never exceeds 0V, it's -0.5V to 0V rather than 0V to 5V, there is also a considerable slope on the rising edge which may not be great.Any help urgently needed, my weekend project is about to fall flat on it's face!

author: lewis
author_rank: Frequent Contributor
timestamp: February 09, 2013, 04:17:42 pm
content: You could try something like this (attached). The two series diodes on the non-inverting input of the comparator generate an approx 1.2V reference so if the audio in signal goes above 1.2V it will make the comparator output go low, or high if it's below 1.2V. This then gets inverted by the inverter to produce a high or low output respectively. The 100K resistor around the comparator provides a limited amount of hysteresis by increasing or decreasing the current through the reference diodes. The two other diodes and 100K series resistor protect the input of the comparator if the input voltage goes too high or low. The 4.7K resistor is a pullup for the comparator's open-collector output. Use a comparator like LM393 or LM339, not an op-amp. Not shown on the diagram are the power pins for the gate which obviously need to be connected to the 5V and GND rails. I haven't tested this so you'll almost certainly need to play with it.One thing to watch out for is that computer sound cards almost always have coupling capacitors at the output which means it will not pass any DC. If you have a long sequence of 1's or 0's, the coupling caps will gradually discharge giving an exponentially decaying voltage at the audio input of this circuit. You'll need to structure the data so there's enough transitions so this doesn't happen. I've never tried outputting serial through a sound card, so it might not be a problem.

author: c4757p
author_rank: Super Contributor
timestamp: February 09, 2013, 07:18:18 pm
content: Quote from: lewis on February 09, 2013, 04:17:42 pmLook up "constant-weight code" - this isn't too hard to implement.

author: PA0PBZ
author_rank: Super Contributor
timestamp: February 09, 2013, 07:33:02 pm
content: Quote from: unknowndomain on February 09, 2013, 11:42:18 amThe fact that you manage to get a negative output from the LM324 while it has no negative supply makes me think that you used the red numbers in the diagram as pin numbers for the op-amp, while you should use the little blue numbers...

author: c4757p
author_rank: Super Contributor
timestamp: February 09, 2013, 07:34:54 pm
content: If that's the case I want to know where he found pin 0.

author: PA0PBZ
author_rank: Super Contributor
timestamp: February 09, 2013, 08:04:47 pm
content: Quote from: c4757p on February 09, 2013, 07:34:54 pmThat's the NC pin, you should know thatJust saying, if the result he shows on the scope is what he gets out of the circuit there must be something wrong with the way he built it.

author: c4757p
author_rank: Super Contributor
timestamp: February 09, 2013, 08:09:26 pm
content: Maybe he just drew the ground line in the wrong spot.