Ejemplo n.º 1
0
        /// <summary>
        /// Read the sensor values from the relevant registers and parse.
        /// </summary>
        public AccelerationAndGyroData GetSensorData()
        {
            byte[] registerList = new byte[]
            {
                MPU6050Registers.ACCEL_XOUT_H,
                MPU6050Registers.ACCEL_XOUT_L,
                MPU6050Registers.ACCEL_YOUT_H,
                MPU6050Registers.ACCEL_YOUT_L,
                MPU6050Registers.ACCEL_ZOUT_H,
                MPU6050Registers.ACCEL_ZOUT_L,
                MPU6050Registers.TEMP_OUT_H,
                MPU6050Registers.TEMP_OUT_L,
                MPU6050Registers.GYRO_XOUT_H,
                MPU6050Registers.GYRO_XOUT_L,
                MPU6050Registers.GYRO_YOUT_H,
                MPU6050Registers.GYRO_YOUT_L,
                MPU6050Registers.GYRO_ZOUT_H,
                MPU6050Registers.GYRO_ZOUT_L
            };

            // Funky - you need to do this, otherwise you won't get anything back. See MPU-6050 datasheet for details.
            //_I2C.Write(new byte[] { MPU6050Registers.ACCEL_XOUT_H });
            _I2CBus.Write(_i2cConfig, new byte[] { MPU6050Registers.ACCEL_XOUT_H }, _timeout);
            //_I2C.Read(registerList);
            _I2CBus.Read(_i2cConfig, registerList, _timeout);

            var result = AccelerationAndGyroDataBuilder.Build(registerList, _gyroRange, _accelRange);

            return(result);
        }
Ejemplo n.º 2
0
        public override string ToString()
        {
            var temp = AccelerationAndGyroDataBuilder.ConvertValueToString(Temp, 2, 1);
            var aX   = AccelerationAndGyroDataBuilder.ConvertValueToString(Ax, 1, 3);
            var aY   = AccelerationAndGyroDataBuilder.ConvertValueToString(Ay, 1, 3);
            var aZ   = AccelerationAndGyroDataBuilder.ConvertValueToString(Az, 1, 3);
            var rX   = AccelerationAndGyroDataBuilder.ConvertValueToString(Rx, 3, 1);
            var rY   = AccelerationAndGyroDataBuilder.ConvertValueToString(Ry, 3, 1);
            var rZ   = AccelerationAndGyroDataBuilder.ConvertValueToString(Rz, 3, 1);

            return("T: " + temp + "degC" +
                   "\tG: " + aX + "X   " + aY + "Y   " + aZ + "Z" +
                   "\tR: " + rX + "X   " + rY + "Y   " + rZ + "Z");
        }