I want to treat Basic Stamp 2 purely as an interface, driven from a Visual Basi
New to Basic Stamps (but not Visual Basic), I want to treat my Basic Stamp 2 (on a Super Carrier board) purely as an interface to up to 8 LEDs, any of which may be switched on or off individually. I thought I could just connect the Stamp to a PC's COMM port and send some appropriate data down to the stamp to get it to switch its various pins high or low.
But I now realise that the Stamp has to be running a program downloaded from the Basic Stamp Development System (BSDS).
I have already worked through the initial Activities involving LEDs in "What's a Microcontroller".
Keeping it simple to begin with, imagine I have 8 low-current LEDs connected to Stamp pins P0 - p7, here's how I see the project:
Write a Stamp program to switch each LED on or off individually on receipt of certain data from the PC. Load the program into the Stamp, then unload the BSDS.
Fire up VB5 or 6 and write a VB program to send suitable data. One possible data format could be: Send a "0", "1", "2" etc to denote the LED required, followed by a "1" or "0" to denote ON or OFF.
Run the VB program. The program uses the MSComm control, opens the relevant COM port, sends the data, e.g. "3", "1", "6", "0" whereupon the Stamp program receives the data, switches LED #3 ON and LED #6 OFF.
Important: The VB program would use the *same* PC-to-Stamp link as the BSDS, namely Sout/Sin via the Super Carrier on-board 9-pin serial connector. That is, I would run BSDS to update the Stamp's running program when required, or run VB to communicate with the Stamp. By the way, I'm not (at least initially) interested in receiving any data FROM the Stamp.
The Stamp would never be operating "standalone", but only when connected to a PC and only to receive data from the PC and act upon it.
Comments? Book recommendations?
Thanks!
But I now realise that the Stamp has to be running a program downloaded from the Basic Stamp Development System (BSDS).
I have already worked through the initial Activities involving LEDs in "What's a Microcontroller".
Keeping it simple to begin with, imagine I have 8 low-current LEDs connected to Stamp pins P0 - p7, here's how I see the project:
Write a Stamp program to switch each LED on or off individually on receipt of certain data from the PC. Load the program into the Stamp, then unload the BSDS.
Fire up VB5 or 6 and write a VB program to send suitable data. One possible data format could be: Send a "0", "1", "2" etc to denote the LED required, followed by a "1" or "0" to denote ON or OFF.
Run the VB program. The program uses the MSComm control, opens the relevant COM port, sends the data, e.g. "3", "1", "6", "0" whereupon the Stamp program receives the data, switches LED #3 ON and LED #6 OFF.
Important: The VB program would use the *same* PC-to-Stamp link as the BSDS, namely Sout/Sin via the Super Carrier on-board 9-pin serial connector. That is, I would run BSDS to update the Stamp's running program when required, or run VB to communicate with the Stamp. By the way, I'm not (at least initially) interested in receiving any data FROM the Stamp.
The Stamp would never be operating "standalone", but only when connected to a PC and only to receive data from the PC and act upon it.
Comments? Book recommendations?
Thanks!
Comments
Option1:
This topic has come up a lot .... All you need to do is write a small program with the basic stamp IDE to react to a serial string sent from the P.C (have a look at SERIN and SEROUT and SERIN pin,Baud,[noparse][[/noparse]str yourstring\length] ) and IF it receives a specific string THEN you can goto a subroutine which changes the state of the I/O's......VB MSComm on the PC to serial port ...
Option2:
You mentioned changing the state of 8 I/O's - there is a DLL written which can be referenced from a VB application which allows you to change the state of D0-D7 - 8 I/O's on a PC parallel port pins 2 to pins 9 (if you have a parallel port).. I have used this previously with addin cards on P.C's with no original parallel port and multiple parallel ports . This was easy in DOS and win95/98 - from win2k and above it became more of an issue so this DLL is the answer .. the DLL is called inpout32.dll - I just wrote a simple VB6·sample for you·- make sure the DLL is in the application path or else copy it to 'system32' folder and register it (regsvr32).. Basically you should be able to address and read any port that is available...you can read back the values using inp ... see sample app..
If you do 'Out(888),255' in the sample app. D0-D7 will be high (8 Pins·logic 1)
If you do 'Out(888),0' in the sample app. D0-D7 will be·low (8 Pins·logic 0)
and all values in between ... remember 0,1,2,4,8,16,32,64,128... for individual O/P's ...... and of course any·value in between .. for combinations ....
look at these...
www.lvr.com/parport.htm
www.logix4u.net/inpout32.htm
for pinout of parallel port -
www.diyha.co.uk/electronics/parallel.html
Hope this helps ...
Regards,
John Twomey
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
'Necessity is the mother of invention'
Post Edited (QuattroRS4) : 8/26/2007 11:29:07 AM GMT
OK - have a look at SERIN and SEROUT and SERIN pin,Baud,[noparse][[/noparse]str yourstring\length] in the BASIC STAMP manual .. I have used a stamp in such a manner a number of years back ..
have a look at SERIN / SEROUT ...
www.parallax.com/dl/docs/prod/stamps/web-BSM-v2.2.pdf
Similar Project (serin/Serout to/from PC serial port) during prototyping ..HERE
and more details
www.parallax.com/html_pages/resources/custapps/app_barracuda.asp
Regards,
John
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
'Necessity is the mother of invention'
Post Edited (QuattroRS4) : 8/26/2007 1:12:09 PM GMT
DO
SERIN 16, baud, [noparse][[/noparse]cmdByte]
OUTL = cmdByte
LOOP
Somewhere in the Stamp docs it says I must specify the pin as 16 to designate the Sin pin on the Stamp. I do not want to faff about with a separate serial link (e.g. with a MAX232) if the onboard 9-pin connector will work from VB (which it apparently will on the Super Carrier board I have).
If only I had my eight low-current LEDs right now, I could try it this very minute (they're on order)! But I only have standard LEDs and I've read somewhere that I should only connect a few of these to the Stamp I/O pins to avoid overloading the Stamp. Not sure what "a few" is, though. Maybe three or four, but I don't want to risk blowing the Stamp up after only using it for a day!
Post Edited (LittleTyke) : 8/26/2007 2:51:29 PM GMT
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
- Stephen
Note:· LED's Connected to Vdd use negative logic, LOW PIN = Lit LED.·
ALSO: $15.00 will by you a pre-assembled RS232 Level converter Building Block from SCHMARTBOARD to save you the hassle of building it yourself.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
There's nothing like a new idea and a warm soldering iron.
Post Edited (pwillard) : 8/26/2007 4:21:57 PM GMT
Each switch adjusts the value of a byte at the PC end although in my case I only used 6 switches. I did the manipulation·by subtracting or adding ·integers when a switch was operated. +-1 , +-2 ,+-4 ,+-8 ,+-16 ,+-32. At the Stamp this can be interpreted however you want, OUTL or OUTH·for direct output or reading individual bits BIT0 BIT1 etc for use internal to the Stamps code.
Using only 6 switches if you wanted to implement OUTX you might mask the input:- Result=In_data & 63
One possible drawback with using the default programming port is that the characters are echoed back to the PC after each transmission and need to be parsed out before transmission of the next data.
Jeff T.
http://forums.parallax.com/showthread.php?p=667413
For the current calculations, take a look in the WaM manual and read the section on Ohms Law. You can use it to determine how much resistance is needed to limit the current at the pins to the correct level.
Also, the BS2 has 4 "banks" of 4 pins each. Each pin has a current limit, and each bank has a limit when usiing multiple pins on the bank. Since you are using 8 LEDs, placing 2 per bank will give you more room for error than 4 per bank.
The room for error factor comes into play in that electronic components generally have a +/- tolerance range that they fall within, especially with resistors.
Post Edited (Kevin Wood) : 8/27/2007 1:01:49 AM GMT
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
(a) cathode to Vss, anode to Stamp I/O pin (turned on with logical one)
or
(b) anode to Vdd, cathode to Stamp I/O pin (turned on with logical zero)
Use of appropriate resistor is assumed in both cases.
Post Edited (LittleTyke) : 8/27/2007 1:09:26 PM GMT
Thus, 'old-timers' like myself will tend to prefer anode to Vdd, cathode toward BS2 I/O pin, and use a "LOW" to turn "ON" the LED.
Now, the PIC chip the BS2 is based on has been engineered to be able to 'source' or 'sink' about the same amount of current. And frankly, it makes more intuitive sense to use a 'HIGH' to turn "ON" the LED. So the bottom line is, with the PIC chip (and BS2) it doesn't really matter which you use. For flexibility and historical purposes, I'd still recommend using the BS2 to 'sink' current.
Another comment: I have just been experimenting with different value resistors, 470 Ohm, 680, 820, 4K7 and there is no appreciable difference in the brightness of the LED. I expected to notice a definite weakness between 470 and 4K7.
And there's a current-to-brightness 'knee' at that 8 mA (or whatever) which means a small increase or decrease in current has large changes in brightness.
Ways to get around this are with "PWM" (Pulse Width Modulation) -- basically you make it 'full bright' for 50% of the time, and 'off' for the other 50%, so the human eye 'averages' this as a 50% 'dim-ness'. That's pretty easy to do with digital circuitry. The other way to get around this is to use a D-to-A converter to lower the voltage (and thus current) through the LED around that "knee". This is much harder to get right, depends on exactly what LED's you're using, and takes more hardware. So most people use "PWM" to change LED brightness.
Now, you can do this with a BS2, but since it only does 'single tasking', you can't use the BS2 "PWM" command to light more than one LED at a time. Bummer. However, since the BS2 runs at about 2000 Instructions Per Second, you CAN use "HIGH" and "LOW" instructions on multiple LED's to implement a "PWM" in PBasic code. Then you just have to worry about your "flash rate" -- how long you leave it on and off.
If you keep your "flash rate" above 60 Hz (8 mSec on, 8 mSec off), then the human eye won't 'see' the separate 'blinks', and will average the LED light into a 'dimness'. This should be very doable with the BS2.
Edit:· Some simple math suggests that with a 4.7 KOhm resistor in series with the LED, you'd be putting about 700 uA through the LED.· This really shouldn't light the LED, so something else must be happening.
The equation is:
5 volts - 1.4 volts(LED voltage) == Voltage across the current limiting resistor, Vr.· == 3.6 volts.
Now, V = IR, so Vr = I * R, or Vr / R == I.· 3.6 / 470 == 7.6 mA, which lights the LED.
3.6 / 4.7K == 765 uA, which shouldn't light the LED.
Post Edited (allanlane5) : 8/27/2007 3:33:20 PM GMT