Arduino Freezes on Serial Connection

hi All,

I’ve written a custom app to log temperature and status data from heating system via my Arduino Duemilanove however the majority of the time when I open the serial port in the app the Arduino freezes up. If I hit the reset button on the Arduino it comes back up fine and the program starts logging data as it should but this isn’t feasible as a long term solution.

Here is the relevant code from my program:

Imports System
Imports System.IO.Ports
Imports System.Timers
Imports System.Data.OleDb
Imports System.Data.Common
Imports System.Data
Module Module1

    Dim message As String

    Dim readthread As Threading.Thread = New Threading.Thread(AddressOf read)

Sub Main()

        'AddHandler mytimer.Elapsed, AddressOf dataInsertTest

        Console.WriteLine("Press the Enter key to exit the program.")

 End Sub

Sub read()
        Dim mySerial As SerialPort
        Dim I As Integer = 0
        mySerial = New SerialPort

        mySerial.PortName = "COM3"
        mySerial.BaudRate = "9600"
        mySerial.Parity = Parity.None
        mySerial.DataBits = 8
        mySerial.StopBits = StopBits.One
        mySerial.Encoding = System.Text.Encoding.ASCII
        mySerial.NewLine = Chr(13) + Chr(10)
        mySerial.ReadTimeout = 30000

        Catch ex As Exception
        End Try
        While (1 < 2)

                message = mySerial.ReadLine()
                If message <> "" Then
                    Console.WriteLine(CStr(Now) + Chr(9) + CStr(message))
                End If
            Catch ex As Exception
            End Try

        End While

    End Sub

Does anyone have any idea why this might be causing the Arduino to freeze? I can use the Arduino serial monitor or a terminal program and it doesn’t cause any problem with the device.

thanks for any help.

Opening the Serial Monitor window causes the Arduino to reset.

What terminal program are you using? It may also be triggering the Arduino to reset.

The SerialPort class in VB has a number of options that you are not setting. One of them causes the Arduino to reset. I don't remember which one, but the text in VB as you check the properties let me figure out what the option was.

How do you know that the Arduino is freezing when you try to connect to it? LED's quit blinking?

thanks for the reply Paul.

I know its freezing as the LCD hooked up locally doesn't update and all of the relays I have connected stop functioning. This presents a real problem as the Arduino is controlling my house's heating system.

I'll check through the options presented in vb to see if I can find the appropriate function.

I used Hyperterminal in Windows.


I think I found the function/setting you were referring to Paul. It’s called DtrEnable.

mySerial.DtrEnable = True… should do the trick. It looks like it has fixed it for other people.

Thank you for your suggestion.

I will test it tonight.

I am having a freezing problem also. I have a bluetooth module which I have setup to autoconnect to my phone. it works great if I try it from boot till about 5 mins. If I leave the program running it stops looping I believe. I have a while loop in main that resets the main loop after 60 seconds, I throw a print statement once it reaches this time. This indicates to me that it is not my bluetooth module locking up but my arduino locking up.

I flush my bluetooth serial line every time something correct has been read, should I flush my serial com line to the computer?

I flush my bluetooth serial line every time something correct has been read

Why? Do you have any idea what data you are throwing away?

I had a similar problem. If you accidentally send a negative number to the delay() function, this can cause the uC to quit responding. Best to use an abs() function on any variables you are sending to delay()... or just be sure it's not negative.

There are no "negative" numbers for delay, its parameter is "unsigned long". So it does not freeze, it just waits - small negative numbers are large unsigned ones....But thise implicite casting is indeed awkward; I should have expected the compiler to complain...