USB connects and disconnects after 30sec

Adafruit cellular platform - SMS and IoT over celluar

Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.
Locked
User avatar
Vmarinus
 
Posts: 11
Joined: Tue Dec 18, 2018 4:59 am

USB connects and disconnects after 30sec

Post by Vmarinus »

Hello,

I am building a setup with an Adafruit Fona feather and a Ultimate GPS feather wing.

After three days of happy (and sometimes unhappy) programming, uploading, testing and starting over again. It seems to be game-over.

As long as I was only using the Fona no problems occurred. Once I attached the GPS wing and started using it some bizarre things happened.
At some point I wasn't able anymore to do a new upload. As if the connection between PC and board was used by a process. And as if there was a mix up of serial ports on the board.
Once going back to basics and cleaning up the code. The problem seemed to be solved.

And then, at once after adding some more GPS code. I wasn't able anymore to upload the code. I should tell I was already using 82% of memory.
When connecting the Arduino to the pc you hear the familiar USB discovery sound, the IDE recognizes the board and port (com8) and after 30 sec it disappears with the disconnected sound. Of course at that moment uploading isn't possible anymore. During the 30 sec serial monitor doesn't give a sign of life.

I tried it on different USB ports of my pc. I tried on another PC. I tried another cable...
Then I reflashed the bootloader (Verbose uploading and doubleclicking the reset button). This worked.
But I keep getting the same problem. my board is not recognized and gives the windows error that a usb device with a problem is connected.

What else can i try? Or should I look out for a new board?

User avatar
Vmarinus
 
Posts: 11
Joined: Tue Dec 18, 2018 4:59 am

Re: USB connects and disconnects after 30sec

Post by Vmarinus »

Just to be sure I'll include the code:

Code: Select all

#include "Adafruit_FONA.h"
#include <Adafruit_GPS.h>
#include <SoftwareSerial.h>

char replybuffer[255];                    // this is a large buffer for replies
char fonaNotificationBuffer[64];          //for notifications from the FONA
char smsBuffer[250];

//Fona setup
#define FONA_RST 4
#define FONA_RX 9
#define FONA_TX 8

SoftwareSerial fonaSS = SoftwareSerial(FONA_TX, FONA_RX);
SoftwareSerial *fonaSerial = &fonaSS;
Adafruit_FONA fona = Adafruit_FONA(FONA_RST); // Use this for FONA 800 and 808s

// GPS setup
#define GPSSerial Serial1
Adafruit_GPS GPS(&GPSSerial);

// Set GPSECHO to 'false' to turn off echoing the GPS data to the Serial console
// Set to 'true' if you want to debug and listen to the raw GPS sentences
#define GPSECHO false

uint8_t readline(char *buff, uint8_t maxbuff, uint16_t timeout = 0); //No idea what this lines is for

uint32_t timer = millis();

void setup() {
  while (!Serial); 
  
  Serial.begin(115200);
  Serial.println(F("FONA an GPS test"));
  Serial.println(F("Initializing....(May take 3 seconds)"));

  // make it slow so its easy to read!
  fonaSerial->begin(4800);
  if (! fona.begin(*fonaSerial)) {
    Serial.println(F("Couldn't find FONA"));
    while(1);
  }
  Serial.println(F("FONA is OK"));

  fonaSerial->print("AT+CNMI=2,1\r\n");  //set up the FONA to send a +CMTI notification when an SMS is received

  Serial.println("FONA Ready");

  GPS.begin(9600);
  //Request updates on antenna status, comment out to keep quiet
  GPS.sendCommand(PGCMD_ANTENNA);
  GPS.sendCommand(PMTK_SET_NMEA_OUTPUT_RMCGGA);
  GPS.sendCommand(PMTK_SET_NMEA_UPDATE_1HZ);   // 1 Hz update rate

  
}

void loop() {
  
  char* bufPtr = fonaNotificationBuffer;  //handy buffer pointer

  if (fona.available())  //any data available from the FONA?
  {
    int slot = 0;  //this will be the slot number of the SMS
    int charCount = 0;
    //Read the notification into fonaInBuffer
    do {
      *bufPtr = fona.read();
      Serial.write(*bufPtr);
      delay(1);
    } while ((*bufPtr++ != '\n') && (fona.available()) && (++charCount < (sizeof(fonaNotificationBuffer) - 1)));

    //Add a terminal NULL to the notification string
    *bufPtr = 0;

    //Scan the notification string for an SMS received notification.
    //  If it's an SMS message, we'll get the slot number in 'slot'
    if (1 == sscanf(fonaNotificationBuffer, "+CMTI: " FONA_PREF_SMS_STORAGE ",%d", &slot)) {
      Serial.print("slot: ");
      Serial.println(slot);

      char callerIDbuffer[32];  //we'll store the SMS sender number in here

      // Retrieve SMS sender address/phone number.
      if (!fona.getSMSSender(slot, callerIDbuffer, 31)) {
        Serial.println("Didn't find SMS message in slot!");
      }
      Serial.print(F("FROM: "));
      Serial.println(callerIDbuffer);

      // Retrieve SMS value.
      uint16_t smslen;
      fona.readSMS(slot, smsBuffer, 250, &smslen);

      //Send back an automatic response
      Serial.println("Sending reponse...");
      if (!fona.sendSMS(callerIDbuffer, (char*)"Hey, I got your text!")) {
        Serial.println(F("Failed"));
      } else {
        Serial.println(F("Sent!"));
      }

      // delete the original msg after it is processed
      //   otherwise, we will fill up all the slots
      //   and then we won't be able to receive SMS anymore
      if (fona.deleteSMS(slot)) {
        Serial.println(F("OK!"));
      } else {
        Serial.print(F("Couldn't delete SMS in slot "));
        Serial.println(slot);
        fona.print(F("AT+CMGD=?\r\n"));
      }


    }     
  }

  char c = GPS.read();
  // if you want to debug, this is a good time to do it!
  if ((c) && (GPSECHO))
    Serial.write(c);

  // if a sentence is received, we can check the checksum, parse it...
  if (GPS.newNMEAreceived()) {
    // a tricky thing here is if we print the NMEA sentence, or data
    // we end up not listening and catching other sentences!
    // so be very wary if using OUTPUT_ALLDATA and trytng to print out data
    //Serial.println(GPS.lastNMEA());   // this also sets the newNMEAreceived() flag to false

    if (!GPS.parse(GPS.lastNMEA()))   // this also sets the newNMEAreceived() flag to false
      return;  // we can fail to parse a sentence in which case we should just wait for another
  }

  if (millis() - timer > 20000) {
   timer = millis();
   if (GPS.fix) {
    Serial.print("Location: ");
    Serial.println("Location in Degrees");
    Serial.print(GPS.latitudeDegrees, 8);
    Serial.print(", ");
    Serial.println(GPS.longitudeDegrees, 8);

    Serial.print("Speed (knots): "); Serial.println(GPS.speed);
    Serial.print("Angle: "); Serial.println(GPS.angle);
    }
  }
}

Locked
Please be positive and constructive with your questions and comments.

Return to “FONA”