Main Content

readAcceleration

Read one acceleration data sample from MPU-6050 sensor

Description

example

[accelReadings,timestamp] = readAcceleration(sensor) returns one sample of the acceleration data from the MPU-6050 IMU sensor. The acceleration sample is returned as a 3-by-1 vector in m/s2 along the X, Y, and Z axes. The function also returns the timestamp at which MATLAB® receives the acceleration data from the MPU-6050 sensor. The timestamp output is optional.

Examples

collapse all

Read the acceleration data from the MPU-6050 IMU sensor on the X, Y, and Z axes.

Create a connection from MATLAB to the Raspberry Pi™ hardware board.

mypi = raspi;
mypi = 

  Raspi with Properties:

           DeviceAddress: 'raspberrypi-hysdu8X38o'
                    Port: 18734
               BoardName: 'Raspberry Pi 3 Model B+'
           AvailableLEDs: {'led0'}
    AvailableDigitalPins: [4,5,6,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27]
    AvailableSPIChannels: {‘CE0’,’CE1’}
       AvailableI2CBuses: {'i2c-1'}
             I2CBusSpeed: 100000
        AvailabelWebCams: mmal service 16.1 (platform:bcm2835-v4l2)

Create an mpu6050 sensor object on the I2C bus 'i2c-1' on address '0x69'.

sensor = mpu6050(mypi,'Bus','i2c-1','I2CAddress','0x69');
sensor = 

  mpu6050 with properties:

                         I2CAddress: 105 ("0x69")
                                Bus: i2c-1 

Return one sample of acceleration data read from the MPU-6050 sensor on the X, Y, and Z axes.

[accelReadings,timestamp] = readAcceleration(sensor);
accelReadings =

  data

    4.9457   -1.1245   -0.6850


timestamp = 

  datetime

   22-Dec-2020 18:23:05.926

Since the timestamp output is optional, you can obtain only the acceleration data from the MPU-6050 sensor.

[accelReadings] = readAcceleration(sensor);
accelReadings =

  data

    4.9457   -1.1245   -0.6850

Input Arguments

collapse all

MPU-6050 sensor object connection to the Raspberry Pi hardware board, specified as a mpu6050 object.

Example: sensor = mpu6050(mypi) creates a connection to the MPU-6050 sensor on the Raspberry Pi object mypi.

Output Arguments

collapse all

Read the acceleration data from the MPU-6050 sensor on the X, Y, and Z axes.

Read the date and time at which MATLAB receives the acceleration sample value from the MPU-6050 sensor, specified as a datetime.

Extended Capabilities

Introduced in R2021a