Watching a serial port count on an oscilliscope
Posted: Wed Feb 01, 2012 5:56 pm
So since I got interested in RC, I finally splurged and bought an arduino. Been studying on serial communications and wanted to 'see' it in action. This doesnt actually use the arduino. It's just a perl script communicating to a usb/serial adapter. It shows the marks and spaces counting to 255. demonstrated to me that ttl serial uses a 'high' voltage as a logic 1, whereas I read that actual rs-232 uses a 'low' or negative voltage for a logic 1. Also demonstrated endian, or byte order. This is MSB order. I'd had that backwards in my mind until I saw this and thought about it. Dont really have a question, justed posted it for the entertainment value. my perl is probably a tangled mess also. If you see any errors or have any comments in what I think I have figured out, dont be shy.
http://www.youtube.com/watch?v=zFPpQwZqBDw
http://www.youtube.com/watch?v=zFPpQwZqBDw
Code: Select all
#! /usr/bin/perl
# I had edited this script after I made the video, I tried to get it back the way it was, but may have missed something
use strict;
use Device::SerialPort;
use Time::HiRes;
my $file = "/dev/ttyUSB1";
my $ob = Device::SerialPort->new ($file) || die "Can't open $file: $!";
$ob->baudrate(9600) || die "fail setting baudrate";
$ob->parity("none") || die "fail setting parity";
$ob->databits(8) || die "fail setting databits";
$ob->stopbits(1) || die "fail setting stopbits";
$ob->handshake("none") || die "fail setting handshake";
$ob->write_settings || die "no settings";
my $pass;
$pass=$ob->write("lets get ready to go");
print "We are pausing for 2 seconds to get the port open\n";
sleep 2;
while (1) {
for (my $i = 1; $i < 255; $i++) {
print "the value of i is $i\n";
for (my $repeat =1;$repeat < 100; $repeat++) {
$pass=$ob->write(pack('c',$i));
Time::HiRes::sleep(.01);
}
}
print "finished this cycle, We are pausing for 3 seconds\n";
sleep 3;