Go Down

Topic: Sending a signal to reset the device (Read 852 times) previous topic - next topic

sparticus1701

I've noticed that when the Serial Monitor button is pressed in the Arduino compiler, that it somehow sends a signal that resets the device so that it runs setup() and starts over.

I'm working on a computer program to work with my Uno and I'd like to know how to send this signal.

retrolefty


I've noticed that when the Serial Monitor button is pressed in the Arduino compiler, that it somehow sends a signal that resets the device so that it runs setup() and starts over.

I'm working on a computer program to work with my Uno and I'd like to know how to send this signal.


Simple, the DTR or the RTS comm port control signals are what the arduino uses to cause a auto-reset on the board thus starting the bootloader executing which listens for a little while to see if the arduino IDE is trying to upload a new sketch to the board and if not jumps to any sketch that might have already been loaded onto the board from a prior upload.

So if your PC application can 'talk' to a PC comm port and manipulate the DTR or RTS control signal that is all you need to force a reset on an attached arduino board.

Lefty

sparticus1701

Additional info: I'm using .NET's System.IO.Ports.SerialPort class for communication with the Uno.  The class does have DtrEnable and RtsEnable properties.  I'll post code once I get this working.

retrolefty


Additional info: I'm using .NET's System.IO.Ports.SerialPort class for communication with the Uno.  The class does have DtrEnable and RtsEnable properties.  I'll post code once I get this working.


Well a little more detail from me also. Originally on the first arduino boards that used an auto reset function the RTS signal is what they used to cause the reset condition. Later they started using the DTR signal on the arduino board, so the IDE now pulses both DTR and RTS so that both old and present boards will work. So most likely your arduino board will only respond to the DTR signal unless it's a very old one, so you may have no need to pulse RTS or both, just DTR. That make sense?

Lefty

sparticus1701

I was able to make it work with the code below.  Thanks for the help.


Code: [Select]

class Program
{
static void Main (string[] args)
{
using (SerialPort serial = new SerialPort("COM6", 9600, Parity.None, 8, StopBits.One))
{
try
{
serial.RtsEnable = true;
}
finally
{
}

try
{
serial.DtrEnable = true;
}
finally
{
}

serial.Open();

while (true)
{
System.Windows.Forms.Application.DoEvents();
System.Threading.Thread.Sleep(100);

while (serial.BytesToRead > 0)
{
String strLine = serial.ReadLine().Trim();
Console.WriteLine(strLine);
}

if (Console.KeyAvailable)
{
ConsoleKeyInfo key = Console.ReadKey(false);
Char ch = Char.ToUpper(key.KeyChar);
if (key.KeyChar == 'Q')
break;
else
serial.Write(new Char[] { ch }, 0, 1);
}
}

serial.Close();
}
}
}

PaulS

Code: [Select]
try
{
serial.RtsEnable = true;
}
finally
{
}

Setting a property is hardly likely to fail. The try and finally blocks are unnecessary.

Where in that code do you do anything to reset the Arduino?

It resets when you open the serial port, and again when you close the serial port, but at no other time.

Why do you need to have the PC app reset the Arduino anyway?

Go Up