mpu6050 - vlizBE/dcafs GitHub Wiki

Interfacing the MPU-6050

  • This guides assumes:

    • the hardware connections have been made
    • the I2C bus used is 3, alter this accordingly
    • i2c is on a sbc connected to via ssh
    • working pc is running windows
  • Required tools:

    • putty or any other ssh client
    • winscp

Add it to dcafs

  1. Figure out the address used with i2c:detect,3, this should atleast return:
    • Free - 0x68
      • or
    • Free - 0x69
  2. Add it to dcafs with the command i2c:adddevice,mpu,bus,address,scriptname
    • So this becomes: i2c:adddevice,mpu,3,0x68,mpu6050
      • This will add the file mpu6050.xml in a i2cscripts subfolder
          <?xml version="1.0" encoding="UTF-8" standalone="no"?>
           <commandset script="mpu6050">
             <!-- An empty command to start with -->
             <command id="cmdname" info="what this does"/>
           </commandset>
      • And also add the following section to the settings.xml:
         <i2c>
             <bus controller="3">
                 <device address="0x69" id="mpu"  script="mpu6050"/>
             </bus>
         </i2c>
  3. By default, dcafs has been started as root, so the script mpu6050.xml will be owned by root. Change this so anyone can alter it. This will be needed later unless you don't mind logging in as root in ssh.
    • When the cli is inside the dcafs folder: sudo chmod a+rw i2cscripts/mpu6050.xml

That's it, keep this session open.

Filling in the mpu6050.xml

  1. Open winscp.
  2. Open mpu6050 with your preferred text editor.
  3. First we'll add a command to read the gyro, the xml will become like this
    <?xml version="1.0" encoding="UTF-8" standalone="no"?>
    <commandset script="mpu6050">
        <!-- Read data: 16bit spread over 6 registers starting at 0x43 -->        
        <command id="readgyro" info="Read gyro x,y and z" bits="16">
          <read reg="0x43" return="6"/>
        </command>
    </commandset>
  4. In the dcafs session, use i2c:reload

    All files (1) read ok

  5. Check this with i2c:list

    mpu -> @3:0x68 using script mpu6050 with label void -Stored scripts-
    mpu6050
    readgyro -> Read gyro x,y and z (16bits)
    Read 6 bytes from reg 0x43

  6. Test the new command with i2c:id,command so i2c:mpu,readgyro
⚠️ **GitHub.com Fallback** ⚠️