private void Initialize() { //Initialize the gyro _twiBus.Write(_i2cConfiguration, new byte[] { 0x3E, 0x80 }, 100); // send a reset to the device _twiBus.Write(_i2cConfiguration, new byte[] { 0x15, 0x00 }, 100); // 1kHz sample rate _twiBus.Write(_i2cConfiguration, new byte[] { 0x16, 0x1D }, 100); // 10Hz low pass filter _twiBus.Write(_i2cConfiguration, new byte[] { 0x17, 0x05 }, 100); // enable send raw values _twiBus.Write(_i2cConfiguration, new byte[] { 0x3E, 0x01 }, 100); // use internal oscillator Zero(); }
/// <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); }
/// <summary> /// Write operation to the BlinkM. /// </summary> /// <param name="command"></param> /// <returns></returns> public int Write(Command.BaseCommand command) { I2CBus bus = I2CBus.GetInstance(); int retValue = bus.Write(this._I2CConfig, command.GetSendBytes(), I2CTimeout); if (command.WaitMillis > 0) { Thread.Sleep(command.WaitMillis); } return(retValue); }
///<Summary> /// Inizilizza in sensore ///</Summary> public bool setup() { i2cs = Gadgeteer.SocketInterfaces.I2CBusFactory.Create(Socket.GetSocket(4, false, null, null), I2C_ADDRESS, 400, null); byte[] outBuffer = new byte[2] { CONFIGURATION_REGISTER, CONFIGURATION_WORD }; if (i2cs.Write(outBuffer) == 1) { return(true); } return(false); }
///<Summary> /// Ritorna un oggetto Temperatura ///</Summary> public Temperatura getTemp() { Temperatura t = new Temperatura(); byte[] RegisterNum = new byte[1] { TEMPERATURE_REGISTER }; byte[] RegisterValue = new byte[2]; i2cs.WriteRead(RegisterNum, RegisterValue); Debug.Print("MSB: " + RegisterValue[0] + " LSB: " + RegisterValue[1]); t.setMSB(RegisterValue[0]); //Primo Byte MSB1 t.setLSB(RegisterValue[1]); //Secondo Byte LSB byte[] ResetValue = new byte[1] { RESET_WORD }; i2cs.Write(ResetValue); return(t); }
/// <summary> /// Reset the DS2482 and read the status byte /// </summary> private void ResetDS2482() { try { commandBytes = new byte[1] { (byte)DS2482FunctionCommands.DeviceReset }; readBuffer = new byte[1]; i2cBus.Write(commandBytes, commTimeout); i2cBus.Read(readBuffer, commTimeout); // Verify that communication has occured. After reset RST bit should be 1 if ((readBuffer[0] & (byte)DS2482StatusBits.DeviceReset) != (byte)DS2482StatusBits.DeviceReset) { throw new Exception("DS2482 not found on I2C Bus"); } } catch (Exception) { throw; } }