Lost bootloader and native USB on the pi pico - SOLVED

Hello, My friend let me use his pi Pico 4g LTE kit board. It was working and I was trying to get the LCD to work for him. I looked u-p drivers and libraries and tried different things. When I go to upload the sketch all of the sudden I got a windows USB error said failed. I can normally double tap the button on the Pico and put me into a bootloader state but this time that doesn't even want to work. I'm not sure what to really do. And I don't have another Pico to replace it. I need help please to figure out how to repair this mess? I'm attaching the code below.

#include <Adafruit_GFX.h>
#include <Adafruit_ST7789.h>
#include <SPI.h>

#define ST7789_DRIVER

#define TFT_MOSI 19
#define TFT_SCLK 18
#define TFT_CS   17
#define TFT_DC   21
#define TFT_RST  20

Adafruit_ST7789 tft = Adafruit_ST7789(TFT_CS, TFT_DC, TFT_RST);

void setup() {
  pinMode(TFT_BL, OUTPUT);
  digitalWrite(TFT_BL, HIGH);  // turn ON backlight

  SPI.setSCK(18);
  SPI.setTX(19);
  SPI.setRX(16);
  SPI.begin();

  tft.init(240, 320);
  tft.setRotation(1);

  tft.fillScreen(ST77XX_RED);
  delay(1000);
  tft.fillScreen(ST77XX_GREEN);
  delay(1000);
  tft.fillScreen(ST77XX_BLUE);
}

void loop() {}

Joseph

can you give a link to the specific pi pico board?

with RP2040 boot problems try

  1. disconnect the Pico USB, press BOOTSEL connect the Pico USB
  2. Tools>Port displays UF2 board select it and upload program
  3. after a time UF2 should change to a COM port - select it

if above does not work try unplugging device
COM port appears in Windows device manager
Tools>port select it

very tricky but once COM port is open it programs OK etc

initally try loading and running a simple program such as the blink example

EDIT: it is worth having the Windows Device Manager running with Ports (COM and LPT) expanded so you can see what is happening as you plug/unpluf the RP2040 USB ccable

Maybe the both of you would benefit from reading the 'Arduino Cookbook' for starters.

@horace I have tried all the above before I posted in here. And still all the same. I even tried it on a different computer and got the same error. Here is a link to the device.

@sonofcy Thank you but I do not need a cookbook for arduino. This goes beyond the basic Of getting a board up and running. There is something else wrong I can not tell. I even tried it on a different computer trying to install drivers to be met by the same error as on my computer.

if you remove the PRi Pico from the 4G Expansion board do you still have the same problem?
if you run the Windows device Manage what happens when you plug/unplug the RPi Pico? you should see a COM port or UF2 port appear/disappear

also try the 4G Expansion board without the RPi Pico - see Pico-4g-expansion - SB-Components Wiki

@horace Funny thing is if I leave it on the Expansion board I get no USB at all. If i remove it from the Expansion board I get USB and that error.

Edit: I have looked over that Wiki page and did not help me.

does the 4G expansion board work without the Pico?

unless you can get help from the supplier sounds like it is time to return it

I would look at ESP32 based 4G modules - far simpler to use than RPi pico

@horace the 4G module will work on its own without the Pico with its own USB from what I read. I have not tried that yet. which will also leave me the LCD not being used.

I can save a little headache by just buying a new Pico, But it takes 3 to 4 days to get here. For now I will try the modem module itself and see if I can get that up and running.

@horace I just thought there might be a way to repair this in programming but it looks like that might be a bigger problem.

My apologies, I did not check your history and it sounded like a noob problem. I will leave you in the good hands of @horace

@sonofcy Honestly I wish it was a noob problem. It all good. I don't know what really happen and I'm trying to figure it out.

Take all the connections off the PICO, and try to upload and run the Blink sketch. If that does NOT work the PICO is either damaged beyond repair or it needs a new bootloader. Since I have never (yet) had to replace a bootloader I have no clue how to, but I think it is in the IDE.

I have a few RPi Pico including WiFi version and the adafruit-rp2040-can-bus-feather

never had to reload a bootloader so no idea how to do it

however, tend to use ESP32 based systems for serious work including building custom PCBs

@horace and @sonofcy In all my i guess you call it pre-pairing in the past I totally forgot I bought extra PI Pico's. 5 of them from an old project. I did get one all solider up for the pins and gotten it programmed. I got the AT commands back now. I did change the USB cable just incase. I still have the external 3a power adapter for the extra power on the modem. I have to figure out how to get the LCD screen working.

Good news it i have 4 more chances to get it right if this Pico goes out there are 4 more left. lol

Joseph

assuming the ST7789 pins are correct your pinout should work OK

with a RP2040 and ST7789 I used the following test program

// RP2040  Waveshare General 2inch LCD Display Module IPS Screen 240×320 ST7789
// File>Examples>Adafruit_ST7735_and_ST7789_Library>graphicstest
//  works OK

/**************************************************************************
  This is a library for several Adafruit displays based on ST77* drivers.

  This example works with the 1.14" TFT breakout
    ----> https://www.adafruit.com/product/4383
  The 1.3" TFT breakout
    ----> https://www.adafruit.com/product/4313
  The 1.47" TFT breakout
    ----> https://www.adafruit.com/product/5393
  The 1.54" TFT breakout
    ----> https://www.adafruit.com/product/3787
  The 1.69" TFT breakout
    ----> https://www.adafruit.com/product/5206
  The 1.9" TFT breakout
    ----> https://www.adafruit.com/product/5394
  The 2.0" TFT breakout
    ----> https://www.adafruit.com/product/4311


  Check out the links above for our tutorials and wiring diagrams.
  These displays use SPI to communicate, 4 or 5 pins are required to
  interface (RST is optional).

  Adafruit invests time and resources providing this open source code,
  please support Adafruit and open-source hardware by purchasing
  products from Adafruit!

  Written by Limor Fried/Ladyada for Adafruit Industries.
  MIT license, all text above must be included in any redistribution
 **************************************************************************/

#include <Adafruit_GFX.h>     // Core graphics library
#include <Adafruit_ST7789.h>  // Hardware-specific library for ST7789
#include <SPI.h>

// RP2040
// MOSI: 19
// MISO: 16
// SCK: 18
// SS: 17
#define TFT_CS 17
#define TFT_RST 15  // Or set to -1 and connect to Arduino RESET pin
#define TFT_DC 14


// OPTION 1 (recommended) is to use the HARDWARE SPI pins, which are unique
// to each board and not reassignable. For Arduino Uno: MOSI = pin 11 and
// SCLK = pin 13. This is the fastest mode of operation and is required if
// using the breakout board's microSD card.

Adafruit_ST7789 tft = Adafruit_ST7789(TFT_CS, TFT_DC, TFT_RST);

// OPTION 2 lets you interface the display using ANY TWO or THREE PINS,
// tradeoff being that performance is not as fast as hardware SPI above.
//#define TFT_MOSI 11  // Data out
//#define TFT_SCLK 13  // Clock out

//Adafruit_ST7789 tft = Adafruit_ST7789(TFT_CS, TFT_DC, TFT_MOSI, TFT_SCLK, TFT_RST);


float p = 3.1415926;

void setup(void) {
  Serial.begin(115200);
 delay(1000);
  Serial.print(F("Hello! ST77xx TFT Test"));
  // Use this initializer (uncomment) if using a 1.3" or 1.54" 240x240 TFT:
  //tft.init(240, 240);  // Init ST7789 240x240

  // OR use this initializer (uncomment) if using a 1.69" 280x240 TFT:
  //tft.init(240, 280);           // Init ST7789 280x240

  // OR use this initializer (uncomment) if using a 2.0" 320x240 TFT:
  tft.init(240, 320);           // Init ST7789 320x240

  // OR use this initializer (uncomment) if using a 1.14" 240x135 TFT:
  //tft.init(135, 240);           // Init ST7789 240x135

  // OR use this initializer (uncomment) if using a 1.47" 172x320 TFT:
  //tft.init(172, 320);           // Init ST7789 172x320

  // OR use this initializer (uncomment) if using a 1.9" 170x320 TFT:
  //tft.init(170, 320);           // Init ST7789 170x320
  // SPI speed defaults to SPI_DEFAULT_FREQ defined in the library, you can override it here
  // Note that speed allowable depends on chip and quality of wiring, if you go too fast, you
  // may end up with a black screen some times, or all the time.
  //tft.setSPISpeed(8000000);
  Serial.println(F("Initialized"));
  uint16_t time = millis();
  tft.fillScreen(ST77XX_BLACK);
  time = millis() - time;

  Serial.println(time, DEC);
  delay(500);

  // large block of text
  tft.fillScreen(ST77XX_BLACK);
  testdrawtext("Lorem ipsum dolor sit amet, consectetur adipiscing elit. Curabitur adipiscing ante sed nibh tincidunt feugiat. Maecenas enim massa, fringilla sed malesuada et, malesuada sit amet turpis. Sed porttitor neque ut ante pretium vitae malesuada nunc bibendum. Nullam aliquet ultrices massa eu hendrerit. Ut sed nisi lorem. In vestibulum purus a tortor imperdiet posuere. ", ST77XX_WHITE);
  delay(1000);

  // tft print function!
  tftPrintTest();
  delay(4000);

  // a single pixel
  tft.drawPixel(tft.width() / 2, tft.height() / 2, ST77XX_GREEN);
  delay(500);

  // line draw test
  testlines(ST77XX_YELLOW);
  delay(500);

  // optimized lines
  testfastlines(ST77XX_RED, ST77XX_BLUE);
  delay(500);

  testdrawrects(ST77XX_GREEN);
  delay(500);

  testfillrects(ST77XX_YELLOW, ST77XX_MAGENTA);
  delay(500);

  tft.fillScreen(ST77XX_BLACK);
  testfillcircles(10, ST77XX_BLUE);
  testdrawcircles(10, ST77XX_WHITE);
  delay(500);

  testroundrects();
  delay(500);

  testtriangles();
  delay(500);
while(1);
  mediabuttons();
  delay(500);

  Serial.println("done");
  delay(1000);
}

void loop() {
  tft.invertDisplay(true);
  delay(500);
  tft.invertDisplay(false);
  delay(500);
}

void testlines(uint16_t color) {
  tft.fillScreen(ST77XX_BLACK);
  for (int16_t x = 0; x < tft.width(); x += 6) {
    tft.drawLine(0, 0, x, tft.height() - 1, color);
    delay(0);
  }
  for (int16_t y = 0; y < tft.height(); y += 6) {
    tft.drawLine(0, 0, tft.width() - 1, y, color);
    delay(0);
  }

  tft.fillScreen(ST77XX_BLACK);
  for (int16_t x = 0; x < tft.width(); x += 6) {
    tft.drawLine(tft.width() - 1, 0, x, tft.height() - 1, color);
    delay(0);
  }
  for (int16_t y = 0; y < tft.height(); y += 6) {
    tft.drawLine(tft.width() - 1, 0, 0, y, color);
    delay(0);
  }

  tft.fillScreen(ST77XX_BLACK);
  for (int16_t x = 0; x < tft.width(); x += 6) {
    tft.drawLine(0, tft.height() - 1, x, 0, color);
    delay(0);
  }
  for (int16_t y = 0; y < tft.height(); y += 6) {
    tft.drawLine(0, tft.height() - 1, tft.width() - 1, y, color);
    delay(0);
  }

  tft.fillScreen(ST77XX_BLACK);
  for (int16_t x = 0; x < tft.width(); x += 6) {
    tft.drawLine(tft.width() - 1, tft.height() - 1, x, 0, color);
    delay(0);
  }
  for (int16_t y = 0; y < tft.height(); y += 6) {
    tft.drawLine(tft.width() - 1, tft.height() - 1, 0, y, color);
    delay(0);
  }
}

void testdrawtext(char *text, uint16_t color) {
  tft.setCursor(0, 0);
  tft.setTextColor(color);
  tft.setTextWrap(true);
  tft.print(text);
}

void testfastlines(uint16_t color1, uint16_t color2) {
  tft.fillScreen(ST77XX_BLACK);
  for (int16_t y = 0; y < tft.height(); y += 5) {
    tft.drawFastHLine(0, y, tft.width(), color1);
  }
  for (int16_t x = 0; x < tft.width(); x += 5) {
    tft.drawFastVLine(x, 0, tft.height(), color2);
  }
}

void testdrawrects(uint16_t color) {
  tft.fillScreen(ST77XX_BLACK);
  for (int16_t x = 0; x < tft.width(); x += 6) {
    tft.drawRect(tft.width() / 2 - x / 2, tft.height() / 2 - x / 2, x, x, color);
  }
}

void testfillrects(uint16_t color1, uint16_t color2) {
  tft.fillScreen(ST77XX_BLACK);
  for (int16_t x = tft.width() - 1; x > 6; x -= 6) {
    tft.fillRect(tft.width() / 2 - x / 2, tft.height() / 2 - x / 2, x, x, color1);
    tft.drawRect(tft.width() / 2 - x / 2, tft.height() / 2 - x / 2, x, x, color2);
  }
}

void testfillcircles(uint8_t radius, uint16_t color) {
  for (int16_t x = radius; x < tft.width(); x += radius * 2) {
    for (int16_t y = radius; y < tft.height(); y += radius * 2) {
      tft.fillCircle(x, y, radius, color);
    }
  }
}

void testdrawcircles(uint8_t radius, uint16_t color) {
  for (int16_t x = 0; x < tft.width() + radius; x += radius * 2) {
    for (int16_t y = 0; y < tft.height() + radius; y += radius * 2) {
      tft.drawCircle(x, y, radius, color);
    }
  }
}

void testtriangles() {
  tft.fillScreen(ST77XX_BLACK);
  uint16_t color = 0xF800;
  int t;
  int w = tft.width() / 2;
  int x = tft.height() - 1;
  int y = 0;
  int z = tft.width();
  for (t = 0; t <= 15; t++) {
    tft.drawTriangle(w, y, y, x, z, x, color);
    x -= 4;
    y += 4;
    z -= 4;
    color += 100;
  }
}

void testroundrects() {
  tft.fillScreen(ST77XX_BLACK);
  uint16_t color = 100;
  int i;
  int t;
  for (t = 0; t <= 4; t += 1) {
    int x = 0;
    int y = 0;
    int w = tft.width() - 2;
    int h = tft.height() - 2;
    for (i = 0; i <= 16; i += 1) {
      tft.drawRoundRect(x, y, w, h, 5, color);
      x += 2;
      y += 3;
      w -= 4;
      h -= 6;
      color += 1100;
    }
    color += 100;
  }
}

void tftPrintTest() {
  tft.setTextWrap(false);
  tft.fillScreen(ST77XX_BLACK);
  tft.setCursor(0, 30);
  tft.setTextColor(ST77XX_RED);
  tft.setTextSize(1);
  tft.println("Hello World!");
  tft.setTextColor(ST77XX_YELLOW);
  tft.setTextSize(2);
  tft.println("Hello World!");
  tft.setTextColor(ST77XX_GREEN);
  tft.setTextSize(3);
  tft.println("Hello World!");
  tft.setTextColor(ST77XX_BLUE);
  tft.setTextSize(4);
  tft.print(1234.567);
  delay(1500);
  tft.setCursor(0, 0);
  tft.fillScreen(ST77XX_BLACK);
  tft.setTextColor(ST77XX_WHITE);
  tft.setTextSize(0);
  tft.println("Hello World!");
  tft.setTextSize(1);
  tft.setTextColor(ST77XX_GREEN);
  tft.print(p, 6);
  tft.println(" Want pi?");
  tft.println(" ");
  tft.print(8675309, HEX);  // print 8,675,309 out in HEX!
  tft.println(" Print HEX!");
  tft.println(" ");
  tft.setTextColor(ST77XX_WHITE);
  tft.println("Sketch has been");
  tft.println("running for: ");
  tft.setTextColor(ST77XX_MAGENTA);
  tft.print(millis() / 1000);
  tft.setTextColor(ST77XX_WHITE);
  tft.print(" seconds.");
}

void mediabuttons() {
  // play
  tft.fillScreen(ST77XX_BLACK);
  tft.fillRoundRect(25, 10, 78, 60, 8, ST77XX_WHITE);
  tft.fillTriangle(42, 20, 42, 60, 90, 40, ST77XX_RED);
  delay(500);
  // pause
  tft.fillRoundRect(25, 90, 78, 60, 8, ST77XX_WHITE);
  tft.fillRoundRect(39, 98, 20, 45, 5, ST77XX_GREEN);
  tft.fillRoundRect(69, 98, 20, 45, 5, ST77XX_GREEN);
  delay(500);
  // play color
  tft.fillTriangle(42, 20, 42, 60, 90, 40, ST77XX_BLUE);
  delay(50);
  // pause color
  tft.fillRoundRect(39, 98, 20, 45, 5, ST77XX_RED);
  tft.fillRoundRect(69, 98, 20, 45, 5, ST77XX_RED);
  // play color
  tft.fillTriangle(42, 20, 42, 60, 90, 40, ST77XX_GREEN);
}

photo

@horace I got this error.

C:\Users\JjC\Documents\Arduino\Sketch\SPI-TEST\SPI-TEST.ino: In function 'void setup()':
C:\Users\JjC\Documents\Arduino\Sketch\SPI-TEST\SPI-TEST.ino:67:16: warning: ISO C++ forbids converting a string constant to 'char*' [-Wwrite-strings]
   67 |   testdrawtext("Lorem ipsum dolor sit amet, consectetur adipiscing elit. Curabitur adipiscing ante sed nibh tincidunt feugiat. Maecenas enim massa, fringilla sed malesuada et, malesuada sit amet turpis

Edit: It did upload but nothing showed up on the screen. My Screen is a 240x135.

Edit2: I comment that area out and no errors now and nothing on the screen.

that is just a warning - ignor it for now

if you ran my code from post 16 did you change my pinout

#define TFT_CS 17
#define TFT_RST 15  // Or set to -1 and connect to Arduino RESET pin
#define TFT_DC 14

to suit your ST7789 pins usage?
and change tft.init() to

 tft.init(135, 240);           // Init ST7789 240x135

@horace I change nothing all i did was comment out line 67.

I did manage to find this online. But its for python.

https://github.com/sbcshop/Pico-4G-Expansion/blob/main/Lcd1_14driver.py

looking at code in post 1 your configuration was

#define TFT_CS   17
#define TFT_DC   21
#define TFT_RST  20

if that is the 4G Expansion board configuration change the code to these values

also you probably require

tft.init(135, 240);           // Init ST7789 240x135