Pi Pico Arduino Serial1 and USB issue

I am using Earl Philhower library for Raspberry Pi Pico. The pi pico is used to communicate with SIM868 GPS/GSM module.
After sketch upload PC doesn't recognise USB port anymore. Neither I can see the any data response.

Here is my sketch

char ponpin = 14;
int period = 1000;
unsigned long time_now = 0;
long previousMillis = 0;
long interval = 1000;


String Tym, Loc, smsMode, gpsPwr, gpsSts, gpsRst, chg, chgen, cen, gpsmode, Loc1, gpswait, cn, tz, simrst;
String SMS_Msg;
float Latitude = 0.0, Longitude = 0.0;
const byte numChars = 100;
char receivedChars[numChars];
int count = 900;
void setup() {
pinMode (ponpin, OUTPUT);
digitalWrite(ponpin, HIGH);
Serial1.setRX(0);                           //*************This is how I configure TX and RX for Serial1
Serial1.setTX(1);                          //**************After uploading this code, USB is not recognized
  Serial1.setFIFOSize(128);
  Serial1.begin(9600);
  Serial.begin(9600);
  simrst = gsmQuery("AT+CFUN=1,1");
  time_now = millis();
  while (millis() < time_now + period) {}
  Serial.println(simrst);
  chgen = gsmQuery("AT+ECHARGE=1");
  time_now = millis();
  while (millis() < time_now + period) {}
  Serial.println(chgen);
  tz = gsmQuery("AT+CLTS=0");
  time_now = millis();
  while (millis() < time_now + period) {}
  Serial.println(tz);
  cn = gsmQuery("AT+CNMI=0,0,0,0,0");
  time_now = millis();
  while (millis() < time_now + period) {}
  Serial.println(cn);
  gpsPwr = gsmQuery("AT+CGNSPWR=1");
  time_now = millis();
  while (millis() < time_now + period) {}
  Serial.println(gpsPwr);
  chg = gsmQuery("AT+CBC");
  //Serial.println(chg);
  gpsRst = gsmQuery("AT+CGNSSEQ=RMC");
  time_now = millis();
  while (millis() < time_now + period) {}
  Serial.println(gpsRst);
  pinMode(LED_BUILTIN, OUTPUT);
  //gpswait = gsmQuery("WAIT=15");
  Serial.println(gpswait);
}

void loop() {
 ..................
}

String gsmQuery(String query) {
  String f;
  f = "";
  Serial1.print(query);
  Serial1.print("\r\n");
  while (Serial1.available() == 0)  {}
  f = Serial1.readString();
  while (Serial1.available() > 0)  {}
  query = "";
  return f;
}



String getValue(String data, char separator, int index)
{
  int found = 0;
  int strIndex[] = {0, -1};
  int maxIndex = data.length() - 1;

  for (int i = 0; i <= maxIndex && found <= index; i++) {
    if (data.charAt(i) == separator || i == maxIndex) {
      found++;
      strIndex[0] = strIndex[1] + 1;
      strIndex[1] = (i == maxIndex) ? i + 1 : i;
    }
  }

  return found > index ? data.substring(strIndex[0], strIndex[1]) : "";
}

String GetStringBetweenStrings(String input, String firstdel, String enddel) {
  int posfrom = input.indexOf(firstdel) + firstdel.length();
  int posto   = input.indexOf(enddel);
  return input.substring(posfrom, posto);
}

Please edit the post and add code tags. Your indentation is awful, too. It would be helpful to auto format it using ctrl-T in the IDE, before re-uploading it with the required code tags.

done...pls check

Thank you, much better. You have two choices:

  • wait for a Pi Pico expert to see this before it drops off the radar
  • post information links that would help a general expert address the problem

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