visual basic-arduino comminication

hi everyone...

im working on vb(visual basic) for making a interface to arduino. i have a question about that.

i want to see some messages on serialport of ide when i click a button on vb's form. while im using vb form then when i open up serial port monitor on IDE , its not working. i mean ,for example im using COM4, i get message on IDE like " COM4 is busy".

how can i use them all at the same time? is it possible?

thanks in advance..

Serial Monitor uses the one and only hardware serial port on the Arduino Uno.

You'll need to use one of the software serial libraries such as AltSoftSerial GitHub - PaulStoffregen/AltSoftSerial: Software emulated serial using hardware timers for improved compatibility
for communicating with VB

.

Serial monitor can actually use any port :wink:

But a single port on a PC can only be used by one application. So you need two ports (e.g. using a FTDI adapter and software serial on the arduino code).

Why don't you just modify the VB application so it can also receive (and display)?

sterretje:
Serial monitor can actually use any port :wink:

It can?

That news to me, because it has always been set up to use D0 & D1 on my Arduino Uno.

How do I change it to use a different pins on the Arduino Uno?

.

All serial ports show in the IDE. So after an upload, you can change to another one and open serial monitor.

It's not the most convenient way because you have to change back before the upload. Easier to use an additional terminal program for that.

sterretje:
All serial ports show in the IDE. So after an upload, you can change to another one and open serial monitor.

It's not the most convenient way because you have to change back before the upload. Easier to use an additional terminal program for that.

Ah, got it.

The Serial Monitor by default uses the 1 hardware serial port on the Arduino Uno.
That is what I should have written.
The rest of what I wrote remains valid.

.

thx for advices. i have a new question for you guys..

now im loooking a code which i can send data to visual basic from arduino. i searched on the internet and i found this;

Function ReceiveSerialData() As String
   ' Receive strings from a serial port.
   Dim returnStr As String = ""

   Dim com1 As IO.Ports.SerialPort = Nothing
   Try
       com1 = My.Computer.Ports.OpenSerialPort("COM1")
       com1.ReadTimeout = 10000
       Do
           Dim Incoming As String = com1.ReadLine()
           If Incoming Is Nothing Then
               Exit Do
           Else
               returnStr &= Incoming & vbCrLf
           End If
       Loop
   Catch ex As TimeoutException
       returnStr = "Error: Serial Port read timed out."
   Finally
       If com1 IsNot Nothing Then com1.Close()
   End Try

   Return returnStr
End Function

but i dont know how to use this code. i tried couple of times but it didnt work fine. this code is from microsoft official websites. i want to read temprature from ide with visual basic interface.

can u please explain me how can i use this code. thanks.. :slight_smile:

In Vb.Net the following is a good tool to have on hand for serials testing, as is it is set up to display text.

Its up to you to set the port up and open it, The project has a Form with a Rich Text Box.

Imports System.IO.Ports

Public Class Form1

    Public Delegate Sub myDelegate(ByVal myData As Byte)

    Private Sub data_display(ByVal s As Byte)
        RichTextBox1.AppendText(Chr(s.ToString))
    End Sub


    Private Sub SerialPort1_DataReceived(sender As Object, e As SerialDataReceivedEventArgs) Handles SerialPort1.DataReceived
        Dim myData As Byte
        SerialPort1.ReadTimeout = 20

        Do While SerialPort1.BytesToRead > 0
            Try
                myData = CByte(SerialPort1.ReadByte)
                Me.BeginInvoke((New myDelegate(AddressOf data_display)), myData)

            Catch ex As Exception

            End Try
        Loop
    End Sub


End Class

example of a terminal emulator in VB