Offline
Newbie
Karma: 0
Posts: 36
|
 |
« on: May 03, 2012, 03:07:58 am » |
hi! can you help me please in right coding the arduino and the vb6...i find hard in communicating the two devices which is the arduino and the vb6. here is my code: for arduino: 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 ("Red is the color of Led/ The pressures value is 20psi"); 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 ("Green is the color of Led/The pressures value is 40psi"); 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 ("Blue is the color of Led/The pressures value is 60psi"); 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 ("Yellow is the color of Led/The pressures value is 80psi"); delay (200); digitalWrite (7, HIGH);
} else if (d==LOW) { digitalWrite (12, LOW); }
} }
here is my vb code: Option Explicit
Private Sub Form_Load() With MSComm1 If .PortOpen Then .PortOpen = False .CommPort = 1 .Settings = "19200,N,8,1" .DTREnable = True .RTSEnable = True .RThreshold = 4 .SThreshold = 3 .PortOpen = True End With With Shape1 Shape1.Shape = 3 'Circle Shape1.Height = 555 Shape1.Width = 555 Shape1.FillColor = vbWhite Shape1.FillStyle = 0 'Solid End With 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
Private Sub MSComm1_OnComm() Dim strData As String Static strBuffer As String Dim strWords() As String Dim intPos As Integer Dim boComplete As Boolean Select Case MSComm1.CommEvent Case comEvReceive strData = MSComm1.Input strBuffer = strBuffer & strData Do intPos = InStr(strBuffer, vbCrLf) If intPos > 0 Then strWords = Split(strBuffer, " ") Select Case UCase(strWords(1)) 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 Select If intPos + 2 < Len(strBuffer) Then strBuffer = Mid(strBuffer, intPos + 2) Else strBuffer = "" boComplete = True End If Else boComplete = True End If Loop Until boComplete = True End Select End Sub
|
|
|
|
|
Logged
|
|
|
|
|
Germany
Offline
Edison Member
Karma: 28
Posts: 1583
|
 |
« Reply #1 on: May 03, 2012, 03:44:12 am » |
1) What about first having the same communication speed on both sides? (Arduino uses 9600, VB uses 19200) 2) What about getting something easier to run first? Arduino sends something like "Red is the color of Led/ The pressures value is 20psi" Your VB code seems to draw colored circles controlled by characters found in that string Is that what you intend to get ? (If I got that wrong, please tell what the code is supposed to do, and what it does instead) 3) What do you see while debugging your VB code ? 4) Select Case UCase(strWords(1)) Case "a" Call LEDOn(vbRed) IMO UCase() will never return a lower case character.
|
|
|
|
« Last Edit: May 03, 2012, 03:48:57 am by michael_x »
|
Logged
|
|
|
|
|
Offline
Newbie
Karma: 0
Posts: 36
|
 |
« Reply #2 on: May 03, 2012, 05:18:06 am » |
thanks for replying me, actually i'm just a newbie about arduino and vb..i have ideas but it's only a sort of idea.. 1. yah, i got mistaken on setting my baud rates..thanks for that  2. yes something like that; the flow would be like this.. when the input is hit it prompts the characters found in serial.print then the indicator which led will turned on.(this will be the flow in arduino) now i want this to simulate by vb, a shape of circle which filled by color when the above is happen in the arduino or else any representation that will simulate the above.. 3. when i run the vb code the only thing that appears is the circle then when i hit the button which came from the arduino nothings happen.. 4. so it should be that in capital letter..thanks for that by the way, as i run the arduino and vb it should be that one of them is not in running mode..it seems, if i run the vb code i should close the serial monitor of the arduino same as the other one.
|
|
|
|
|
Logged
|
|
|
|
|
Germany
Offline
Edison Member
Karma: 28
Posts: 1583
|
 |
« Reply #3 on: May 03, 2012, 10:23:23 am » |
if i run the vb code i should close the serial monitor of the arduino Sure. If one application has opened the serial connection, the other cannot connect and will show an error. when the input is hit it prompts the characters found in Serial.print It's nice to have a verbose text in Serial Monitor, but for your VB code it would be easier just to receive few (single) characters. Anyway, VB is easy to debug, and once you get the same message in your VB code as you saw in Serial Monitor, you're in the wrong forum here (I don't have VB6 any more)
|
|
|
|
|
Logged
|
|
|
|
|
Offline
Newbie
Karma: 0
Posts: 36
|
 |
« Reply #4 on: May 03, 2012, 06:21:26 pm » |
is it possible that the arduino can control the vb6?
in communicating the arduino to vb is it necessary to use the Rx Tx? or the program that Ive been posted will do.?.
THANKS!!!
|
|
|
|
|
Logged
|
|
|
|
|
Germany
Offline
Edison Member
Karma: 28
Posts: 1583
|
 |
« Reply #5 on: May 04, 2012, 05:03:12 am » |
is it possible that the arduino can control the vb6?
Not sure if I understand your question. Of course your VB exe has to be started somehow and has to open the right COM port ( MSComm in VB6, I assume) properly. Then it can listen and thus be controlled by your arduino. communicating the arduino to vb is it necessary to use the Rx Tx I prefer to call it Serial on the Arduino side. necessary? That's by far the easiest way to communicate, if a USB cable is available.
|
|
|
|
|
Logged
|
|
|
|
|
Seattle, WA USA
Offline
Brattain Member
Karma: 332
Posts: 36396
Seattle, WA USA
|
 |
« Reply #6 on: May 04, 2012, 07:07:00 pm » |
in communicating the arduino to vb is it necessary to use the Rx Tx? No, of course not. Your PC is equipped to read smoke signals, right? No? Morse code? Maybe it can see the Arduino waving semaphore flags? No? Damn, then I guess you ARE stuck using the serial port.
|
|
|
|
|
Logged
|
|
|
|
|
Offline
Newbie
Karma: 0
Posts: 36
|
 |
« Reply #7 on: May 04, 2012, 08:26:59 pm » |
thanks for your reply..hehe, anyways i was doubt about the rx/tx that's why i'm asking coz i am pretty sure that you know better the arduino.. if that so, is there any suggestions that you may give to me on how to communicate or interface the arduino to vb6.?. i've done so many research but still it doesn't work..the code i posted can you check if what are the lacking codes.?.
thanks!
|
|
|
|
|
Logged
|
|
|
|
|
Germany
Offline
Edison Member
Karma: 28
Posts: 1583
|
 |
« Reply #8 on: May 05, 2012, 06:55:06 am » |
You are able to get Serial Monitor tool in the Arduino IDE to run and see output coming from Arduino, Right? Then close it and start/debug a VB6 application which opens the same COM port and has an event handler on incoming data. Once you see something arriving, you're done (from the arduino point of view) ... Ah, I see from your other thread you're obviously a step ahead already. Let's abandon this one. One last hint: If you want to send both verbose texts and "Commands" , perhaps you distinguish them by a special first character of a new line : Serial.println("Anything to be put into a text box for debugging, logging, etc. "); Serial.println("#R"); // A command meaning " Paint Circle in Red" ...
|
|
|
|
« Last Edit: May 05, 2012, 07:05:01 am by michael_x »
|
Logged
|
|
|
|
|
Offline
Newbie
Karma: 0
Posts: 36
|
 |
« Reply #9 on: May 05, 2012, 10:15:42 pm » |
thanks for replying michael_x  Then close it and start/debug a VB6 application which opens the same COM port and has an event handler on incoming data. Once you see something arriving, you're done (from the arduino point of view) ...
awesome, it's helpful..  , but still my vb code does not receive any data...  Serial.println("#R"); // A command meaning " Paint Circle in Red" ...
should i have to change my code in arduino into this?..hehe, i don't know the < # > means.. perhaps you can link me to my other thread..
|
|
|
|
|
Logged
|
|
|
|
|
Gosport, UK
Offline
Faraday Member
Karma: 19
Posts: 3117
|
 |
« Reply #10 on: May 06, 2012, 02:39:26 am » |
|
|
|
|
|
Logged
|
|
|
|
|
Offline
Newbie
Karma: 0
Posts: 36
|
 |
« Reply #11 on: May 06, 2012, 05:49:14 am » |
yeah, i feel sorry for this..then, let's merged them.. sorry for this inconvenience becausei don't know how to link the two.. 
|
|
|
|
|
Logged
|
|
|
|
|
Santa Fe
Offline
Full Member
Karma: 1
Posts: 193
|
 |
« Reply #12 on: May 06, 2012, 09:24:04 pm » |
try this ... ' set up for the input....
str = MSComm1.Input ' get the string str = Left(str,1) ' chops off the first char Debug.Print ">" str "<" ' now you can see what is comming through in the immediate window of VB 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 Select 'on the Arduino side just send out:
'Serial.println("A")
'why send out a whole line of text if you don't need it
|
|
|
|
|
Logged
|
|
|
|
|
Offline
Newbie
Karma: 0
Posts: 36
|
 |
« Reply #13 on: May 06, 2012, 10:25:10 pm » |
thanks RPCoyle for your suggestions  i tried the code but still nothing sends to the vb.. 
|
|
|
|
|
Logged
|
|
|
|
|
Santa Fe
Offline
Full Member
Karma: 1
Posts: 193
|
 |
« Reply #14 on: May 07, 2012, 06:03:35 pm » |
You may be finding the wrong com port. You have COM1 hardwired into the VB code. You need to look at what the Arduino IDE is using for your board and use that instead The code below is what I use to make sure that I am seeing output from my board. It look for a specific string input and then selects that COM port You can tweak the code to give you what you want 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
|
|
|
|
|
Logged
|
|
|
|
|
|