Linux Format forums Forum Index Linux Format forums
Help, discussion, magazine feedback and more
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

An idea for simple, OS independent serial data generation.

 
Post new topic   Reply to topic    Linux Format forums Forum Index -> Programming
View previous topic :: View next topic  
Author Message
IamPete



Joined: Thu Apr 03, 2014 12:34 pm
Posts: 12

PostPosted: Wed Apr 09, 2014 11:46 am    Post subject: An idea for simple, OS independent serial data generation. Reply with quote

Bazza's thread (http://www.linuxformat.com/forums/viewtopic.php?t=15979 gave me an idea, what would it take
to make a truly independent way to generate serial data even on smartphones which have no serial port.

These days serial ports are also pretty hard to find on computers which means using a USB to Serial converter which then involves drivers (in some cases) and programming as well.
Sure on Linux one could do something like:
Code:

echo -n "SomeData" >/dev/ttyUSB0

but that wouldn't be very OS/platform independent.

Then I got thinking, one "port" that all computers (and smartphones) have is an audio/headphone output, so why not use that?

All one needs to do is generate tone bursts (with proper durations), then use either a schmitt trigger or fast comparator
connected to the audio output to convert these bursts into pulses to get TTL serial data.
It turns out that there is no easy way to generate these audio bursts "on-the-fly" across all OS's.
The closest one could get to a "universal" method is to use Sox but there is no Sox port for smartphones (that I know of)
plus Sox writes the audio data to a file which means plenty of drive "thrashing" if lots of "serial" data is generated.

So the kludge I thought of is, why not have 256 independent pre-made audio files in wav format, each having a start bit, stop bit and 8 bit data (one file data=0, another for data=1, yet another for data=2 and so on).
Having 256 audio files seems rather clunky but makes things much more universal plus each audio file (mono, 16 bit, 44.1KHz sample rate) is only 784 bytes, so all 256 would only amount to around 200KB.

Each file can be called for example, AudioSerial_0.wav, AudioSerial_1.wav, AudioSerial_2.wav and so on.
Any media player can then be used for playing.
Opens up loads of possibilities as we could create a Bash or batch script to play these files in a sequence to generate
the required serial data stream via the interface circuit.
One could even create a playlist (for vlc, Windows Media Player, etc) so no real programming is required.
Could even play them out via a html page.

I experimented a bit (for serial data at 1200 BPS) and found that if one uses a sample rate of 44.1KHz and for each high bit we
use bursts of 37 samples of a 22.050KHz square wave (or silence for the low bits), the timings are pretty accurate.
I first tried Sox to generate the wav files but found that the resulting waveforms were not very good.
Resorted to using Audacity and they are spot on.
Note that although I specified square waves, I actually got sawtooths.
This is because of the filtering action as 22.050KHz is exactly half of the sample rate of 44.1Khz.

At this point, I must mention that I have not finished experimenting and it's still work in progress, but decided to post it
never the less so others can give suggestions or start experimenting for themselves.

The circuit:



The schmitt trigger (or comparator) is set to trigger as shown in the drawing below.
However, it may happen that "glitches" are created when the waveform drops below the trigger point (even if set very low).
In that case, experiment with the value of Cx.



Could even connect an Arduino to act as a serial to parallel converter:



Perhaps someone can think of a better way to create serial data in a universal way across any OS/platform.
Suggestions very welcome.

One final point, so far I'm only experimenting with serial data at 1200BPS, once I get it working, might try for higher baud rates
although 1200BPS is good enough for general tinkering and communicating with other circuits and modules.


IamPete.
Back to top
View user's profile Send private message
IamPete



Joined: Thu Apr 03, 2014 12:34 pm
Posts: 12

PostPosted: Wed Apr 09, 2014 12:21 pm    Post subject: Reply with quote

Below, an example wav file with the required tone bursts for the example shown in my previous post.

http://www.datafilehost.com/d/7de995f2
Back to top
View user's profile Send private message
Bazza
LXF regular


Joined: Sat Mar 21, 2009 11:16 am
Posts: 1462
Location: Loughborough

PostPosted: Thu Apr 10, 2014 9:37 pm    Post subject: Reply with quote

One word!

Neat!

I am working on a slow ADC using DC out from the earphone socket and a __counter__ and lookup table using the mic input for the AudioScope to grab the DC component.

I have decided against a Chopper and VCO because it can't detect the DC polarity easily when the input is mono as on the Macbook Pro 13 inch model... It requires 2 hits at the port for DC component and another for the AC component, 3 hits.

I only need one DC control output and one mic input to reduce both components to 2 mic input hits, one apiece...

I really like what you are doing...
_________________
73...

Bazza, G0LCU...

Team AMIGA...
Back to top
View user's profile Send private message
IamPete



Joined: Thu Apr 03, 2014 12:34 pm
Posts: 12

PostPosted: Thu Apr 10, 2014 11:23 pm    Post subject: Reply with quote

Hi Bazza and thank you.

I too enjoy finding simple (and sometimes unusual) ways to solving a problem.
In this case the lack of "traditional" I/O ports on modern computers.

As regards your mono mic input dilemma, have you or are you willing to consider using those small, cheap USB sound cards?
They sell for around 3 or 4 Pounds in some shops and even cheaper online.
They also have only mono mic inputs, but using two of them (or one of them and the internal sound cards mic input) and splitting the audio input to both mic inputs might help you.

Those USB sound cards comply to the standard USB Audio spec so no drivers needed (at least in Linux, don't know about the Mac) and show up as /dev/dsp0, /dev/dsp1 and so on.

BTW, connected one to my Android based phone via a micro USB to "normal" USB adaptor, Android picked it up immediately and I could use it.

Here is a pic of one of them (plenty others around):

Back to top
View user's profile Send private message
View previous topic :: View next topic  
Display posts from previous:   
Post new topic   Reply to topic    Linux Format forums Forum Index -> Programming All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
Linux Format forums topic RSS feed 


Powered by phpBB © 2001, 2005 phpBB Group


Copyright 2011 Future Publishing, all rights reserved.


Web hosting by UKFast