Wednesday, January 28, 2009

Finally, the serial port is interfaced

The Transmit Data pin (#3) will require a little more attention. How will the signal (in other words: the wave) be interpreted by the IC? I'll be sending data according to the RS232. The signal is a block type wave, a 0 bit is represented as positive voltage (also called a “space”), a 1 bit is represented as negative voltage (called a “mark”). Furthermore, if the data line is idle, the signal is “spacing” (meaning, it's negative). How a byte is sent, depends on the following parameters: baud rate, byte encoding (e.g. 7-bit or 8-bit), presence of the parity bit (which is optional) and the number of stop bits. I stuck with the default parameters and thus didn't give them any special attention.

Let's visualize how this wave will look like:



Now that I know how it's looks like, I can modify it to my liking. First of all, I do not want it to send out a signal when the line is idle (or else my front door would be open all the time!). This is accomplished by adding a diode to the TD wire. This means that I can only use the positive signal to send to my front door switch. Next, whenever I send a byte out the serial port, I'd like it to be as continuous as possible. Therefore I send out only 0 bits, this is called a null character.

Serial ports cannot give a lot of amps, and I actually don't know how much amps my front door system will ask of my serial port (or even if it will ask any at all) once the current starts flowing. As it turns out, anything below 500 mA should be safe, so that's the rated current for my fuse (if it breaks I'll know my front door system sucks out to much juice and I'll have to come up with something else).

Finally, I know how the entire picture looks like, here's how it looks like schematically:


(click for larger image)

It's all in place, it's time to test for the first time if all my research that I've done so far will suffice! I plugged in the connector, fired up a prompt, and elegantly typed:
$ echo 0 > /dev/ttyS0
Side note: I'm actually sending out the bits 0110000 (= ASCII code 48 = 0). I was anxious to try it out and I couldn't be bothered at the time on finding out how to send a null character to my serial port from command line :-) (which is "echo -en \\0000 > /dev/ttyS0" on Linux, btw.)

Side note #2: /dev/ttyS0 is the serial port under Linux, doing a “echo 0 > COM1” in Windows will have the same effect.

W000000000000000T! My doors opened! I couldn't believe it! So naturally I tried it again, hmm, that's odd, the doors didn't open...

My first assumption was that the fuse had blown, so I checked that, but it wasn't. Next, I tried to echo data to the serial port again, and again, and again, but this time with more bytes:
$ echo 0000000000000000 > /dev/ttyS0
That worked! Apparently the front door black box system has to receive the signal at a given moment for a given amount of time, or else the door will not open. I just was VERY lucky that it opened on the first time, with just sending 1 byte (or else I might have assumed something wasn't working and I'd be stuck for a long time figuring this out). Maybe that adjusting the baud rate of the port would solve this problem, but I'll settle for sending more bytes (so I can send “I AM 1337! 101100111001!” to my front door, and it opens in fear of me :-))

So far so good, this was the easy part! I'll be posting about my Java Bluetooth application for my server and phone in a short while.

4 comments: