Matrix Portal S3 - Always in UF2 BL Mode after Uploading Arduino Sketch

For Adafruit customers who seek help with microcontrollers

Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.
Post Reply
User avatar
MichaelScholz
 
Posts: 15
Joined: Mon Jul 30, 2018 8:20 pm

Matrix Portal S3 - Always in UF2 BL Mode after Uploading Arduino Sketch

Post by MichaelScholz »

Hi!
I just studied all the 'how to upload an Arduino sketch to the Matrix S3 Portal' and 'how to fix a trashed UF2 BL' threads that I found through google and forum search, but that still doesn't get me the answer to my problem.
After uploading a sketch (the log showed it was done successfully), I pressed the Reset button and suddenly the onboard RGB LED sprang to life and I got the MAXS3BOOT drive in my folder view. No matter how hard I tried the 'press the DFU/Boot button, keep it pressed, the press Reset, let go of it and then release the DFU/Boot button' procedure to enter the ROM BL in order to upload my sketch, after uploading the Sketch from Arduino IDE I end up in the UF2 BL mode with the RGB LED color cycling into green and the tiny red LED next to the ESP32 in soft flash mode.
What did I miss to do that enables me to upload - and first and foremost RUN - my Arduino sketches again? I don't think I trashed the board yet, as the connected 64x32 Matrix LED display shows this cute little drawing after a factory reset is performed.

Thanks,

Michael

User avatar
mikeysklar
 
Posts: 13544
Joined: Mon Aug 01, 2016 8:10 pm

Re: Matrix Portal S3 - Always in UF2 BL Mode after Uploading Arduino Sketch

Post by mikeysklar »

Doesn't the Arduino IDE prompt you for one brief manual reset press after upload?

User avatar
MichaelScholz
 
Posts: 15
Joined: Mon Jul 30, 2018 8:20 pm

Re: Matrix Portal S3 - Always in UF2 BL Mode after Uploading Arduino Sketch

Post by MichaelScholz »

Yes, it does, but pressing reset gets me right into UF bootloader mode again. The RGB LED does its red / lilac / green color dance and I end up with MTRXS3BOOT drive listed in my folder view.

User avatar
MichaelScholz
 
Posts: 15
Joined: Mon Jul 30, 2018 8:20 pm

Re: Matrix Portal S3 - Always in UF2 BL Mode after Uploading Arduino Sketch

Post by MichaelScholz »

To test my hardware, I gave this Circuit Python project a try on the matrix portal https://learn.adafruit.com/rgb-matix-ny ... r/overview. Installing Circuit Python and the scroller's project files and getting the display to display some news, worked like a charm, in a matter of 5 minutes. Hence I assume the board is still working.

However, trying to get an Arduino sketch to run keeps failing. The code in question is this:

Code: Select all

/* ----------------------------------------------------------------------
Double-buffering (smooth animation) Protomatter library example.
PLEASE SEE THE "simple" EXAMPLE FOR AN INTRODUCTORY SKETCH.
Comments here pare down many of the basics and focus on the new concepts.

This example is written for a 64x32 matrix but can be adapted to others.
------------------------------------------------------------------------- */

#include <Adafruit_Protomatter.h>

/* ----------------------------------------------------------------------
The RGB matrix must be wired to VERY SPECIFIC pins, different for each
microcontroller board. This first section sets that up for a number of
supported boards.
------------------------------------------------------------------------- */

uint8_t rgbPins[]  = {42, 41, 40, 38, 39, 37};
uint8_t addrPins[] = {45, 36, 48, 35, 21};
uint8_t clockPin   = 2;
uint8_t latchPin   = 47;
uint8_t oePin      = 14;

/* ----------------------------------------------------------------------
Matrix initialization is explained EXTENSIVELY in "simple" example sketch!
It's very similar here, but we're passing "true" for the last argument,
enabling double-buffering -- this permits smooth animation by having us
draw in a second "off screen" buffer while the other is being shown.
------------------------------------------------------------------------- */

Adafruit_Protomatter matrix(
  64,          // Matrix width in pixels
  6,           // Bit depth -- 6 here provides maximum color options
  1, rgbPins,  // # of matrix chains, array of 6 RGB pins for each
  4, addrPins, // # of address pins (height is inferred), array of pins
  clockPin, latchPin, oePin, // Other matrix control pins
  true);       // HERE IS THE MAGIC FOR DOUBLE-BUFFERING!


// SETUP - RUNS ONCE AT PROGRAM START --------------------------------------

void setup(void) {
  Serial.begin(115200);

  // Initialize matrix...
  ProtomatterStatus status = matrix.begin();
  Serial.print("Protomatter begin() status: ");
  Serial.println((int)status);
  if(status != PROTOMATTER_OK) {
    // DO NOT CONTINUE if matrix setup encountered an error.
    for(;;);
  }

  matrix.setRotation(2);
  matrix.fillScreen(0); // Fill background black
  matrix.setTextColor(matrix.color565(20, 15, 15));  // warm-whitish
  matrix.show();
}

void displayTime(bool showDelimiter) {
  char time[9] = {"12:00:00"};
  char time1[9] = {"12 00 00"};
  char date[11] = {"2024.02.09"};
  
  matrix.fillScreen(0);

  matrix.setCursor(9, 7);
  if (showDelimiter) {
    matrix.print(time);
  }
  else {
    matrix.print(time1);
  }
  
  matrix.setCursor(3, 17);
  matrix.print(date);

  matrix.drawRect(59, 27, 4, 4, matrix.color565(0, 15, 0));
  matrix.drawRect(60, 28, 2, 2, matrix.color565(0, 15, 0));

  matrix.show();
}

// LOOP - RUNS REPEATEDLY AFTER SETUP --------------------------------------
void loop(void) {
  displayTime(true);
  usleep(200000);

  displayTime(false);
  usleep(800000);
}
I daisy chained 2 32x32 LED Matrix panels for a 64x32 display.

What do I miss?


Thanks,

Michael

User avatar
mikeysklar
 
Posts: 13544
Joined: Mon Aug 01, 2016 8:10 pm

Re: Matrix Portal S3 - Always in UF2 BL Mode after Uploading Arduino Sketch

Post by mikeysklar »

Since dropping in the factory reset image still works I suspect the issue is with being in BLE mode or the sketch. Maybe we can narrow it down.

When you try running the Blink example from the Arduino IDE do things work as expected?

What OS are you using?

Which version of the Arduino IDE?

Which version of the esp32 board support package?

User avatar
MichaelScholz
 
Posts: 15
Joined: Mon Jul 30, 2018 8:20 pm

Re: Matrix Portal S3 - Always in UF2 BL Mode after Uploading Arduino Sketch

Post by MichaelScholz »

OS: macOS Monterey, 12.7.3 (21H1015)
Arduino IDE: 2.3.0
esp32 board support package: 2.0.14 (I don't use 3.0.0-alpha, most of the sketches don't compile in this context)
blink sketch: compiles, uploads and runs (shame on me I didn't try that)
my sketch (re-uploaded after the blink sketch): compiles, uploads and - again - enters the UF2 BL mode, dang!

board config (https://prnt.sc/LJdUgj33AM8U):
Image

User avatar
MichaelScholz
 
Posts: 15
Joined: Mon Jul 30, 2018 8:20 pm

Re: Matrix Portal S3 - Always in UF2 BL Mode after Uploading Arduino Sketch

Post by MichaelScholz »

I got news... after fiddling around with things, I found that changing this section

Code: Select all

void loop(void) {
  displayTime(true);
  usleep(200000);

  displayTime(false);
  usleep(800000);
}
into this (adding the delay(1);)

Code: Select all

void loop(void) {
  displayTime(true);
  usleep(200000);

  displayTime(false);
  usleep(800000);

  delay(1);
}
makes it work. Now it runs as expected. Thank you for motivating me to reconsider the code.

The question remains, why does it go wrong without the delay(1); command?


Thanks,

Michael

User avatar
mikeysklar
 
Posts: 13544
Joined: Mon Aug 01, 2016 8:10 pm

Re: Matrix Portal S3 - Always in UF2 BL Mode after Uploading Arduino Sketch

Post by mikeysklar »

I'm surprised it was going into bootloader and that delay(1) made a difference. Good find.

User avatar
MichaelScholz
 
Posts: 15
Joined: Mon Jul 30, 2018 8:20 pm

Re: Matrix Portal S3 - Always in UF2 BL Mode after Uploading Arduino Sketch

Post by MichaelScholz »

Yeah, if someone could help shedding some light onto this, I'd be grateful. ;)

User avatar
mikeysklar
 
Posts: 13544
Joined: Mon Aug 01, 2016 8:10 pm

Re: Matrix Portal S3 - Always in UF2 BL Mode after Uploading Arduino Sketch

Post by mikeysklar »

What is the origin of the Arduino sketch you were running?

It is not part of the NYT times scroller which you linked to, but is a CircuitPython project.

User avatar
MichaelScholz
 
Posts: 15
Joined: Mon Jul 30, 2018 8:20 pm

Re: Matrix Portal S3 - Always in UF2 BL Mode after Uploading Arduino Sketch

Post by MichaelScholz »

Hi!

I used the NYT Time Scroller to find out whether or not my board was all the way bricked. Since everything worked out fine, I suspected I had overwritten some essential bootcode.

The Arduino code is a 'stripped down to my needs' version of Adafruit's Protomatter library example "double buffer scrolltest".
Since I find it more pleasing when the hour/minute and minute/seconds delimiters blink at a 20% duty cycle (rather than that boring 50% / half a second one), I used the usleep(200000) ... usleep(800000) to accomplish this. But without the delay(1); I crash (?) into BL mode.

Anyway, I replaced the usleep with vTaskDelay, hence I could get rid of the delay() altogether, so the code looks like this now (gives you a nicely colored display of time of day and date (dd.mm.yyyy), the green rectangle in the lower right corner is a dummy for now and will be used later to display the NTP sync state):

Code: Select all

/* ----------------------------------------------------------------------
Double-buffering (smooth animation) Protomatter library example.
PLEASE SEE THE "simple" EXAMPLE FOR AN INTRODUCTORY SKETCH.
Comments here pare down many of the basics and focus on the new concepts.

This example is written for a 64x32 matrix but can be adapted to others.
------------------------------------------------------------------------- */

#include "time.h"
#include "esp_sntp.h"
#include <WiFi.h>
#include <Adafruit_Protomatter.h>

/* ----------------------------------------------------------------------
The RGB matrix must be wired to VERY SPECIFIC pins, different for each
microcontroller board. This first section sets that up for a number of
supported boards.
------------------------------------------------------------------------- */

uint8_t rgbPins[]  = {42, 41, 40, 38, 39, 37};
uint8_t addrPins[] = {45, 36, 48, 35, 21};
uint8_t clockPin   = 2;
uint8_t latchPin   = 47;
uint8_t oePin      = 14;

/* ----------------------------------------------------------------------
Matrix initialization is explained EXTENSIVELY in "simple" example sketch!
It's very similar here, but we're passing "true" for the last argument,
enabling double-buffering -- this permits smooth animation by having us
draw in a second "off screen" buffer while the other is being shown.
------------------------------------------------------------------------- */

Adafruit_Protomatter matrix(
  64,          // Matrix width in pixels
  6,           // Bit depth -- 6 here provides maximum color options
  1, rgbPins,  // # of matrix chains, array of 6 RGB pins for each
  4, addrPins, // # of address pins (height is inferred), array of pins
  clockPin, latchPin, oePin, // Other matrix control pins
  true);       // HERE IS THE MAGIC FOR DOUBLE-BUFFERING!


/* WiFi, fixed credentials for now*/
const char* ssid       = "YOUR SSID";
const char* password   = "YOUR PASS";

/* UDP and NTP stuff */
const char* ntpServer1 = "pool.ntp.org";
const char* ntpServer2 = "time.nist.gov";
// TimeZone rule for Europe/Rome including daylight adjustment rules
const char* time_zone = "CET-1CEST,M3.5.0,M10.5.0/3";


void printLocalTime() {
  struct tm timeinfo;

  if(!getLocalTime(&timeinfo)) {
    Serial.println("No time available (yet)");
    return;
  }
  Serial.println(&timeinfo, "%A, %B %d %Y %H:%M:%S");
}

// Callback function (get's called when time adjusts via NTP)
void timeavailable(struct timeval *t) {
  Serial.println("Got time adjustment from NTP!");
  printLocalTime();
}

// SETUP - RUNS ONCE AT PROGRAM START --------------------------------------
void setup(void) {
  Serial.begin(115200);

  // Initialize matrix...
  ProtomatterStatus status = matrix.begin();
  Serial.print("Protomatter begin() status: ");
  Serial.println((int)status);
  if(status != PROTOMATTER_OK) {
    while (true);  // DO NOT CONTINUE if matrix setup encountered an error.
  }

  matrix.setRotation(0);
  matrix.fillScreen(0); // Fill background black
  matrix.setTextColor(0xfc6900 /*matrix.color565(20, 15, 15)*/);  // warm-whitish
  matrix.show();

  sntp_set_time_sync_notification_cb(timeavailable);
  sntp_servermode_dhcp(1);
  configTzTime(time_zone, ntpServer1, ntpServer2);

  WiFi.begin(ssid, password);
  while (WiFi.status() != WL_CONNECTED) {
      vTaskDelay(500);
      Serial.print(".");
  }
  Serial.println(" CONNECTED");
}

void displayTime(bool showDelimiter) {
  struct tm timeinfo = {0};
  char buffer[11] = {0};

  while(!getLocalTime(&timeinfo)) {
      vTaskDelay(5);
  }

  matrix.fillScreen(0);

  matrix.setCursor(9, 7);
  snprintf(buffer, sizeof(buffer), "%02d%c%02d%c%02d", timeinfo.tm_hour, showDelimiter?':':' ', timeinfo.tm_min, showDelimiter?':':' ', timeinfo.tm_sec);
  matrix.print(buffer);
  
  memset(buffer, 0, sizeof(buffer));

  matrix.setCursor(3, 17);
  snprintf(buffer, sizeof(buffer), "%02d.%02d.%04d", timeinfo.tm_mday, timeinfo.tm_mon+1, timeinfo.tm_year+1900);
  matrix.print(buffer);

  matrix.drawRect(60, 28, 4, 4, matrix.color565(0, 15, 0));
  matrix.drawRect(61, 29, 2, 2, matrix.color565(0, 15, 0));

  matrix.show();
}

// LOOP - RUNS REPEATEDLY AFTER SETUP --------------------------------------
void loop(void) {
  displayTime(true);
  vTaskDelay(200);

  displayTime(false);
  vTaskDelay(800);
}

Thanks,

Michael

User avatar
mikeysklar
 
Posts: 13544
Joined: Mon Aug 01, 2016 8:10 pm

Re: Matrix Portal S3 - Always in UF2 BL Mode after Uploading Arduino Sketch

Post by mikeysklar »

Nice solution using vTaskDelay. Thank you for sharing the full code as well.

Post Reply
Please be positive and constructive with your questions and comments.

Return to “Microcontrollers”