Arduino board disconnects after sketch upload (Adafruit QT Py M0)

I am working with the QT Py M0 SAMD21 board and having some trouble uploading a sketch. The sketch will finish uploading, but when the board resets after uploading, it does not power back on--it just disconnects entirely. Single clicking the reset button does nothing, and double clicking powers it back on but on another port of course.

Even if I don't upload a sketch, resetting the board seems to just power it off. So it appears the reset is the problem and not the sketch.

Any advice or things I can try is very much appreciated.

Look for something concerning a capacitor on the reset pin and ??? I forgot the purpose, other than doing something with the rest.

I'm not familiar with your board. Can you post a link?

That would be the "bootloader" port. The L-LED (if your board has that) should fade in / fade out for a few seconds if the behaviour is anything like e.g. a Leonardo.

If that board has a power LED, does it switch off?

A single tap reset will reset the board but it will basically immediately jump to the loaded sketch.

==
I suggest that you (try to) upload blink and see if it works. Further disconnect everything from the board (except the PC for upload).

This is the board: Overview | Adafruit QT Py SAMD21 | Adafruit Learning System
It's pretty small and practical, and I'm using it because I need a bit of flash memory to run my sketch. I have two of these boards, and I get the same problem on both of them.

The board has leds but does not have a power led (or any leds that can be controlled by the user), but it does not appear on the com port until I enter the bootloader, so I assume it is off. When it is in bootloader mode, a green led turns on.

I uploaded a blink and it runs. The single tap reset works as expected, disconnecting the board and immediately jumping to the sketch after reconnecting. So I suppose there is something about the sketch itself that is causing this problem.

To re-summarize the problem, the board disconnects from the computer (I hear the disconnect usb sound effect) as expected, but does not reconnect and run the sketch. Sometimes I get an error message after disconnect saying that the board cannot be found or com port not available. After this happens, the only way to power the board back on and upload a sketch is to enter the bootloader--single tapping the reset does nothing.

There is a lot of code in this program, so I will only post the Arduino sketch for now. It is intended to help calibrate a LiDAR sensor.

#include <OPT3101device.h>
#include <stdio.h>
#include <Wire.h>

#define VERBOSE_MODE

OPT3101::device dev; //default address 0x5F

void setup() {
  Serial.begin(9600);
  Serial.println("Starting setup");
  #define INLAB_STEP_0 //check raw crosstalk using the live view with no calibration loaded.
  //#define OPTIONAL_INLAB_STEP_1A //optional! compensates the xtalk on tx2. only needed for 3ch boards with high xtalk on tx2
  //#define INLAB_STEP_1 //simple bringup
  //#define INLAB_STEP_2
  //#define INLAB_STEP_3
  //#define INLAB_STEP_4
  //#define INPRODCTION
  //#define TESTING_LIVE_VIEW //load existing calibrations and run live view. Useful during inlab steps to verify calibrations are working properly.

#ifdef VERBOSE_MODE
  host.printf("-------------------------------\r\n");
  host.printf("Starting Main Program Execution\r\n");
  host.printf("-------------------------------\r\n");
#endif

  host.initialize();
  host.pause();

  if (!dev.validateI2C()) {
    host.pause();
    Serial.println("validateI2C error");
    return;
  }
  if (!dev.validateDesignID()) {
    host.pause();
  }

#ifdef INLAB_STEP_0
  dev.resetInitAndViewData(3000, false);
#endif
#ifdef INLAB_STEP_1
  dev.calibrationSession_firstTimeBringUp();
  dev.resetInitAndViewData(3000, true);
#endif
#ifdef OPTIONAL_INLAB_STEP_1A //optional! compensates the xtalk on tx2. only needed for 3ch boards with high xtalk on tx2
  dev.calibrationSession_perDesignTx2IllumXtalkCorrection();
#endif
#ifdef INLAB_STEP_2
  dev.calibrationSession_perDesignCalibrationCrosstalkTemp();
#endif
#ifdef INLAB_STEP_3
  dev.calibrationSession_perDesignCalibrationPhaseTemp();
#endif
#ifdef INLAB_STEP_4
  dev.calibrationSession_perDesignCalibrationPhaseAmbient();
#endif
#ifdef INPRODCTION
  dev.calibrationSession_perUnitFactoryCalibration();
#endif
#ifdef TESTING_LIVE_VIEW
  dev.resetInitAndViewData(3000, true);
#endif

  host.printf("-------------------------------\r\n");
  host.pause();
}


void loop() {

}

Are you saying I should put a capacitor between rst and gnd? There is no reset pin on this board, just a button. Even if there was though, what size capacitor would be right for this?

I was meaning to pass keywords to look up (concerning your issue).

Time to start debugging :wink: I could not find the OPT3101device library and I have no idea what host is.

One thing that I notice is that, if VERBOSE_MODE is defined, you first print and later initialise the host; looks a bit strange to me.

Any tips on where to start / what to look for when debugging? I'm just at a loss for what kind of bug could be causing the board to not start up at all. I've tried commenting all the arduino code out except for the include statements, and I get the same results. It compiles fine and says it uploads fine, but could there be something wrong with how it uploads that I could look for?

"host" is a class constructed when "dev" is declared as a global variable. "initialize" is intended to initialize the opt3101 device that the arduino board is connected to.

Part of the code that you upload to a board that supports native USB is responsible for the board detection and the reaction on the software reset that the Arduino IDE issues to invoke the boot loader.

Your sketch can make that code inaccessible (e.g. a long running interrupt) or 'damage' the variables that are used for that (e.g. writing outside the boundaries of arrays) and as a result your board is not recognised by the operating system and/or does not react on the software reset (opening and closing the serial port with a baud rate of 1200 baud).

You will have to provide your full sketch so people can advise what possibly can be wrong. And a link to the library.

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