View Full Version : basic 2 stamp and usb...
04-16-2007, 10:04 AM
I would like to create a project that connects to my computer VIA usb using the basic stamp 2. Then I would like to create a C# program to send and receive commands. Is this possible and what type of hardware would I need to use? The only hardware I thought of is a usb cable and usb port for the hardware end.
04-16-2007, 10:21 AM
It is possible. The Stamp speaks standard asynchronous I/O. If you're using USB, you already have a USB to serial adapter either built into the development board you're using or separate from it and you're using it to program the Stamp. You can use the same adapter to talk to a program. Have a look at the SERIN/SEROUT and DEBUG/DEBUGIN statements in the PBasic manual for the Stamp side of things. You'll have to work out the C# end yourself. The only tricky part is that, if you use the programming port for communications, when the virtual (USB) serial port is opened on the PC, it will reset the Stamp since that's how programming is done. You can disconnect the DTR (reset) line temporarily (when not programming the Stamp) if you need to or you can use a separate USB to serial adapter and a pair of I/O pins for the serial port.
04-16-2007, 10:41 AM
sounds interesting. I was under the assumption that I could get a usb port solder it onto my pcb and connect a usb cable from that to my computer. Then communicate with my i/o leads from the microprocessor to the usb port then to my computer.
04-16-2007, 11:21 AM
USB is a very complex protocol that also requires a lot of high speed bit manipulation, far beyond the capabilities of something like a Stamp or PIC or similar processor that doesn't have special purpose circuitry built-in. There are some special exceptions for things like a mouse or joystick, but even that is usually problematic. FTDI and others have relatively cheap ($30) USB to serial adapter chips that do all the work for you and require a minimum of external parts. One example is: www.saelig.com/miva/merchant.mvc?Screen=PROD&Product_Code=U040&Category_Code=U (http://www.saelig.com/miva/merchant.mvc?Screen=PROD&Product_Code=U040&Category_Code=U) and another is Parallax's PropPlug: www.parallax.com/detail.asp?product_id=32201 (http://www.parallax.com/detail.asp?product_id=32201).
04-16-2007, 11:18 PM
The typical way people do this is to purchase a USB to Serial adapter. They then plug the Serial part of this adapter into the DB-9 connector of the BOE board, and the USB end of it into the PC.
The PC C# program (or whatever) treats the USB adapter as a "COM" serial port. It would be possible to purchase a DB-9 plug, solder some wires to it, and plug those wires into the BOE breadboard. You could then use the USB to Serial adapter with other pins than the BS2 programming port.
However, as Mike says, the 'native' USB protocol is quite involved. There's a 'slave' device, a 'master' device, an identification phase, the 'master' needs to load a 'driver' for the particular 'slave' involved. Unlike RS-232, there's a lot of signalling and communication going on to establish the link. Fortunately, a simple $20 or so USB to Serial adapter handles all of this for you.
So that's the easy way to go. I believe Jan Axelson has written a complete "USB Interfacing" book which covers all the complexities if you really want to go that way. But you could easily spend $3,000 on hardware to get your simple $20 interface working.