Arduino Library Deployment

Hi,

First Post so apologies if this doesn’t follow any specific rules or formatting.

I have been following the gesture control examples on the website and can confirm I have achieved the following:

  1. Trained a model
  2. Uploaded to Arduino BLE 33 using the command Prompt Flash (Firmware)
  3. Run impulse in command prompt and all works correct. i.e. it detects my gestures with good accuracy.

However, as I now want the Arduino to do something useful with the detections I have done the following:

  1. Exported Arduino .ZIP library from deployment.
  2. Included the .ZIP library in Arduino IDE and build and upload to the Arduino BLE 33.
  3. Compile and upload the Example “nano_ble33_sense_accelerometer”

These are the following issues I am having:

  1. It takes an absolute age to build and upload the program. (~30 mins)
  2. A lot of the times it is changing COM Ports. It looks as if it goes into Bootloader mode by itself.
  3. When it does eventually upload to the board I open Serial Monitor and get nothing (baud rate correct). I have on some occasions have it display Sampling… but nothing from there.

Any Ideas?

Hi @bobby1991,

  1. Compiling under Arduino takes definitely some time but it should be less than 5 minutes. Which hardware/environment do you have?
  2. The COM ports changing is a recurrent issue for Arduino Windows users, I don’t know if there is a way to “lock” it but it’s worth checking on the Arduino forum.
  3. Have you modified the nano_ble33_sense_accelerometer example? This one should work out of the box with the Arduino BLE Sense 33.

Aurelien

Because of the Com Port switching for the Bootloader I always need to manually reselect the Com Port in the Tools Menu for the Serial Monitor to work. Have you verified that the Serial Monitor is on the correct port?

Aurel,

Thank you for the response. I have resolved my issues now:

  • COM PORT kept changing to COM4 so I always just put it into boot loader (press reset twice) then compiles and builds ok. Then I can load serial monitor when changing to COM 3.
  • Compilation time has been reduced after a few builds.
  • I’ve trained my own gesture model and deployed it to the board. Changing the RGB LED for different gestures.

Thank you for the quick response.

Bobby

1 Like

#include <gestures_inference.h>
#include <Arduino_LSM9DS1.h>

static signed short redPin = 22;
static signed short greenPin = 23;
static signed short bluePin = 24;

static signed short classificationNone = EI_CLASSIFIER_LABEL_COUNT;

static bool debug_nn = true; // Set this to true to see e.g. features generated from the raw signal

#define CONVERT_G_TO_MS2 9.80665f

void setup()
{
// put your setup code here, to run once:
Serial.begin(9600);

if (!IMU.begin()) {
    ei_printf("Failed to initialize IMU!\r\n");
}
else {
    ei_printf("IMU initialized\r\n");
}

if (EI_CLASSIFIER_RAW_SAMPLES_PER_FRAME != 3) {
    ei_printf("ERR: EI_CLASSIFIER_RAW_SAMPLES_PER_FRAME should be equal to 3 (the 3 sensor axes)\n");
    return;
}

}

void ei_printf(const char *format, …) {
static char print_buf[1024] = { 0 };
va_list args;
va_start(args, format);
int r = vsnprintf(print_buf, sizeof(print_buf), format, args);
va_end(args);
if (r > 0) {Serial.write(print_buf);}
}

void loop()
{
ei_printf("\nStarting inferencing in 2 seconds…\n");
ei_printf(“Sampling…\n”);

// Allocate a buffer here for the values we'll read from the IMU
float buffer[EI_CLASSIFIER_DSP_INPUT_FRAME_SIZE] = { 0 };

for (size_t ix = 0; ix < EI_CLASSIFIER_DSP_INPUT_FRAME_SIZE; ix += 3) {
    // Determine the next tick (and then sleep later)
    uint64_t next_tick = micros() + (EI_CLASSIFIER_INTERVAL_MS * 1000);
    IMU.readAcceleration(buffer[ix], buffer[ix + 1], buffer[ix + 2]);
    buffer[ix + 0] *= CONVERT_G_TO_MS2;
    buffer[ix + 1] *= CONVERT_G_TO_MS2;
    buffer[ix + 2] *= CONVERT_G_TO_MS2;
    delayMicroseconds(next_tick - micros());
}

// Turn the raw buffer in a signal which we can the classify
signal_t signal;
int err = numpy::signal_from_buffer(buffer, EI_CLASSIFIER_DSP_INPUT_FRAME_SIZE, &signal);
if (err != 0) {
    ei_printf("Failed to create signal from buffer (%d)\n", err);
    return;
}

// Run the classifier
ei_impulse_result_t result = { 0 };
err = run_classifier(&signal, &result, debug_nn);
if (err != EI_IMPULSE_OK) {
    ei_printf("ERR: Failed to run classifier (%d)\n", err);
    return;
}


// print the predictions
ei_printf("Predictions (DSP: %d ms., Classification: %d ms., Anomaly: %d ms.): \n",
    result.timing.dsp, result.timing.classification, result.timing.anomaly);
for (size_t ix = 0; ix < EI_CLASSIFIER_LABEL_COUNT; ix++) {
    ei_printf("    %s: %.5f\n", result.classification[ix].label, result.classification[ix].value);
    
    if (result.classification[ix].value > 0.7) {
        if(ix==0){
          analogWrite(22,0);
          analogWrite(23,255);
          analogWrite(24,255);
          }
          else if(ix==1){
          analogWrite(22,255);
          analogWrite(23,0);
          analogWrite(24,255); 
          }
          else if(ix==2){
          analogWrite(22,255);
          analogWrite(23,255);
          analogWrite(24,0); 
          }
          else{
          analogWrite(22,0);
          analogWrite(23,0);
          analogWrite(24,255);
            }
    }
}

#if EI_CLASSIFIER_HAS_ANOMALY == 1
ei_printf(" anomaly score: %.3f\n", result.anomaly);
#endif
}

#if !defined(EI_CLASSIFIER_SENSOR) || EI_CLASSIFIER_SENSOR != EI_CLASSIFIER_SENSOR_ACCELEROMETER
#error “Invalid model for current sensor”
#endif