Reset Arduino from IDE?

I'm using an Arduino 33 BLE. Since adding a watchdog timer to my code the Arduino needs to be rest by pressing the reset button twice to allow it it upload software. Since I have this board in an enclosure It would be a huge convenience to be able to reset the Arduino through the IDE instead of removing the enclosure cover. Is there a way to do this?

Can't think of one. Might be easier, faster, simpler to just extend a pair of wires and put a button on the end.
C

Trying to avoid that. But if need be, I can just put a hole in the case.

Does opening the serial monitor in the IDE reset the sketch. It seems to do so with my Nano.

Opening Serial Monitor only resets the boards that have a dedicated USB to serial adapter chip (e.g., classic Nano, Uno, Mega). It does not do so for the boards with native USB such as the Nano 33 BLE used by @mb107.

To make matters more complicated, @mb107 is looking for a way to put the board into bootloader mode, which requires a double reset rather than only a simple reset on these boards.

1 Like

Fortunately, the Arduino community comes through as usual. A similar question was asked about the Nano RP2040 Connect (which uses the same Mbed OS-based core as the Nano 33 BLE) a couple of weeks ago, and the forum member was kind enough to share their findings for the benefit of all:

So just call that function in your sketch to put the board into bootloader mode.

A minimal demo:

void setup() {
  _ontouch1200bps_();
}
void loop() {}
1 Like

Getting to the boatloader mode in code is discussed here
https://github.com/arduino/ArduinoCore-nRF528x-mbedos/issues/64

1 Like

I'm not quite sure what the WDT has to do with the issue, not familiar with your board. You can try the below.

Boards with native USB can be reset by opening and closing the serial port with a baudrate of 1200; it's what happens when you upload a sketch to those boards.

From within the IDE, open serial monitor and change the baudrate to 1200. Next change it back to the desired baudrate.

A change in baudrate will close and open the serial port again.

Will give it a try Thank You

I'm not sure myself. @Klaus_K was able to guide me through getting the watch dog to work and advised me of the double reset button trick. I certainly understand why I need to do it when the watch dog gets triggered but still kind of baffled why I need to do it when the program terminates normally. It would be a nice feature if the IDE had a switch to reset it. Doing it programmatically with code is a big help but I don't think its as good as a switch in the IDE.

Assuming it was a forum post, can you post a link?

I've moved your topic to the dedicated Nano 33 BLE section as it's not quite an Installation and Troubleshooting question :wink:

Link here.

https://forum.arduino.cc/t/is-there-a-watchdog-time-library-available-for-the-nano-33-ble/975900

I was actually trying to find an IDE area as I didn't think it was specific issue for the Nano 33 BLE. But that will work.

Hi @mb107

I don't own a Nano 33 BLE, but on the SAMD21 based MKR and Nano 33 IoT boards it's possible to "trick" them to reset into bootloader mode, by copying the double tap "magic number" into double tap data location stored in the last 4-bytes (word) of RAM, before a performing software reset.

Here's a SAMD21 based code example that blinks the built in LED five times before entering bootloader mode:

// Code to programmatically initiate bootloader mode after reset
#define BOOT_DOUBLE_TAP_ADDRESS           (0x20007FFCul)
#define BOOT_DOUBLE_TAP_DATA              (*((volatile uint32_t *) BOOT_DOUBLE_TAP_ADDRESS))
#define DOUBLE_TAP_MAGIC 0x07738135

void setup() 
{
  pinMode(LED_BUILTIN, OUTPUT);               // Initialise the LED as an OUTPUT
}

void loop() 
{
  for (uint8_t i = 0; i < 5; i++)             // Blink the built-in LED for 5 seconsds before reset
  {
    digitalWrite(LED_BUILTIN, HIGH);          // Turn LED on
    delay(500);                               // Wait half a second
    digitalWrite(LED_BUILTIN, LOW);           // turn the LED off by making the voltage LOW 
    delay(500);                               // Wait for a second
  }
  BOOT_DOUBLE_TAP_DATA = DOUBLE_TAP_MAGIC;    // Start in bootloader mode after reset
  NVIC_SystemReset();                         // Reset the microcontroller
}

It should be possible to obtain these double tap values for your Nano 33 BLE board from the bootloader definitions files. On the SAMD21 these bootloader files are "board_definitions_arduino_zero.h" and "main.c". On my machine they're located at:

C:\Users\Computer\AppData\Local\Arduino15\packages\arduino\hardware\samd\1.8.13\bootloaders\zero

...obviously your will differ slightly from "samd" downwards.

Here are the double tap definitions in the "boards_definitions_arduino_zero.h" file:

#define BOOT_DOUBLE_TAP_ADDRESS           (0x20007FFCul)
#define BOOT_DOUBLE_TAP_DATA              (*((volatile uint32_t *) BOOT_DOUBLE_TAP_ADDRESS))

and in the "main.c" file:

#define DOUBLE_TAP_MAGIC 0x07738135

Since the BLE also uses an ARM microcontroller, the software reset command is the same:

NVIC_SystemReset();                         // Reset the microcontroller
1 Like

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.