Working progressively: Part IV (Serial connections)
Posted Sun, Feb 27, 2005 at 07:51 PM
After Part III, the story continues...
In some ways, serial communication was the hardest part -- or at least the one that caused the most frustration.
I had overlooked one very important detail: I have a Basic Stamp Stack with a BS2sx chip which is faster than a regular BS2 chip. And with serial communication between a microcontroller and a computer, timing is everything.
Here's a good article about using the Basic Stamp's SERIN and SEROUT commands, along with a handy baudmode chart: http://www.emesystems.com/BS2rs232.htm.
You can also read this other article (pdf) from Parallax that "demystifies" BS2 serial connections: http://www.parallax.com/dl/docs/cols/nv/vol1/col/nv16.pdf
I used Processing to animate my LEDs (by telling the Stamp what rows to light up) and the Stamp itself is programmed to scan through the columns.
Links to the source code (along with lots of commenting) are below:
PBASIC: html | download file (.bsx)
Processing: html | download file (.pde)
I couldn't figure out how to convert decimal numbers into binary format using PBASIC so, in the end, I'm just sending decimal/integer numbers from Processing to the Stamp since the numbers 0-255 would represent a unique combination of LEDs to be lit up.
It required a binary math refresher so below is a chart:
Or if you're on Windows, use the built-in calculator in scientific mode (View > Scientific). Make sure the radio button for "Bin" (binary) is selected, and type in your number. When you're done, select the "Dec" radio button and it will convert your numbers.
Next up: Switching to the transistor arrays, getting better animations out of Processing, and then getting Processing to talk to the Basic Stamp, which then talks to a PIC. (It might be a while...)