Nano 33 BLE vs Nano Every speed

Nano 33 BLE vs Nano Every

I wrote an app that logs to a microSD card using a Nano Every. Decided to switch project to a Nano 33 BLE in order to move from an external IMU to the internal IMU. After swapping and compiling I noticed that the routine processes much slower in the BLE.

Here is a minimized piece of code demonstrating how the open-write-close of the microSD is much slower in the Nano 33 BLE at 89ms verses the same code in the Nano Every at 16ms.

Is there extra overhead in the BLE related to my unused Bluetooth hardware? Is the BLE energy saving? Or the ATMega4809 at 20 Mhz simply faster than the NINA-B306 at 64 Mhz?

Help is appreciated.

M

#include <SPI.h>
#include <SD.h>

const int chipSelect = 10;
unsigned long oldMillis = 0;
unsigned long newMillis = 0;


void setup() {

  Serial.begin(115200);
  while (!Serial) { ; }

  Serial.print("Initializing SD card...");

  if (!SD.begin(chipSelect)) {
    Serial.println("Card failed, or not present");
    // don't do anything more:
    while (1);
  }
  Serial.println("card initialized.");
}


void loop() {

  File dataFile = SD.open("SDTest.txt", FILE_WRITE);

  if (dataFile) {
    dataFile.println("Write 22 bytes of data");
    dataFile.close();
    newMillis = millis();
    Serial.println(newMillis - oldMillis);
    oldMillis = newMillis;
  }
  else {
    Serial.println("error opening datalog.txt");
  }
}

I'm having similar concerns. I wrote an even more trivial script to try to get a sense of the raw speed of a few different devices:

void setup() {
  // put your setup code here, to run once:
  pinMode(9, OUTPUT);
}

void loop() {
  // put your main code here, to run repeatedly:
  digitalWrite(9, HIGH);
  digitalWrite(9, LOW);
}

And then measured the speed using a multimeter and an oscilloscope which agreed within 100Hz in each case:

Device MCU Clock Measured speed
Sparkfun Pro Micro ATMEGA32U4 16MHz 97.6kHz
Arduino NANO (Elegoo clone) ATMEGA328P 16MHz 126.1kHz
Arduino NANO Every ATMEGA4809 20MHz 277.7kHz
Arduino NANO 33 BLE NINA-b3 (nRF52840) 64Mhz 32.6kHz (!)

So, what with the poor library compatibility and abysmal compile times, I think I'm going to still with a separate BT module at least for now.

The issue is that the Nano 33 BLE is running mbed OS and you are using the Arduino way of accessing pins. The Arduino way is not fully compatible with the mbed OS style. But it allows older sketches to run on the new Nano 33 BLE and make use of new functionality like BLE.

davidhbrown:
Arduino NANO 33 BLE NINA-b3 (nRF52840) 64Mhz 32.6kHz (!)

To specify your results a bit more. This creates a puls 3us wide and repeated every 29us. So the loop function is repeated every 29us and the digitalWrite takes about 3us.

When you use the following code in mbed style. The puls is 30ns wide and is repeated every 526ns. So the puls is 100x faster and the loop runs 60x more often.

#include "mbed.h"

mbed::DigitalInOut ledPin( digitalPinToPinName( 9 ) );

void setup()
{
  ledPin.output();
}

void loop()
{
  // put your main code here, to run repeatedly:
  ledPin = HIGH;
  ledPin = LOW;
}

These mbed OS functions are called by the Arduino code, but you can also use them directly.

Klaus, thank you for insights, expertise, code sample, and confirming my suspicion about Mbed's involvement. Indeed, running your code, my multimeter was completely unable to detect the pulse and the oscilloscope reports ~1.83Mhz with a 15ns pulse width (8.8ns rise/fall time). Maybe I'm reading it wrong, since that's about half what you said it would be (occasionally there's a wider pulse with a flat top, but usually it is just up and down). Regardless of those details, plenty fast, indeed.

The product page, https://store.arduino.cc/usa/nano-33-ble, includes the statement, "If you used Arduino Nano in your projects in the past, the Nano 33 BLE is a pin-equivalent substitute. Your code will still work, but remember, it operates at 3.3V." While this is presumably true, it is misleading if code needs to be substantially rewritten to operate at (at least) the speed of previous devices. Even on the getting started page, https://www.arduino.cc/en/Guide/NANO33BLE, there's no discussion of mbed.h

I think that if I want to learn a new framework, I might just go for it more directly.

David, the Nano 33 BLE might be a bit slower switching a pin when you use the Arduino framework. On the other side you get a 32bit ARM processor running at three times the clock speed. This will give you a significant performance advantage over the AVR for computations.
So, depending the code I would say it’s still fair to say that it will run as fast as your program on previous devices, even if it is true that there are corner cases where this is not entirely true.

1 Like