/// <summary> /// https://www.bosch-sensortec.com/media/boschsensortec/downloads/datasheets/bst-bno055-ds000.pdf /// Page 26 /// </summary> private void RemapAxis() { byte axisPositionAddress = 0x41; byte axisSignAddress = 0x42; byte newAxisPosition = 0b00_10_00_01; byte newAxisSigns = 0b00000_1_0_0; sensor.OperatingMode = Bno055.OperatingModes.CONFIGURATION_MODE; Thread.Sleep(100); #if DEBUG Console.WriteLine($"Writing: {Convert.ToString(newAxisPosition, 2)} to {axisPositionAddress:X}"); Console.WriteLine($"Writing: {Convert.ToString(newAxisSigns,2)} to {axisSignAddress:X}"); #endif bno.WriteRegister(axisPositionAddress, newAxisPosition); bno.WriteRegister(axisSignAddress, newAxisSigns); Thread.Sleep(100); sensor.OperatingMode = Bno055.OperatingModes.NINE_DEGREES_OF_FREEDOM; }
public static SensorReading CreateFromDevice(I2cPeripheral device, SensorSettings sensorSettings) { // Read the current control register var status = device.ReadRegister(RegisterAddresses.ControlTemperatureAndPressure.Address); // Force a sample status = BitHelpers.SetBit(status, 0x00, true); device.WriteRegister(RegisterAddresses.ControlTemperatureAndPressure.Address, status); // Wait for the sample to be taken. do { status = device.ReadRegister(RegisterAddresses.ControlTemperatureAndPressure.Address); } while (BitHelpers.GetBitValue(status, 0x00)); var sensorData = device.ReadRegisters( RegisterAddresses.AllSensors.Address, RegisterAddresses.AllSensors.Length) .AsSpan(); var rawPressure = GetRawValue(sensorData.Slice(0, 3)); var rawTemperature = GetRawValue(sensorData.Slice(3, 3)); var rawHumidity = GetRawValue(sensorData.Slice(6, 2)); //var rawVoc = GetRawValue(sensorData.Slice(8, 2)); var compensationData1 = device.ReadRegisters(RegisterAddresses.CompensationData1.Address, RegisterAddresses.CompensationData1.Length); var compensationData2 = device.ReadRegisters(RegisterAddresses.CompensationData2.Address, RegisterAddresses.CompensationData2.Length); var compensationData = ArrayPool <byte> .Shared.Rent(64); try { Array.Copy(compensationData1, 0, compensationData, 0, compensationData1.Length); Array.Copy(compensationData2, 0, compensationData, 25, compensationData2.Length); var temp = RawToTemp(rawTemperature, new TemperatureCompensation(compensationData)); var pressure = RawToPressure(temp, rawPressure, new PressureCompensation(compensationData)); var humidity = RawToHumidity(temp, rawHumidity, new HumidityCompensation(compensationData)); return(new SensorReading(pressure, temp, humidity, 0, sensorSettings)); } finally { ArrayPool <byte> .Shared.Return(compensationData, true); } }