Pages: [1]   Go Down
Author Topic: arduino + visual basic 2008  (Read 673 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Newbie
*
Karma: 0
Posts: 9
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

hi, i need somebody to help me solve this easy programming.. i tried running simple programming, blinking 3 LEDs at different pin at arduino and control it using VB 2008 and it is works. however, when i tried to do same command bt only blink 1 LED at receiver (pin 13), by using 2 arduinos+xbees as tx and rx, it didnt blink at all.

for transmitting part
Code:
int SerialData = 0;

void setup ()
{
  Serial.begin (9600);
  }

void loop ()
{
  SerialData = Serial.read ();
 
  switch (SerialData)
  {
    case 10:
    Serial.print ('H');
    break;
   
    case 20:
    Serial.print ('L');
    break;
  }
}

for receiving part
Code:
const int ledPin = 13;
int incomingByte;

void setup ()
{
  Serial.begin (9600);
  pinMode (ledPin, OUTPUT);
}

void loop ()
{
  if (Serial.available () > 0)
  {
    incomingByte = Serial.read ();
    if (incomingByte == 'H')
    {
    digitalWrite (ledPin, HIGH);
    }
    if (incomingByte == 'L')
    {
    digitalWrite (ledPin,LOW);
    }
  }
}

visual basic code
Code:
Imports System.IO.Ports.SerialPort

Public Class Form1

    Private Sub form1_formClosing(ByVal sender As Object, ByVal e As System.Windows.Forms.FormClosingEventArgs) Handles MyBase.FormClosing
        If serialport1.IsOpen Then
            SerialPort1.Write(ChrW(100))
        End If
    End Sub

    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

        Dim ports As String() = GetPortNames()
        Dim Port As String

        CbbComport.Items.Clear()

        If ports.Length > 0 Then

            For ii As Integer = 0 To (ports.Length - 1)
                If CInt(ports(ii).Substring(3)) < 10 Then
                    ports(ii) = "COM" & ports(ii).Substring(3)
                End If
            Next

            Array.Sort(ports)

            For ii As Integer = 0 To (ports.Length - 1)
                ports(ii) = "COM" & ports(ii).Substring(3).Trim
            Next

        End If

        For Each Port In ports
            CbbComport.Items.Add(Port)
        Next Port

        BtnConnect.Enabled = False
        BtnDisconnect.Enabled = False

    End Sub

    Private Sub BtnConnect_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BtnConnect.Click

        Try

            BtnConnect.Enabled = False
            BtnDisconnect.Enabled = True
            CbbComport.Enabled = False

            SerialPort1.PortName = CbbComport.Text
            SerialPort1.BaudRate = 9600
            SerialPort1.Open()

            Timer1.Enabled = True

        Catch ex As Exception

            BtnConnect.Enabled = True
            BtnDisconnect.Enabled = False
            CbbComport.Enabled = True

        End Try

    End Sub

    Private Sub BtnOn_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BtnOn.Click
        If SerialPort1.IsOpen Then
            SerialPort1.Write(ChrW(10))
        End If
    End Sub

    Private Sub BtnOff_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BtnOff.Click
        If SerialPort1.IsOpen Then
            SerialPort1.Write(ChrW(20))
        End If
    End Sub

    Private Sub CbbComport_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles CbbComport.SelectedIndexChanged
        BtnConnect.Enabled = True
        BtnDisconnect.Enabled = False
    End Sub
End Class

i need to know why is my LED at reciver part didnt blik at all..please help me.. thanx
is it i have to change my serial.print () to digital.read () at transmitter part??
Logged

Seattle, WA USA
Offline Offline
Brattain Member
*****
Karma: 601
Posts: 48556
Seattle, WA USA
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
however, when i tried to do same command bt only blink 1 LED at receiver (pin 13), by using 2 arduinos+xbees as tx and rx, it didnt blink at all.
If you remove the wire, and replace it with a wireless link, and it (whatever it is) no longer works, how can that be a coding issue?

It looks to me like you have not configured your XBees correctly. You haven't even mentioned what kind they are, or how (or even if) you have configured them.
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 9
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset


It looks to me like you have not configured your XBees correctly. You haven't even mentioned what kind they are, or how (or even if) you have configured them.

i did configure it like you told before in another forum(topic)..and it's work when i insert the coding like below.. only when i add some coding to make it works with vb, it didnt blink at all. here is the code without inserting vb..

transmitting part
Code:
void setup ()
{
  Serial.begin (9600);
  }

void loop ()
{
  Serial.print ('H');
  delay (2000);
  Serial.print ('L');
  delay (2000);
}

receiver part is same like previous..i did not change anything..
Logged

Anchorage, AK
Offline Offline
Edison Member
*
Karma: 42
Posts: 1176
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
Code:
SerialPort1.Write(ChrW(10))

Disclaimer:  I haven't touched Visual Basic since Microsoft called for a complete language do-over after 6.0.  After the .NET makeover, it was just too hideous to stomach anymore.

So, maybe I'm jumping to conclusions here, but from that line it looks like you might be sending WIDE characters.

Wide characters are Unicode-style 16-bit (2-byte) characters.  Your Arduino sketch is expecting a single-byte (8-bit) char.
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 9
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

thanx for helping SirNickity, i'll fix it.. smiley-grin
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 9
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

ok, i already figure something. at our arduino board have TX abd RX 'pin' right ??

1) i try to modified my coding and do xbee-xbee connection wirelessly (success).
2) i try to do vb-xbee by wired (success). the TX and RX light is blinking to when i click button on vb.

but, when i do vb-xbee(1st)-xbee(2nd) wirelessly..
1) the 1st xbee did not transmit any data to 2nd xbee
2) only RX light at 1st xbee is blinking.

what can i do to make it communicate wirelessly ?? can somebody help me?? please =___=".. i appreciate it.
Logged

Pages: [1]   Go Up
Jump to: