Serial.print not working on Zero

Hi All,

I have sketch that's about 3000 lines plus libraries, running perfectly on AVR. With a few changes it compiles on the Zero (Arduino.cc version, not Pro) and MKR1000, but I can't get Serial.print to work and because of that, I can't tell if the sketch is even running. After the compile, the serial port on the MKR1000 are disabled until it is reset with a double button press. This does not happen on the Zero.

Same result on two Windows 10 PCs, and a MAC.

Below are the compiler messages. Help and suggestions are greatly appreciated. I've spent a couple days on this.

Open On-Chip Debugger 0.9.0-gd4b7679 (2015-06-10-22:24)
Licensed under GNU GPL v2
For bug reports, read
	http://openocd.org/doc/doxygen/bugs.html
debug_level: 0
adapter speed: 500 kHz
adapter_nsrst_delay: 100
cortex_m reset_config sysresetreq
target state: halted
target halted due to debug-request, current mode: Thread 
xPSR: 0x01000000 pc: 0x000005e8 msp: 0x20007ffc
** Programming Started **
auto erase enabled
wrote 40960 bytes from file C:\Users\mitch\AppData\Local\Temp\builde63aae430abc29b2b1e451824e5114ae.tmp/test.ino.bin in 6.033966s (6.629 KiB/s)
** Programming Finished **
** Verify Started **
verified 38400 bytes in 3.127339s (11.991 KiB/s)
** Verified OK **
** Resetting Target **
shutdown command invoked

It is 3000 lines long. Do you have any suggestions as to what to look for?

It is 3000 lines long. Do you have any suggestions as to what to look for?

The typical Hello World program is, if you abuse things to the extreme, two lines.

void setup() { Serial.begin(115200); }
void loop() { Serial.println("Hello World"); }

I'm removing chunks of code to try to figure this out. When I have a working small sketch that's manageable and demonstrates the issue, I'll post it. Below are some libraries that have been removed so far, and a few lines of test code in Setup() that don't work.

//#include <Arduino.h>
#include <TimeLib.h>
//#include <NTPClient.h>
//#include <WiFi101.h>
//#include <WiFiUdp.h>
#include <DS1307RTC.h>
#include <TinyGPS++.h>
#include <Timezone1.h>
//#include <I2C_eeprom.h>
#include <Curve.h>
#include <LEDfader.h>
#include <SimpleTimer.h>
//#include <TimerThree.h>
#include <Bounce2mcp.h>
#include <Adafruit_MCP23017.h>
//#include <Wire.h>
//#include <SPI.h>
//#include <Adafruit_Sensor.h>
//#include <Adafruit_BME280.h>
//#include <morse.h>

const byte fRev = 11; // firmware revision

#define serialGPS Serial1
TinyGPSPlus gps;

struct tmt { // used for digit change effects
  byte hour10;
  byte hour1;
  byte minute10;
  byte minute1;
  byte second10;
  byte second1;
  byte tenth;
  byte hundredth;
};
tmt currTime;
tmt oldTime;
struct tmt *switchTime;

// initialize and instantiate tz object
TimeChangeRule dSt; // = {};
TimeChangeRule sTd; // = {};
Timezone1 tz(dSt, sTd);
void setup()
{

Serial.begin(9600);
delay(2000);
Serial.println("here");

Now the sketch is down to this:

//#include <Arduino.h>
//#include <TimeLib.h>
//#include <NTPClient.h>
//#include <WiFi101.h>
//#include <WiFiUdp.h>
//#include <DS1307RTC.h>
//#include <TinyGPS++.h>
//#include <Timezone1.h>
//#include <I2C_eeprom.h>
//#include <Curve.h>
//#include <LEDfader.h>
//#include <SimpleTimer.h>
//#include <TimerThree.h>
//#include <Bounce.h>
//#include <Adafruit_MCP23017.h>
//#include <Wire.h>
//#include <SPI.h>
//#include <Adafruit_Sensor.h>
//#include <Adafruit_BME280.h>
//#include <morse.h>



/*----------------------------------------------------------------------*
   Initialize
  ----------------------------------------------------------------------*/
void setup()
{

Serial.begin(9600);
delay(2000);
Serial.println("here");

}

/*----------------------------------------------------------------------*
   Main Loop
  ----------------------------------------------------------------------*/
void loop()
{

}

Obviously something else is going on here, not related to the sketch. This works perfectly on a Mega 2560.

I tried flashing the bootloader again, but that didn't help.

Is it possible that NVIC_SystemReset() changed a fuse setting, or had some other effect on the boards?

I have a new MKR1000 arriving shortly. I'll try it without that command. Suggestions are greatly appreciated.

I believe that "Serial" on the MKR1000 refers to its native USB port, while "Serial" on the Zero refers to its programming USB port. On the Zero you need to use "SerialUSB", if you intend on using its native port?

Also, if you're using the native port you need to add the line:

while (!SerialUSB);      // Check if the SerialUSB port is ready

... after the SerialUSB.begin() function. This ensures that the native port is ready before proceeding with the rest sketch.

Thanks for your comments. I was using the programming port on the Zero, and the native USB port on the MKR1000. I will try SerialUSB on the Zero, but this should work on the programming port.

I'm guessing that something was changed on both the Zero and MKR1000, that can't be fixed by flashing the bootloader.

Next I tried this on a Due clone. The sketch worked as expected. I then added NVIC_SystemReset();
after the Serial.println() statement, and only garbage printed every second or so, as the Due was reset.

Strange because reset executes after the print statement. Removing that statement, the sketch again worked as expected.