Slow serial on Nano 33 BLE

Hi everyone,

Recently, I purchase a Nano 33 BLE that act as i/o buffer for reading sensors and sending it to computer via Serial or BLE. However, I noticed that this have significant slow serial writing time. For instance, running the below script showed that it takes 6000us to send a single frame while on the the arduino due it only takes around 300us (20 time faster comparing with the BLE board). Even the MEGA board only takes 3000us to send a frame.

void setup() {
  // put your setup code here, to run once:
    Serial.begin(115200);
  while (!Serial) {}

  
}

void loop() {
  // put your main code here, to run repeatedly:
  uint32_t t0 = micros();
  for (uint8_t i =0; i<32; i++)
  {
    Serial.print(i);
    Serial.print("\t");
  }
  Serial.println("");
  uint32_t dt = micros() - t0;
  Serial.println(dt);
  delay(1000);
}

Does any one know why it happens and how to fix it ? Thank you everybody so much !

P/s: I also read that this board seem support variable baud rate, hence even though I set baud rate as 115200, serial monitor can still read just fine as 9600 ? Does that relate to my problem in anyway ?

The baudrate is meaningless for the Arduino Nano 33 BLE and Nano 33 IoT. They both use USB natively and the COM port is virtual.

I did some test and the issue is likely because you print each element separately. Because USB uses packets it would be useful to combine values before printing. This reduces the USB overhead. I got the time down to around 850us by using a buffer. The USB transfer/print takes about half of the time.

void setup()
{
  // put your setup code here, to run once:
  Serial.begin( 115200 );
  while ( !Serial ) {}
}

void loop()
{
#define BUFFER_SIZE 100
  // put your main code here, to run repeatedly:
  char buffer [BUFFER_SIZE];
  int cx = 0;

  uint32_t t0 = micros();
  for ( uint8_t i = 0; i < 32; i++ )
  {
    if ( cx >= 0 && cx < BUFFER_SIZE )
    {
      cx = cx + snprintf( buffer + cx, BUFFER_SIZE - cx, "%d\t", i );
    }
  }
  Serial.println( buffer );
  uint32_t dt = micros() - t0;
  Serial.println( dt );
  delay( 1000 );
}

Thank you, Klaus_K. I dig into the library and indeed, baud rate is just there for code compatibility, they should have mentioned it. I think will stick with the DUE board. I’m bit disappointed in the Nano BLE board

1 Like