Talking to Visual Basic or any other program?

So basically I got my arduino to spit out either a one when my room is lit and a 0 when it's dark. I was told I can use visual basic or processing to log what time a 1 was displayed and log it so I can see when my light was turned on?

Anyone know how to do this or where I can find out?

KE7GKP:
The next step appears to be getting the PC to talk to the Aduino. That probably means figuring out how to talk to serial port "COMx" (where "x" is the number of the Arduino's USB virtual port.)

Ok well my serial port is Com 3 and /device/USBSER000 is the port name or value or whatever. Now I need to know how to send this to processing or VB and log the time at which this happens

Now I need to know how to send this to processing or VB and log the time at which this happens

More accurately, now you need to write a program in VB or Processing that will communicate with the Arduino on the assigned com port, read the PC system clock and write to a log file.

Lefty

This will read and display data from a serial port, you should be able to modify for your application.

Public Class Form1
    Dim stop_serial As Boolean = False


    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        Dim i As Long
        TextBox1.Clear()
        Do
            Try
                i = SerialPort1.ReadByte()
                TextBox1.Text = TextBox1.Text + Str(i) + "-"
                TextBox1.Refresh()
            Catch ex As Exception
            End Try
            Application.DoEvents()
        Loop While Not stop_serial

    End Sub

    Private Sub Form1_Disposed(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Disposed
        If SerialPort1.IsOpen() Then
            SerialPort1.Close()
        End If

    End Sub

    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        SerialPort1.PortName = "Com37"
        SerialPort1.ReadTimeout = 10

        SerialPort1.Open()
    End Sub

    Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
        stop_serial = True
    End Sub
End Class

Rob

KE7GKP:
Getting a VB program to talk to a serial port is almost certainly a VB FAQ. You should be able to find at least a dozen good answers to that question in less than 60 seconds on Google. But you won't find much good VB help here in the Arduino forum.

Note that there are simpler ways of implementing your project that don't require a whole Arduino microcontroller. For example, the "USB Bitwhacker": USB Bit Whacker - 18F2553 Development Board - DEV-00762 - SparkFun Electronics

Why would he do that? The UBW is no simpler, its just a different micro. Arduinos are the same price, and you get more I/Os....If you really wanted simplicity, you could just use a usb-serial adapter and use the GPIOs on that. But those are $15 too...

Graynomad:
This will read and display data from a serial port, you should be able to modify for your application.

Public Class Form1

Dim stop_serial As Boolean = False

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        Dim i As Long
        TextBox1.Clear()
        Do
            Try
                i = SerialPort1.ReadByte()
                TextBox1.Text = TextBox1.Text + Str(i) + "-"
                TextBox1.Refresh()
            Catch ex As Exception
            End Try
            Application.DoEvents()
        Loop While Not stop_serial

End Sub

Private Sub Form1_Disposed(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Disposed
        If SerialPort1.IsOpen() Then
            SerialPort1.Close()
        End If

End Sub

Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        SerialPort1.PortName = "Com37"
        SerialPort1.ReadTimeout = 10

SerialPort1.Open()
    End Sub

Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
        stop_serial = True
    End Sub
End Class




______
Rob

thanks alot! But how would I modify it? I mean I don't know the first thing about visual basic. And how would I add in the time?

I haven't got the time or hardware to test anything right now, have a look at the Now() function, that gives you the time in this format

23/02/2011 1:17:39 PM

so you can add that to the data being printed.


Rob

Graynomad:
I haven't got the time or hardware to test anything right now, have a look at the Now() function, that gives you the time in this format

23/02/2011 1:17:39 PM

so you can add that to the data being printed.


Rob

ok but this is all REALLY confusing. I just want the text box to display the time when the serial port send the number 1 to VB and to display nothing when it send a 0.

OK this appears to work

   Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        Dim i As Integer
        Dim last_i As Integer = 255
        TextBox1.Clear()
        Do
            Try
                i = SerialPort1.ReadByte()
                If i <> last_i Then
                    TextBox1.Text = TextBox1.Text + Str(i) + "  " + Now + vbCrLf
                    TextBox1.Refresh()
                    last_i = i
                End If
            Catch ex As Exception
            End Try
            Application.DoEvents()
        Loop While Not stop_serial

    End Sub

It doesn't test for 0 and 1, just a change in the character received which in your case is the same thing. It will print the time for light on and off.


Rob

I mean I don't know the first thing about visual basic.

Look at your subject line. If you don't know the first thing about Visual Basic, why do you want to use it to communicate with the Arduino?

If you know some other language, use that. If this is homework, do yourself a favor and LEARN the language. If it is not homework, do a better job of explaining your background/skills/needs up front.