简体   繁体   中英

How do I reset my Arduino Mega2560 with my C# application?

I noticed the Arduino IDE automatically resets on startup/exit by the built in serial application due to

one of the hardware flow control lines (DTR) of the FT232RL is connected to the reset line of the ATmega1280 via a 100 nanofarad capacitor. When this line is asserted (taken low), the reset line drops long enough to reset the chip.

I noticed that behaviour does not happen with my serial C# application. I would like the reset feature to work with my C# application. What am I not doing to get my Arduino Mega to reset by my C# application?

Working Code for Arduino and C#:

I got it working in about 5 minutes by hooking up a wire from PWM Port12 to the RESET Port. On the Arduino, I checked for the text RESET on the incoming SerialEvent3. When RESET is found do:

pinMode(7, OUTPUT);  
digitalWrite(7, LOW);

As for as the C# it was as simple as:

if (serialPort1.IsOpen)
{ 
    serialPort1.Write("RESET"); 
}

Reset seems to work as expected.

DTR works fine for me from the .NET SerialPort class.

Just set the property:

port.DtrEnable = true;

I have noticed different defaults if you use the SerialPort in the WinForms designer, but DtrEnable is in fact true (by default) when using it from a console app.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM