Why do I have to open and close serial monitor in ArduinoIDE after reset/connection?

  • Arduino Nano 33 BLE genuine
  • Connected via microUSB
  • Windows 11 (latest 15/12/2023)
    Why do I need to open and close ArduinoIDE Serial Monitor before FaceTrackNoIR will read serial data with ArduinoHatire Plugin? I would like to be able to restart or reconnect the Arduino and just have FaceTrackNoIR read the serial data.

    I'm a noob with Arduino so any help pointing me in the right direction will be greatly appreciated.
#include <Arduino_LSM9DS1.h>

// Arduino frame structure
struct TArduinoData
{
    uint16_t Begin;         // Header trame 0xAAAA;
    uint16_t Code;         // 0-999 = TRACKING (+frame counter), 1000-1999 = CALIBRATING (+frame counter)
    float Rot[3];
    float Trans[3];
    uint16_t End;            // End trame 0x5555;
} ;
TArduinoData hat;

//  SERIAL_PORT_SPEED defines the speed to use for the debug serial port
#define  SERIAL_PORT_SPEED  9600

// Sensor measurements
float ax, ay, az; // Accelerometer data in m/s^2
float gx, gy, gz; // Gyroscope data in rad/s

void setup() 
{
  if(!IMU.begin())
  {
    while (1);
  }
  Serial.begin(9600);
  // header frame
  hat.Begin=0xAAAA;
  // Frame Number or Error code
  //hat.Cpt=0;
  hat.Code = 0;
  hat.Rot[0] = 0;
  hat.Rot[1] = 0;
  hat.Rot[2] = 0;
  hat.Trans[0] = 0;
  hat.Trans[1] = 0;
  hat.Trans[2] = 0;
  // footer frame
  hat.End=0x5555;
}
 
 void loop() 
 {
	// Read sensor data
	IMU.readAcceleration(ax, ay, az);
	IMU.readGyroscope(gx, gy, gz);
		
  hat.Rot[0] = ax*90;//pitch;
  hat.Rot[1] = ay*90;//roll;

  hat.Code++;
  if (hat.Code>999) 
  {
    hat.Code=0;
  }
  // Send HAT  Trame to  PC
  Serial.write((byte*)&hat,30);

  delay(1);
}      

'cause the programmers of the IDE did not care enough.

1 Like

That's what I'm afraid of, but I was wondering if I could do anything extra in my sketch to make up for that.

No way.

Thank you, I found out serial connection works fine in opentrack!

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.