Esempio n. 1
0
        private static void Main(string[] args)
        {
            RaspProc.StartInfo.UseShellExecute        = false;
            RaspProc.StartInfo.RedirectStandardOutput = true;

            var accelerometerData = new XyzUshortS();
            var magnetometerData  = new XyzUshortS();
            var gyroscopeData     = new XyzUshortS();


            // Enable bypass mode to get data from magnetometer (AK8963).
            I2C.set_byte(I2C_Regs_Addrs.MPU9255.DevAddr, I2C_Regs_Addrs.MPU9255.IntBypEnAddr,
                         I2C_Regs_Addrs.MPU9255.BypEnBit);

            // Set continuous mode of magnetometer data gathering.
            I2C.set_byte(I2C_Regs_Addrs.AK8963.DevAddr, I2C_Regs_Addrs.AK8963.Cntl1Addr,
                         I2C_Regs_Addrs.AK8963.CntnsMode2Set);

            Console.WriteLine("Setting up connection with 10DOF IMU...");

            I2C.get_XYZ_data(I2C_Regs_Addrs.MPU9255.DevAddr, I2C_Regs_Addrs.MPU9255.AccAddr,
                             ref accelerometerData);

            I2C.get_XYZ_data(I2C_Regs_Addrs.MPU9255.DevAddr, I2C_Regs_Addrs.MPU9255.GyroAddr,
                             ref gyroscopeData);

            I2C.get_XYZ_data(I2C_Regs_Addrs.AK8963.DevAddr, I2C_Regs_Addrs.AK8963.MagnAddr,
                             ref magnetometerData);

            Console.WriteLine(accelerometerData.ToString());
            Console.WriteLine(gyroscopeData.ToString());
            Console.WriteLine(magnetometerData.ToString());
        }
Esempio n. 2
0
        public static void get_XYZ_data(byte devAddr, byte regAddr, ref XyzUshortS dest)
        {
            Program.RaspProc.StartInfo.FileName = "i2cget";
            for (byte i = 0; i < 6; i++)
            {
                Program.RaspProc.StartInfo.Arguments = "-y 1 " + devAddr + " " + regAddr; \
                Program.RaspProc.Start();
                var readLine = Program.RaspProc.StandardOutput.ReadLine();
                if (readLine != null)
                {
                    dest.RcvBuf[i] = Convert.ToByte(readLine.Substring(0, 4), 16);
                }
                dest.assign_data();
                regAddr++;
            }

            Program.check_procbuff_empty();
        }