[plt-scheme] Reading voltages on a serial port...

From: Jim Blandy (jimb at red-bean.com)
Date: Sat Aug 5 02:20:27 EDT 2006

On 8/4/06, geb a <geb_a at yahoo.com> wrote:
> Maybe this is way off topic but here goes... What I
> would like to do is to read the voltage of a pin on
> the serial port so that if the pin reads high it
> returns a boolean value (positive or negative logic is
> fine).
>
> Can someone point me in the right direction?  The
> following program yields nothing when run...
>
> (define serial (open-input-file "/dev/ttyS0"))
>
> (define (read-loop in-port)
>   (display (read-line in-port))
>   (newline)
>   (read-loop in-port))
>
> (read-loop serial)

Well, when you open /dev/ttyS0, between your program and the pin is a
device called a UART (Universal Asynchronous Receiver/Transmitter),
which is looking for a certain pattern of voltage changes on the pin,
having a specific timing, before it will report anything to you.
Think about the UART as a "parser" for electrical pulses; it's not
going to give you anything via /dev/ttyS0 until it recognizes a
well-formed character.  And you're very unlikely to get anything that
looks like a well-formed character from a real-world voltage source.

You might try the parallel port.  In particular, try the strobe pins
and see if you can't get some sort of sensitivity to level changes.


Posted on the users mailing list.