BASIC STAMP II + USB Cx
Rf
Posts: 11
Hi guys,
I am a newbie with the Stamp so I need your help.
Using the Stampworks development board, I am trying to communicate with my Stamp to turn a led on/off following the suggestions from some of your postings of going from simple to complex.
The board came with a USB cable and it is my understanding that this is a serial kind of commnication as well. In my case, I am using COM8. When I send the following code to the EEPROM using the Parallax Basic Stamp Editor (COM8), it works like a champ but when I use VB .NET it doesn't. The .NET code is very simple and it uses a class that allows to send and read data via COM ports. If needed, I will post the VB code in future postings. Here is the code from the Parallax Editor:
'···· {$STAMP BS2}
'···· {$PBASIC 2.5}
·
command VAR Byte
ledOut4 PIN 4
x1····· VAR·· Nib
·
·
One:
FOR x1 = 1 TO 5
HIGH ledOut4
PAUSE 500
LOW ledOut4
PAUSE 500
NEXT
GOTO Main
·
Main:
·
command = 0
SERIN 16, 16780, [noparse][[/noparse]command]
PAUSE 500
BRANCH command, [noparse][[/noparse]One]
PAUSE 500
GOTO Main
Thank you in advance!
Roger
I am a newbie with the Stamp so I need your help.
Using the Stampworks development board, I am trying to communicate with my Stamp to turn a led on/off following the suggestions from some of your postings of going from simple to complex.
The board came with a USB cable and it is my understanding that this is a serial kind of commnication as well. In my case, I am using COM8. When I send the following code to the EEPROM using the Parallax Basic Stamp Editor (COM8), it works like a champ but when I use VB .NET it doesn't. The .NET code is very simple and it uses a class that allows to send and read data via COM ports. If needed, I will post the VB code in future postings. Here is the code from the Parallax Editor:
'···· {$STAMP BS2}
'···· {$PBASIC 2.5}
·
command VAR Byte
ledOut4 PIN 4
x1····· VAR·· Nib
·
·
One:
FOR x1 = 1 TO 5
HIGH ledOut4
PAUSE 500
LOW ledOut4
PAUSE 500
NEXT
GOTO Main
·
Main:
·
command = 0
SERIN 16, 16780, [noparse][[/noparse]command]
PAUSE 500
BRANCH command, [noparse][[/noparse]One]
PAUSE 500
GOTO Main
Thank you in advance!
Roger
Comments
The only thing wrong now must be your software... The VB .NET may help.
Oh, and note when you open a serial port in Windows (using Hyperterm, for example) it has a nasty tendency to keep DTR active. DTR is the reset signal for the BS2. Now, the BOE board has a couple of capacitors to decouple the reset signal -- but when Hyperterm comes up, it still resets it once.
I think you need to 'attach' the VB code to a message and let us see it.
Thank you in advance. Here is my VB .NET 2003 code. I have a form with three buttons: open port, Tx, and Read; and two textboxes, one to write and code to send and the other one to receive (read).
Public Class Form1
Inherits System.Windows.Forms.Form
Dim setrs232 As New rs232
#Region " Windows Form Designer generated code "
Public Sub New()
MyBase.New()
'This call is required by the Windows Form Designer.
InitializeComponent()
'Add any initialization after the InitializeComponent() call
End Sub
'Form overrides dispose to clean up the component list.
Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)
If disposing Then
If Not (components Is Nothing) Then
components.Dispose()
End If
End If
MyBase.Dispose(disposing)
End Sub
'Required by the Windows Form Designer
Private components As System.ComponentModel.IContainer
'NOTE: The following procedure is required by the Windows Form Designer
'It can be modified using the Windows Form Designer.
'Do not modify it using the code editor.
Friend WithEvents Button1 As System.Windows.Forms.Button
Friend WithEvents TextBox1 As System.Windows.Forms.TextBox
Friend WithEvents button2 As System.Windows.Forms.Button
Friend WithEvents Button3 As System.Windows.Forms.Button
Friend WithEvents TextBox2 As System.Windows.Forms.TextBox
Friend WithEvents Button4 As System.Windows.Forms.Button
<System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
Me.Button1 = New System.Windows.Forms.Button
Me.TextBox1 = New System.Windows.Forms.TextBox
Me.button2 = New System.Windows.Forms.Button
Me.Button3 = New System.Windows.Forms.Button
Me.TextBox2 = New System.Windows.Forms.TextBox
Me.Button4 = New System.Windows.Forms.Button
Me.SuspendLayout()
'
'Button1
'
Me.Button1.Location = New System.Drawing.Point(24, 24)
Me.Button1.Name = "Button1"
Me.Button1.Size = New System.Drawing.Size(104, 40)
Me.Button1.TabIndex = 0
Me.Button1.Text = "Open Port"
'
'TextBox1
'
Me.TextBox1.Location = New System.Drawing.Point(24, 80)
Me.TextBox1.Multiline = True
Me.TextBox1.Name = "TextBox1"
Me.TextBox1.ScrollBars = System.Windows.Forms.ScrollBars.Both
Me.TextBox1.Size = New System.Drawing.Size(696, 152)
Me.TextBox1.TabIndex = 1
Me.TextBox1.Text = ""
'
'button2
'
Me.button2.Location = New System.Drawing.Point(624, 24)
Me.button2.Name = "button2"
Me.button2.Size = New System.Drawing.Size(104, 40)
Me.button2.TabIndex = 2
Me.button2.Text = "Tx"
'
'Button3
'
Me.Button3.Location = New System.Drawing.Point(316, 24)
Me.Button3.Name = "Button3"
Me.Button3.Size = New System.Drawing.Size(104, 40)
Me.Button3.TabIndex = 3
Me.Button3.Text = "Close Port"
'
'TextBox2
'
Me.TextBox2.Location = New System.Drawing.Point(24, 248)
Me.TextBox2.Multiline = True
Me.TextBox2.Name = "TextBox2"
Me.TextBox2.ScrollBars = System.Windows.Forms.ScrollBars.Vertical
Me.TextBox2.Size = New System.Drawing.Size(696, 144)
Me.TextBox2.TabIndex = 4
Me.TextBox2.Text = ""
'
'Button4
'
Me.Button4.Location = New System.Drawing.Point(608, 424)
Me.Button4.Name = "Button4"
Me.Button4.Size = New System.Drawing.Size(104, 40)
Me.Button4.TabIndex = 5
Me.Button4.Text = "Read"
'
'Form1
'
Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13)
Me.ClientSize = New System.Drawing.Size(736, 476)
Me.Controls.Add(Me.Button4)
Me.Controls.Add(Me.TextBox2)
Me.Controls.Add(Me.Button3)
Me.Controls.Add(Me.button2)
Me.Controls.Add(Me.TextBox1)
Me.Controls.Add(Me.Button1)
Me.Name = "Form1"
Me.Text = "Form1"
Me.ResumeLayout(False)
End Sub
#End Region
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
setrs232.Open()
End Sub
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
With setrs232
.Port = 8
.BaudRate = 2400
.DataBit = 8
.StopBit = Rs232.DataStopBit.StopBit_1
.Parity = Rs232.DataParity.Parity_None
.Timeout = 1500
End With
End Sub
Private Sub button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles button2.Click
setrs232.Write(TextBox1.Text)
End Sub
Private Sub TextBox1_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TextBox1.TextChanged
End Sub
Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
setrs232.Close()
End Sub
Private Sub Button4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button4.Click
setrs232.Read(200)
TextBox2.Text = setrs232.InputStreamString
End Sub
End Class
I don't know where you got that SERIN baud selector of "16780". For a BS2, 9600 baud is selected with 16468.
And in your VB code, you're selecting 2400 baud. No wonder they can't talk to each other. For a BS2, 2400 baud would be 16780 -- oh, look, there it is!
Okay, so that's right. Hmm again. You might want to set DTREnable to FALSE (if there IS such a property).
Now, you're aware the BS2 is only 'listening' when its actually IN the SERIN command, right? Also, that you've only told the BS2 to recieve ONE BYTE. You might want to use the "DEC" modifier in the BS2. That way, when you send "0 <cr>", it will convert it to a zero byte, and "1 <cr>" will convert to a '1' value so your Branch will work properly.
Oh, and you probably want:
Branch Command, [noparse][[/noparse]Zero, One]
Zero:
' Etc....
Because the first element IS the 'Zero' select one, the second element is the '1' select one.
I am kind of getting sick of fighting the USB connection and if that doesn't work, I will try to go through the DB9 and make the proper connections on the development board. I can't figure out why is not doing the trick. [noparse]:([/noparse]
BTW there is a propery for DTR so I will add DTR = FALSE to my code and let's see if I have better luck.
Thanks again!
After learning the trick, I think I can take it from there.
Is funny because SEROUT works great for me when I open hyperterminal but SERIN doesn't send anything from the PC to the BS2. I checked the speed (9600) and that looks correct. I tried different combinations with DTR and RTS but nothing helped.
If I download the program for the led to the EEPROM and I just open the port from .NET the led starts flashing.
Is terrible being a newbie.....! :=(
Thank you again in advance!
If you used a 'SERIN' on the BS2, it should 'pend' forever on that SERIN until SOME data comes in to the BS2.
What bothers me is that the Editor works really well sending the program down to the BS2. lol
Thanks a lot for your posting allan.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
1 + 1 = Window
/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\
0............................................0
0............................................0
0.(Microman171@hotmail.com)..0
0............................................0
0............................................0
\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/
The Stamp is programmed by the Parallax provided editor (also called the IDE...and yes, I'm glossing over any 3rd-party stuff using the Parallax libraries...). If you can program your Stamp using the IDE, then the cable and setup you have are good and any difficulty in communicating with your Stamp program is most likely an error in your code, either on the Stamp side (PBASIC) or on the PC side (VB, C, Delphi, .net, etc...). Remember that many languages on the PC side that have facility to communicate through the serial port raise the DTR line by default. This is a signal to the Stamp to reset itself (and STAY reset as long as the DTR is held high). The documentation of your PC programming language of choice should indicate how you can handle the DTR signal.
If you haven't programmed the Stamp or do not understand how to write a program to DO something with serial data, then I would recommend some more study...the free "What's a Microcontroller?" course is high on my list of recommendations...
Sorry if this sounded surly...
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Truly Understand the Fundamentals and the Path will be so much easier...
Post Edited (Tom Walker) : 1/11/2006 2:45:20 PM GMT
Charlie
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Truly Understand the Fundamentals and the Path will be so much easier...
·· You are correct, once the VCP Driver is installed all applications accessing that port should only "see" a COM Port.· Now on your other statement regarding DTR, this only affects Stamp Modules not protected by the 2 .1uF capacitors we install on our development boards.· These capacitors prevent the ATN line from being held HIGH by DTR, although it doesn't rule out DTR as an issue for programming, necessarily.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Chris Savage
Parallax Tech Support
csavage@parallax.com
Charlie
Thanks for this exchange of information. I am using a 2003 and the class I am using has the DTR property which I set as follows:
With setrs232
.Port = 8
.BaudRate = 2400
.DataBit = 8
.StopBit = Rs232.DataStopBit.StopBit_1
.Parity = Rs232.DataParity.Parity_None
.Timeout = 1500
.DTR=FALSE
End With
I know I have the correct COM port (which BTW I can change via OS to any port I want) because if I program the BS2 and open my port from VB .NET 2003, my leds start blinking. Besides, all my programs run using the Parallax Editor (cheers to parallax!).
My major concern using SERIN is about timing since I know that the processor won't be waiting forever to receive my code. Any thoughts on that?
Thanks a lot!
Roger
2. EVERYTHING sent to the BS2 over port 16 gets echoed (by the BS2 hardware) back to the sender. Be aware of this, and toss your echo before you process the BS2 reply.
3. You can implement a simple 'ack' 'nack' protocol with the BS2. Start with a sync character (like an $01), send your data, then send a 'end' character (like an $02). The BS2 should send back a $03 when it gets a 'full' message, and send nothing or an $04 when it gets a 'garbled' message.
Thanks Allan! I have to read more about hand-shaking. I don't have a clue how to implement the ack-nack routines.
·