Hi!
I'm trying to read the data from a MPU-6050 sensor (I2C). I have managed to get the raw data, but I would also like to create a function which formats the data to "correct" units, g's and deg/s. So I figured I could create another function which calls the "raw data function" and then it formats the read, raw data.
I'm very new to pointers so that's why I can't get this to work, I guess...
Anyway, I've created a library called IMUlib, and the code looks like this:
Main sketch
#include <Wire.h>
#include "IMUlib.h"
IMUlib IMU;
const uint8_t MPU6050 = 0x68; // I2C address to Acc/gyro
int16_t aX, aY, aZ, gX, gY, gZ;
void setup(){
// Initialize serial monitor at 9600 baud
Serial.begin(9600);
// Initialize Wire object
Wire.begin();
// Wake the IMU sensor and set the sensor range
IMU.initializeIMU(MPU6050_ACCEL_FS_2, MPU6050_GYRO_FS_250);
// Test IMU connection
IMU.testConnection();
}
void loop(){
IMU.readIMUForm(&aX, &aY, &aZ, &gX, &gY, &gZ);
}
IMUlib.cpp (relevant functions):
void IMUlib::readIMU(int16_t *aX, int16_t *aY, int16_t *aZ, int16_t *gX, int16_t *gY, int16_t *gZ){
I2Cdev::readBytes(devAddress, MPU6050_RA_ACCEL_XOUT_H, 14, data);
*aX = (((int16_t)data[0]) << 8) | data[1];
*aY = (((int16_t)data[2]) << 8) | data[3];
*aZ = (((int16_t)data[4]) << 8) | data[5];
// data[6:7] contains temperature
*gX = (((int16_t)data[8]) << 8) | data[9];
*gY = (((int16_t)data[10]) << 8) | data[11];
*gZ = (((int16_t)data[12]) << 8) | data[13];
}
// Function which errors...
void IMUlib::readIMUForm(int16_t *aX, int16_t *aY, int16_t *aZ, int16_t *gX, int16_t *gY, int16_t *gZ){
readIMU(&aX, &aY, &aZ, &gX, &gY, &gZ);
*aX = *aX/16384;
}
Error:
IMUlib.cpp: In member function 'void IMUlib::readIMUForm(int16_t*, int16_t*, int16_t*, int16_t*, int16_t*, int16_t*)':
IMUlib.cpp:48: error: invalid conversion from 'int' to 'int16_t*'
IMUlib.cpp:48: error: initializing argument 1 of 'void IMUlib::readIMU(int16_t*, int16_t*, int16_t*, int16_t*, int16_t*, int16_t*)'
IMUlib.cpp:48: error: invalid conversion from 'int' to 'int16_t*'
IMUlib.cpp:48: error: initializing argument 2 of 'void IMUlib::readIMU(int16_t*, int16_t*, int16_t*, int16_t*, int16_t*, int16_t*)'
IMUlib.cpp:48: error: invalid conversion from 'int' to 'int16_t*'
IMUlib.cpp:48: error: initializing argument 3 of 'void IMUlib::readIMU(int16_t*, int16_t*, int16_t*, int16_t*, int16_t*, int16_t*)'
IMUlib.cpp:48: error: invalid conversion from 'int' to 'int16_t*'
IMUlib.cpp:48: error: initializing argument 4 of 'void IMUlib::readIMU(int16_t*, int16_t*, int16_t*, int16_t*, int16_t*, int16_t*)'
IMUlib.cpp:48: error: invalid conversion from 'int' to 'int16_t*'
IMUlib.cpp:48: error: initializing argument 5 of 'void IMUlib::readIMU(int16_t*, int16_t*, int16_t*, int16_t*, int16_t*, int16_t*)'
IMUlib.cpp:48: error: invalid conversion from 'int' to 'int16_t*'
IMUlib.cpp:48: error: initializing argument 6 of 'void IMUlib::readIMU(int16_t*, int16_t*, int16_t*, int16_t*, int16_t*, int16_t*)'
As you might see I want to be able to call two different functions depending on if I want the raw data or the formatted. How should I write this ?