Web Editor USB link drops out

Hello I have been struggling with this problem for a couple of days.

Having eventually got the MKR 1010 set up (Web Editor set up failed several times) I have successfully compiled a simple Sketch which appears to upload OK, but a few seconds later the USB link drops out. I can't seem to reconnect USB until the device is reset.

The Sketch uses a DS3231 RTC (AdaFruit library) which reports a time at minute intervals to the Dashboard (its the start of a wider project just to check the principle.)

I'm using Mac OS 14.5 and Safari.

Any help would be appreciated.

Thank you

Hi @squashplayer

Please post this simple sketch.

I'll provide instructions you can follow to do that:

  1. Do an Auto Format on your code by pressing Ctrl+B.
    This is done to make the code easier for us to read.
  2. Click on the window that contains your sketch code.
  3. Press the Ctrl+A keyboard shortcut.
    This will select all the text.
  4. Press the Ctrl+C keyboard shortcut.
    This will copy the selected text to the clipboard.
  5. Open a forum reply here by clicking the "Reply" button.
  6. Click the <CODE/> icon on the post composer toolbar.
    This will add the forum's code block markup (```) to your reply to make sure the error messages are correctly formatted.
    Code block icon on toolbar
  7. Press the Ctrl+V keyboard shortcut.
    This will paste the copied code into the code block.
  8. Move the cursor outside of the code block markup before you add any additional text to your reply.
  9. Repeat the above process if your sketch has multiple tabs.
  10. Click the "Reply" button to post the output.

When your code requires a library that's not pre-installed in "Arduino Cloud Editor", please post a link to where you downloaded that library from.

#include <RTClib.h>


/* 
  Sketch generated by the Arduino IoT Cloud Thing "Clock_It"
  https://create.arduino.cc/cloud/things/6567a801-aa2b-401f-8ce1-ba66d17e64a5 

  Arduino IoT Cloud Variables description

  The following variables are automatically generated and updated when changes are made to the Thing

  int ss;

  Variables which are marked as READ/WRITE in the Cloud Thing will also have functions
  which are called when their values are changed from the Dashboard.
  These functions are generated with the Thing and added at the end of this sketch.
*/

#include "thingProperties.h"

// Date and time functions using a DS3231 RTC connected via I2C and Wire lib



RTC_DS3231 myrtc;

char daysOfTheWeek[7][12] = {"Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"};

void setup() {
  // Initialize serial and wait for port to open:
  Serial.begin(9600);
  // This delay gives the chance to wait for a Serial Monitor without blocking if none is found
  delay(1500); 

  // Defined in thingProperties.h
  initProperties();

  // Connect to Arduino IoT Cloud
  
  ArduinoCloud.begin(ArduinoIoTPreferredConnection);
  
  /*
     The following function allows you to obtain more information
     related to the state of network and IoT Cloud connection and errors
     the higher number the more granular information you’ll get.
     The default is 0 (only errors).
     Maximum is 4
 */
  setDebugMessageLevel(2);
  ArduinoCloud.printDebugInfo();
}

void loop() {
  ArduinoCloud.update();
  // Your code here 
   DateTime now = myrtc.now();

    Serial.print(now.year(), DEC);
    Serial.print('/');
    Serial.print(now.month(), DEC);
    Serial.print('/');
    Serial.print(now.day(), DEC);
    Serial.print(" (");
    Serial.print(daysOfTheWeek[now.dayOfTheWeek()]);
    Serial.print(") ");
    Serial.print(now.hour(), DEC);
    Serial.print(':');
    Serial.print(now.minute(), DEC);
    Serial.print(':');
    Serial.print(now.second(), DEC);
    Serial.println();

  

    // calculate a date which is 0 days, 1 hours, minutes,  seconds into the future
    DateTime future (now + TimeSpan(0,1,0,0));

    Serial.print(" now + 1: ");
    Serial.print(future.year(), DEC);
    Serial.print('/');
    Serial.print(future.month(), DEC);
    Serial.print('/');
    Serial.print(future.day(), DEC);
    Serial.print(' ');
    Serial.print(future.hour(), DEC);
    Serial.print(':');
    Serial.print(future.minute(), DEC);
    Serial.print(':');
    Serial.print(future.second(), DEC);
    Serial.println();

    Serial.print("Temperature: ");
    Serial.print(myrtc.getTemperature());
    Serial.println(" C");

    Serial.println();
    delay(5000);

  ss=now.second(),DEC;
}

/*
  Since Ss is READ_WRITE variable, onSsChange() is
  executed every time a new value is received from IoT Cloud.
*/
void onSsChange()  {
  // Add your code here to act upon Ss change
}


















Hi @squashplayer. You forgot to call myrtc.begin(). This is essential to initialize the "RTClib" library. I think this is probably the cause of your problem2. .

You can learn how to correctly use the "RTClib" library by studying the library examples. I'll provide instructions you can follow to access the examples:

  1. Select "Libraries" from the menu on the left side of the Arduino Cloud Editor window.
  2. Type RTCLib in the "SEARCH LIBRARIES" field.
  3. Find the entry for the "RTCLib" library in the search results.
  4. Click the "❯ Examples" at the bottom of the entry.
    A list of the library's example sketches will open.
  5. Click on the "ds3231" example.
    The "ds3231" example will open in a new Cloud Editor browser tab.

Hi, Thats absolutely brilliant, thank you, not sure how I missed that out :frowning:

You are welcome. I'm glad if I was able to be of assistance.

Regards,
Per