That's the Arduino Cassette Engine to me and you.
Hankering after some old-skool interfacing? Got the urge for PCM? Here's some Arduino code to read a data stream encoded in a frequency shift keyed manner. As usual I'm presenting this in its completely raw form. There are plenty of comments in the code and enough information to allow any intermediate level programmer to get started.
Also included in the archive is the c# app that creates demo data to be read. It was adapted from another application I wrote to get data from binary images into my zx81 which explains the cockamamy structure. And the icon! If you have problems downloading let me know.
Beware of the output from SquareWave - it's as loud as it can possibly be. Make sure that volumes are turned right down before running it. You have been warned!
Enough blabber - here's the skinny ripped right from the code:
/*
/ 'Arduino Cassette Engine'.
/
/ Developed by Charlie Robson in 2008.
/
/ This is half of a solution for getting data into an arduino. The other
/ half being code to generate frequency shift keyed (FSK) data in the form
/ of WAV files which should be widely playable. These can be recorded or
/ otherwise electronically distributed. Why do it this way? 1. Because it's
/ funny. 2. Having given an updatable arduino-powered 'toy' to someone, I
/ can't expect them to re-program the device by traditional means in order
/ to update it. Everyone has a means of playing a sound!
/
/ On with the show.
/
/ The data is encoded like so:
/
/ Lead-in
/ High byte of data length
/ Low byte of data length
/ {
/ Data[0 < size <= 512]
/ (Lead-in)
/ }
/
/ Lead-in is a train of bits terminated with a start bit. This means the lead-in
/ bit needs to be the logical complement of the start bit.
/
/ Every byte is represented by 10 bits - a start bit, 8 data bits, and a stop
/ bit. The start and stop bits are complementary.
/
/ Data arrives in 512 byte blocks. Each block except the last is followed by a
/ short period, about 25 milliseconds, of lead-in. This is to allow processing time
/ on each block as it arrives.
/
/ Decoding a data bit is done something like so:
/
/ Await a rising edge then take 2 samples at a period which will allow us
/ to distinguish a 0 or 1 bit. Sampling 2 identical values yields a 0 bit.
/ Delay so the next bit read will occur when the signal is in a low period.
/
/ Following is a picture of a '0' bit, or low frequency cycle, followed by
/ a '1' bit or high frequency cycle, with some important times noted.
/
/ The X shows a rough expected time at which we start the bit reading.
/ The 0 shows relative time zero, when we detect the rising edge.
/ The + signs show the times at which we sample.
/ The * shows the earliest time at which we can await a new bit. IOW, X.
/
/ __`_____`__ __
/ | ` ` | |
/ | ` ` | |
/ | ` ` | ` |
/ ` | ` ` | ` |
/ __`_| ` ` | ____`_____|
/ ` ` ` ` `
/ X 0 + + *
/ ` `__`__ ` _____`
/ ` | ` | ` | |
/ ` | ` | ` | |
/ | | | |
/ | | | | |
/ ____| |_____| |_____|
/ `
/ `
/ |-----------------------| = usPerCycle = 1360uS
/ |-----------| = usPerHalfCycle = 680uS
/ |-----| = usPerQuarterCycle = 340uS
/ |--| = usPerEighthCycle = 170uS
/
/
/ It's assumed that the audio signal is connected to PORTB-0 which is
/ digital pin 8. If you'd like to change that, then replace occurrences
/ of...
/
/ PINB & 1
/
/ ... with the direct bit-access for your implementation. I do it this
/ way because it's slightly faster than digitalRead()ing. If you do change
/ the port you'll also need to change the logic in readBit as this relies
/ on the fact that we work with bit 0.
/
*/
Enjoy!
5 comments:
Great project. Thought you might like to know that you can decode the wave form just by measuring the timing of the rising and falling edges.
Thanks!
I'll try that in Ace2 :D
A little bit a work, we could create an Arduino based 300 baud modem!
can u please send me the sourcecode, because the download link is dead.
And i u could also the schematic.
Many thanxzzz
greetings,
Woenderik Nagtegaal
bigdeal@zonnet.nl
Hi - the code is now available from google code:
https://code.google.com/p/ayss/source/browse/
There is no schematic. All you do is play the audio VERY LOUDLY into the right pin on the Arduino. You could rig up something with a transistor - I may have done this but to be honest it was a long time ago now :D
Post a Comment