Reset an Arduino?

I was wondering if anyone had figured out how to do a reset of an Arduino from an xojo program?

When you fire up the Arduino serial window it resets the Arduino, that’s what I’m looking for.

The problem I’m having is that every time a user shuts down their PC, the next time they restart it’s uncertain if the Arduino works, sometimes it starts working, sometimes it’s just dead until it’s reset.

Only way to be sure is to reset it, either by hitting the reset button (Not an option as it’s built into a case and I don’t want to have people messing with it)

Supposedly you just need to set DTR low for one pulse, but I’m having no luck with that.

You can do a soft reset with "asm volatile (“jmp 0”); " but that doesn’t reset peripherals and registers which my program relies heavily on (Lots of probes with peripheral breakout stamps that needs to be reset also)

Anyone have any pointers?

It’s been a while since I’ve done anything with an arduino so I’m not sure but if I recall each time you open a connection to it the arduino will reset. If that’s the case, can you close your serial connection and then reopen it?

On one of the devices I was working on, I made a reset button accessible outside the casing.

It doesn’t seem to work like that anymore unfortunately.

It’s just that if/when the user reboots, the USB to serial for some reason stops working until a reset, not always which is puzzling, sometimes it works, other times not.

The Arduino IDE serial monitor resets the Arduino correctly when you load it after the Arduino has stopped responding, so I’m trying to figure out just what the Arduino IDE serial window is sending to make that happen.

I tried the asm jmp 0 workaround, it works as in the program resets, but leaves the breakout stamps in limbo so they stop working when the Arduino comes back after the soft reset.

It’s pretty crucial that the software can connect back up to the Arduino after a power outage so even though a reset button on the case would work for manual interaction, it needs to work as unattended as possible. (Power outage at night for example)

There’s a way to implement a watchdog that needs to be reset every x seconds or it will do a hard reset, that sounds like what I need to be looking at if I can’t make this work.

Well that makes sense. I hadn’t considered overnight contingencies.

Sounds like you would do this in the arduino code? If so do you mind telling me how you would go about it?

It’s basically a mode you activate via a function and an interval like 2 or 4 seconds, the watchdog starts running, and if it doesn’t get reset via a reset function, it hard reboots the Arduino once the interval is up.

There’s a good explanation here:

http://www.leonardomiliani.com/2013/impariamo-ad-usare-il-watchdog-1/?lang=en

If I can’t get a hard reset working from xojo code, I think I’m just going to implement it and have my controlling software send a heartbeat reset command every say 1 second, it the Arduino doesn’t get the reset (PC restarted and unable to communicate) then the Arduino is simply reset.

Of course it figures that all my dev boards are mega’s so I have to flash a new bootloader.

EDIT: Just wanted to point out: DO NOT try on a mega board unless you flash with a compatible rom, it will go into endless rebooting.

Thanks for sharing. I will have a look at the watchdog set up.

I too have been chasing a problem which causes my arduino/xojo to intermittently fail. I am running my xojo app as a windows service. But eventually it always fails even if the power never goes off and the machine never goes to sleep. It seems like its a problem with the serial connection failing. But it may also be my service setup. So not I’m not sure.

Eureka!

I must be sending a DTR incorrectly from my app. (Dropping DTR low for one cycle should make the Arduino reboot)

I just downloaded CompuPhase Termite and it had a button to hold DTR high/low.

Clicked that for about 1 second and the Arduino setup routine is fired.

I have a welcome/version message printing in the Setup() routine on the Arduino, and it gets printed each time I hold DTR high for about a second.

It should in theory be able to reset the Arduino even if it’s gone dead as holding DTR high just shorts a wire, basically like pressing the reset button on the board.

Have you figured how to do this in your Xojo app? I checked the language reference and all I see for DTR is a property, and no method emulate what you’re doing in the CompuPhase Termite application.

Yeah that’s the one that bit me originally, because I’ve read that you needed to set DTR to reset in the Arduino datasheet, but when I tried it did nothing, so I went and searched for another solution.

There’s another property called .DataTerminalReady instead of .DTR

.DTR just enables DataTerminalReady flow control, so you need to set .DataTerminalReady = True after setting .DTR true.

So doing this in the action event of a checkbox for example:

Serial1.DataTerminalReady = chkDTR.Value
Serial1.Reset

Makes the Arduino reset, stick something like Serial.println(“RESET”) in the Arduino Setup() and you should see that message everytime you check/uncheck the checkbox in the example.

I just tried this morning when the Arduino had become unresponsive again, and it works even when it’s gone dead. Changing the state of DataTerminalReady acts like hitting the reset button.

Kenneth, thank you for sharing this. I will be testing this out on one of my arduino projects that has been giving me headaches.

I’ve been having this exact same problem. I’ve tried doing this right before sending data, but without success:

Serial1.DTR=True Serial1.DataTerminalReady=True Serial1.Reset
What am I doing wrong? Do I need to hold a state for a given length of time? Do I need to rebuild the serial port after the Serial1.Reset?