Did you know that you could play sound using an usb to uart/serial converter , by just using an FT232RL usbserial and an external speaker with amplifier?
Let’s take a look at the software side first, the basic idea is to send bytes purposedly crafted to create some sort of PWM.
So we have 8 bits each byte sent, which mean 8 levels, kinda crappy if you like hi-fi sound , but that’s not the purpose of this hack obviously.
So the easiest way is to send these bytes for each level
-
Level Bits -4 00000000 -3 10000000 -2 11000000 -1 11100000 0 11110000 1 11111000 2 11111100 3 11111110 4 11111111 A simple python script with pyserial can easily do it, by taking bytes from stdin coming from a raw mono s8 pcm file , to the usbserial
1234567891011121314151617181920212223242526272829import serialimport structimport sysimport timeser = serial.Serial()ser.baudrate = 576000 #By trial and error i found out this to be the best speed which does not give bad sound on the speakerser.port = "/dev/ttyUSB0"ser.parity = "N"ser.stopbits = 1ser.xonxoff = 0ser.bytesize = 8ser.open()while True:buf = sys.stdin.read(1024)if len(buf) == 0:breaks = time.time()data = ""for c in buf:val = struct.unpack("b", c)[0] # Convert the byte to a signed int8val = 4+(val/127.0)*4 # Clamp it from -127,+127 to 0,8val = int(val) #Convert it back to int to be able to do str*intbstr = "0"*(8-val)+"1"*val # Convert it to val ones and 8-val zeroes to obtain values in the above tabledata += chr(int(bstr,2)) # Convert the bits , like "11100000" to the byteser.write(data) # Send the 1024 bytes to the serial portprint((1.0/(time.time()-s))*1024)To create the raw file use the following command:
1ffmpeg -i youraudiofile.whatever -f s8 -acodec pcm_s8 -ar 58000 -ac 1 filename.rawThe 58000 sample rate value is obtained experimentally by looking at the script output , to see how much bytes/sec are actually sent
To play it:
1cat filename.raw | python2.7 serialsound.py
Connect the GND pin of the serial converter to the ground of the amplifier cable, and the TX pin to the signal pin.
If you get strange interference because your amplifier is class D and it is not filtered, you need to add a lowpass filter with cutoff frequency of 22 Khz
Result:
Thanks to Valerio “Gurzo” Morgante ( latanadelgurzo.blogspot.it ) who was working on doing the opposite ( Emulating a serial port using a sound card ) and that gave me the idea of obtaining sound output using an inexpensive FT232RL usb-serial
This is very cool. Are you using TTL UART output? If so, 3.3v or 5v?