Thanks for the reply, no I appreciate I may have left needed information out.I have no experience of what you are trying to accomplish, so cannot help directly.
But to improve the quality of advice you might be able to get from these Raspberry Pi forums it would be helpful to have background information such as -
- What model of RPi board you are using;
- What Operating System it is running;
- How the sensor is connected to the RPi board;
- What code you have written to interact with the sensor via the dotnet library.
1. Raspberry Pi 5 Model B Rev 1.0, 2GB.
2. Raspberry Pi Os 64-BIT
3. Connected via QWIIC STEMMA to pins
3 - Blue
4 - Power
5 - Gnd
6 - Yellow
I initialise in the constructor
Code:
public Bno055Controller( ILogger<Bno055Controller> logger, int i2cAddress, int recalibrationIntervalMinutes, int i2cBusId = 1){ _logger = logger; try { var i2cSettings = new I2cConnectionSettings(i2cBusId, i2cAddress); var i2cDevice = I2cDevice.Create(i2cSettings); _bno055 = new Bno055Sensor(i2cDevice); // Initialize the MPU6050 _logger.LogInformation($"Id: {_bno055.Info.ChipId}, AccId: {_bno055.Info.AcceleratorId}, GyroId: {_bno055.Info.GyroscopeId}, MagId: {_bno055.Info.MagnetometerId}"); _logger.LogInformation($"Firmware version: {_bno055.Info.FirmwareVersion}, Bootloader: {_bno055.Info.BootloaderVersion}"); _logger.LogInformation($"Temperature source: {_bno055.TemperatureSource}, Operation mode: {_bno055.OperationMode}, Units: {_bno055.Units}"); _logger.LogInformation($"Powermode: {_bno055.PowerMode}"); _bno055.OperationMode = OperationMode.AccelerometerGyroscopeRelativeOrientation; _logger.LogInformation($"AccelerometerGyroscope operation mode set to {_bno055.OperationMode.ToString()}"); _logger.LogInformation("Running the SelfTest"); var testResult = _bno055.RunSelfTest(); _logger.LogInformation($"SelfTest result: {testResult.ToString()}"); _logger.LogInformation($"BNO055 initialized with I2C address {i2cAddress} on bus {i2cBusId}."); } catch (Exception ex) { _logger.LogError(ex, $"Failed to initialize BNO055 with I2C address {i2cAddress} on bus {i2cBusId}. Check connections and configuration."); //throw new InvalidOperationException("MPU6050 initialization failed. Ensure the device is connected and configured correctly.", ex); } _recalibrationIntervalMinutes = recalibrationIntervalMinutes; _lastCalibrationTime = DateTime.Now;}Next
Code:
public async Task<AccelerometerData> GetRawDataAsync() { return await Task.Run(() => { var acceleration = GetAccelerometerVector(); var angularVelocity = GetGyroscopeVector(); var pitch = CalculatePitch(acceleration); var roll = CalculateRoll(acceleration); var yaw = CalculateYaw(angularVelocity); return new AccelerometerData { Pitch = pitch, Roll = roll, Yaw = yaw }; }); } // Method to get accelerometer data as Vector3 private Vector3 GetAccelerometerVector() { var accel = _bno055.Accelerometer; // Assuming it provides X, Y, Z properties //_logger.LogInformation($"Raw Acceleration: X={accel.X}, Y={accel.Y}, Z={accel.Z}"); return new Vector3(accel.X, accel.Y, accel.Z); } // Method to get gyroscope data as Vector3 private Vector3 GetGyroscopeVector() { var gyro = _bno055.Gyroscope; // Assuming it provides X, Y, Z properties //_logger.LogInformation($"Raw Gyro: X={gyro.X}, Y={gyro.Y}, Z={gyro.Z}"); return new Vector3(gyro.X, gyro.Y, gyro.Z); } public async Task<Vector3> GetRawAccelerationAsync() { return await Task.Run(() => { var acceleration = GetAccelerometerVector(); return new Vector3(acceleration.X, acceleration.Y, acceleration.Z); }); } public async Task<Vector3> GetRawAngularVelocityAsync() { return await Task.Run(() => { var angularVelocity = GetGyroscopeVector(); return new Vector3(angularVelocity.X, angularVelocity.Y, angularVelocity.Z); }); } private double CalculatePitch(Vector3 acceleration) => Math.Atan2(acceleration.X, Math.Sqrt(acceleration.Y * acceleration.Y + acceleration.Z * acceleration.Z)) * (180.0 / Math.PI); private double CalculateRoll(Vector3 acceleration) => Math.Atan2(acceleration.Y, acceleration.Z) * (180.0 / Math.PI); private double CalculateYaw(Vector3 angularVelocity) => angularVelocity.Z;Statistics: Posted by mfit — Mon Feb 17, 2025 12:42 pm