Santa Fe
Offline
Full Member
Karma: 1
Posts: 192
|
 |
« Reply #15 on: May 07, 2012, 06:08:22 pm » |
Woops! got the "<" and ">" backwards on my last post. They are not consistent with my previous code... sorry. turn them around and try it.
|
|
|
|
|
Logged
|
|
|
|
|
Offline
Newbie
Karma: 0
Posts: 36
|
 |
« Reply #16 on: May 07, 2012, 07:58:44 pm » |
wow very awesome RPCoyle..great  !. i salute you all guys  now when i run the vb application after running the arduino i can access the switch when i press it, then the LED will flash which i find hard before on how to access it..thank you so much RPCoyle  ... one more lacking is to fill the color of the circle; i just use the code you posted RPCoyle then i inserted the cases..here is the code, perhaps you can see if what is the lacking of this. Private Sub MSComm1_OnComm()
MSComm1.Settings = "9600,N,8,1" FoundIt = False ' find USB port ComFail = False FailErr = False For n = 1 To 16 If MSComm1.PortOpen = True Then MSComm1.PortOpen = False On Error Resume Next MSComm1.CommPort = n On Error Resume Next MSComm1.InputLen = 0 MSComm1.PortOpen = True If MSComm1.CommID > 0 Then For i = 1 To 100 Str = "" Str = MSComm1.Input If InStr(Str, "<") > 0 And InStr(Str, ">") > 0 Then GoTo jump: ' in this case the output from Your Arduino would be "< R >" or "< Y >" of < G > ".... Sleep 50 Next i End If Next n If MSComm1.PortOpen = False Then MsgBox "Controller Not functioning , Please check USB connection", vbCritical, "": ComFail = True: Exit Sub
jump: ' your case statement Debug.Print Str; Select Case (Str) ' set a break point here so you can step through the case statement Case "A" Call LEDOn(vbRed) Case "B" Call LEDOn(vbGreen) Case "C" Call LEDOn(vbBlue) Case "D" Call LEDOn(vbYellow) Case Else Call LEDOff End Sub
Private Sub LEDOn(col As Long) End Sub Shape1.FillColor = col End Sub
Private Sub LEDOff() End Sub Shape1.FillColor = vbWhite End Sub
on my arduino code, i just replace the serial.println< "R5"> into < "A" , < "B" > and so on...as what you noted also.
|
|
|
|
|
Logged
|
|
|
|
|
Santa Fe
Offline
Full Member
Karma: 1
Posts: 192
|
 |
« Reply #17 on: May 07, 2012, 09:25:01 pm » |
too many end subs... did this compile? Private Sub LEDOn(col As Long) End Sub Shape1.FillColor = col End Sub
Private Sub LEDOff() End Sub Shape1.FillColor = vbWhite End Sub
On the arduino side you need to output Serial.print("< "); Serial.print(ColorStr); // output to computer USB port Serial.println(">");
On the VB side you need to get the vale back out of the string coming in from the Arduino. Then use ColorStr in your case statement strt = InStr(str, "<") + 1 fin = InStr(str, ">") If (fin - strt) <= 0 Then Exit Function Else ColorStr = Mid(str, strt, (fin - strt)) End If
You should be able to piece this together and get it working. Get one piece working at a time. learn to set breakpoints and step through the VB code. It will help a lot also if you use lots of debug statements till you get the thing worked out
|
|
|
|
|
Logged
|
|
|
|
|
Offline
Newbie
Karma: 0
Posts: 36
|
 |
« Reply #18 on: May 08, 2012, 07:03:10 am » |
hello RPCoyle..sorry for this delay information i just found out when i use to compile the vb application an error message appear which is " Argument not optional" that points on the code Str = ""
1. i can't understand the what does it means.. Private Sub LEDOn(col As Long) End Sub Shape1.FillColor = col //in this code the error appears End Sub
Private Sub LEDOff() End Sub Shape1.FillColor = vbWhite End Sub 2. also this, when i compile an error appear stating " Only comments may appear after End Sub, End Function, or End Property" which points the above code which i commented. 3. learn to set breakpoints and step through the VB code
as what i understand on my research it has something to do with pausing the running mode base on your cursor pointing the code..i don't think if i can really understand it..i was so confuse.  4. Finally, i can't find if where on the code the shape appear.. 
|
|
|
|
|
Logged
|
|
|
|
|
Germany
Offline
Edison Member
Karma: 27
Posts: 1502
|
 |
« Reply #19 on: May 08, 2012, 07:23:23 am » |
Private Sub LEDOn(col As Long) End Sub // this is theoretically correct, but makes no sense Shape1.FillColor = col //in this code the error appears , because VB was told Sub LEDOn has ended already End Sub
I added a comment as well. Same for Sub LEDOff below. This was the reason for RPCoyle's comment "too many End Subs... did this compile?". 1. i can't understand the what does it means.. It's a feature of VB6 to allow lazy programming. Is Dim Str as String
clearer to you? the latter declares a variable and its type, RPCoyle's code implicitly declares it by filling data (An empty sring) in, just to determine its data type. But besides that, you might benefit a lot by learning a bit VB6 usage ( Stepping through code, etc. )
|
|
|
|
|
Logged
|
|
|
|
|
Santa Fe
Offline
Full Member
Karma: 1
Posts: 192
|
 |
« Reply #20 on: May 08, 2012, 09:55:21 am » |
hi Glennmars ... just like michael_x says... It's time you slowed down and started to learn to use the VB and Arduino IDE's
If you don't know even how to set a break point or view a debug window, then you must learn.
If what you are doing is just a one time project, then I think you might be able to work your way through it by just using examples off the internet. If you want to continue you just have to learn your code and that takes time and a hell of a lot of patience.
You already have what you need for the communication between VB and Arduino. That is kind of the hard part. The rest is learning to code in VB6
Good luck
|
|
|
|
|
Logged
|
|
|
|
|
Offline
Newbie
Karma: 0
Posts: 36
|
 |
« Reply #21 on: May 08, 2012, 11:42:22 am » |
Thanks guys..i appreciate your helpfulness  I can’t imagine how I passed by that code without noticing that a double end sub appears,  well thanks again.. RPCoyle thanks, I understand what you mean..hehehe, I just can’t fully understand those other terms in vb that’s why I keep on asking..sorry for that.!.  Anyways, I’m still confuse on the code you posted..just feel free to make this clear to me but if not I understand.. Hmmp, about this code: strt = InStr(str, "<") + 1 fin = InStr(str, ">") If (fin - strt) <= 0 Then Exit Function Else ColorStr = Mid(str, strt, (fin - strt)) End If
You should be able to piece this together and get it working. do you mean that, that code is inserted one by one or they belong to a separate places of the code then i should only determine if where this code fits.?.  Finally, the code of my arduino goes like this: Serial.println ("<Y>"); Serial.print(ColorStr);
is this right.?.or it should be like this: Serial.print("< "); Serial.println ("<Y>") Serial.print(ColorStr); // output to computer USB port Serial.println(">");
i was confused for that..
|
|
|
|
|
Logged
|
|
|
|
|
Santa Fe
Offline
Full Member
Karma: 1
Posts: 192
|
 |
« Reply #22 on: May 08, 2012, 06:41:01 pm » |
Here is some VB6 code I put together from your code... I added a text box as Text1 so that you would know what the pressure is Option Explicit ' this is added to allow the sleep call Private Declare Sub Sleep Lib "kernel32" ( _ ByVal dwMilliseconds As Long)
Private Sub Form_Load() With MSComm1 If .PortOpen Then .PortOpen = False .CommPort = 7 ' *************** YOU MAY NEED TO CHANGE THIS OR ADD MY CODE TO FIND THE COM PORT************************ .Settings = "9600,N,8,1" .DTREnable = True .RTSEnable = True .RThreshold = 4 .SThreshold = 3 .PortOpen = True End With End Sub
Private Sub LEDOn(col As Long)
Shape1.BackColor = col End Sub
Private Sub LEDOff()
Shape1.BackColor = &HFFFFFF End Sub
Private Sub MSComm1_OnComm() Dim strData As String Static strBuffer As String Dim strWords() As String Dim intPos As Integer Dim boComplete As Boolean Dim mystr As String
Sleep 1000 ' this waits one second between readings from the Arduino mystr = "" ' set the string to nothing mystr = MSComm1.Input intPos = InStr(mystr, "<") If intPos > 0 Then Select Case Mid(mystr, 1, 3) ' strip off the CR/LF Case "<Y>" Text1.Text = ("The pressures value is 80 psi") Call LEDOn(&HFFFF&) ' this is in hex Case "<B>" Text1.Text = ("The pressures value is 60 psi") Call LEDOn(&HFF0000) ' this is in hex Case "<R>" Text1.Text = ("The pressures value is 20 psi") Call LEDOn(&HFF&) ' this is in hex Case "<G>" Text1.Text = ("The pressures value is 40 psi") Call LEDOn(&HFF00&) ' this is in hex Case Else Call LEDOff End Select End If
End Sub
here is the Arduino code I used to send the info to the VB code, based on your code. I eliminated some of the logic in your rev because I did not know what it did, and I wonder if you did. It seemed to have njot much to do with what you are looking for. You can put it back in is you need it. void setup() { pinMode(9, OUTPUT); pinMode(10, OUTPUT); pinMode(11, OUTPUT); pinMode(12, OUTPUT); pinMode(2, INPUT); pinMode(3, INPUT); pinMode(4, INPUT); pinMode(5, INPUT); pinMode(7, OUTPUT); Serial.begin (9600); } void loop() {
int a = digitalRead (2); int b = digitalRead (3); int c = digitalRead (4); int d = digitalRead (5); //digitalWrite (7,LOW); { if (a == HIGH) { digitalWrite (9, HIGH); Serial.println ("<R>"); delay (200); digitalWrite (7, HIGH); delay (400); digitalWrite (7, LOW);
} else if (a == LOW) { digitalWrite (9, LOW);
}
if (b == HIGH) { digitalWrite (10, HIGH); Serial.println ("<G>"); delay (200); digitalWrite (7, HIGH); delay (400); digitalWrite (7, LOW); delay (200); digitalWrite (7, HIGH); delay (400); digitalWrite (7, LOW); } else if(b==LOW) { digitalWrite (10, LOW); }
if (c == HIGH) { digitalWrite (11, HIGH); Serial.println ("<B>"); delay (200); digitalWrite (7, HIGH); delay (400); digitalWrite (7, LOW); delay (200); digitalWrite (7, HIGH); delay (400); digitalWrite (7, LOW); delay (200); digitalWrite (7, HIGH); delay (400); digitalWrite (7, LOW); } else if (c==LOW) { digitalWrite (11, LOW); }
if (d == HIGH) { digitalWrite (12, HIGH); Serial.println ("<Y>"); delay (200); digitalWrite (7, HIGH);
} else if (d==LOW) { digitalWrite (12, LOW); }
} }
It works for me... it should work for you... give it a try!
|
|
|
|
|
Logged
|
|
|
|
|
Offline
Newbie
Karma: 0
Posts: 36
|
 |
« Reply #23 on: May 08, 2012, 08:51:10 pm » |
thanks for your reply RPCoyle..how great you are  what you posted on the code on my arduino is same as mine too, but i was so confused about this code that's why i clarify it to you.. Serial.print(ColorStr);
Private Declare Sub Sleep Lib "kernel32" ( _ ByVal dwMilliseconds As Long)
yes, i know this declaration, well thanks for specifying..  strt = InStr(str, "<") + 1 fin = InStr(str, ">") If (fin - strt) <= 0 Then Exit Function Else ColorStr = Mid(str, strt, (fin - strt)) End If
i just want to clarify if the code above should be still inserted or this code below will do it's function: intPos = InStr(mystr, "<") If intPos > 0 Then Select Case Mid(mystr, 1, 3)
thanks 
|
|
|
|
|
Logged
|
|
|
|
|
Santa Fe
Offline
Full Member
Karma: 1
Posts: 192
|
 |
« Reply #24 on: May 08, 2012, 09:08:37 pm » |
just use the code that I posted last... the other code snippets were examples based on some of the things I did to get a temperature reading to control a kiln
|
|
|
|
|
Logged
|
|
|
|
|
Offline
Newbie
Karma: 0
Posts: 36
|
 |
« Reply #25 on: May 08, 2012, 09:22:10 pm » |
okay thanks RPcoyle  i'm so excited to try the code..heheheh, thanks again 
|
|
|
|
|
Logged
|
|
|
|
|
Offline
Newbie
Karma: 0
Posts: 36
|
 |
« Reply #26 on: May 09, 2012, 08:49:58 pm » |
hi again.!. RPCoyle, your right that i should add the code you posted in the code below because when i use to debug this it never finds the comport1, (i already change the commport 7 to commport 1)..let us say that i should close the arduino first before it runs..now, i edit the code and add your code but when i debug the vb application an error prompts me that the < FoundIt does not define.> i search through the net some samples on how it was going to be declared but still i find nothing..Perhaps, you know this much will you please help me again for this..  With MSComm1 If .PortOpen Then .PortOpen = False .CommPort = 7 ' *************** YOU MAY NEED TO CHANGE THIS OR ADD MY CODE TO FIND THE COM PORT************************ .Settings = "9600,N,8,1" .DTREnable = True .RTSEnable = True .RThreshold = 4 .SThreshold = 3 .PortOpen = True
Thanks!
|
|
|
|
|
Logged
|
|
|
|
|
Germany
Offline
Edison Member
Karma: 27
Posts: 1502
|
 |
« Reply #27 on: May 10, 2012, 03:11:20 am » |
Which is your COM port then ? You see/set it in the Arduino IDE, Serial Monitor, and see it when you locate your Arduino among "Printers, Devices" in your Windows Control Panel. For e.g. COM3 you should modify that line to .CommPort = 3 ' *************** YOU MAY NEED TO CHANGE THIS OR ADD MY CODE TO FIND THE COM PORT************************ Alternatively you might try to understand the hint ADD MY CODE TO FIND THE COM PORT this refers to ' find USB port ComFail = False FailErr = False For n = 1 To 16 If MSComm1.PortOpen = True Then MSComm1.PortOpen = False On Error Resume Next MSComm1.CommPort = n ... in Entry 16. Can you guess what these lines are doing ?
|
|
|
|
|
Logged
|
|
|
|
|
Offline
Newbie
Karma: 0
Posts: 36
|
 |
« Reply #28 on: May 21, 2012, 11:51:42 pm » |
hi again!..i feel sorry for the delay.. michael_x..i can see already the comport number when i use to plug the arduino it's comport 1...yet, i set the comport as a .CommPort = 1 and as what you said that i should change or add your code for me to find the comport but when i add your code it prompts an error on: FoundIt = False // in this code an error occur stating that it was not being defined... ' find USB port ComFail = False FailErr = False For n = 1 To 16 ' find USB port ComFail = False FailErr = False For n = 1 To 16 If MSComm1.PortOpen = True Then MSComm1.PortOpen = False On Error Resume Next MSComm1.CommPort = n ... base on my understanding, this line of codes set for finding the comport...
|
|
|
|
|
Logged
|
|
|
|
|
Santa Fe
Offline
Full Member
Karma: 1
Posts: 192
|
 |
« Reply #29 on: May 22, 2012, 10:54:41 am » |
It is hard to believe that your board shows up as COM 1. The computer usually has something at COM 1.
but if the Arduino IDE says it is on COM 1 and you are able to see your output coming through over the serial monitor then it is on COM 1 and the code I gave you should work as long as the output is unclosed in "<" and ">"
If you are mixing the code I gave you with the code Glen gave you, then you might have problems, even though his code is OK. He just uses a "With" statement to streamline the code and it might be a little harder for you to figure out, even though you started out that way. I don't think you understand the fine points.
If you are just using my code, then i really have no idea what the problem might be.
|
|
|
|
|
Logged
|
|
|
|
|
|