Here is the library in case anyone wants to try it
MeAccelGyro.h
/**
* \par Copyright (C), 2012-2016, MakeBlock
* \class MeAccelGyro
* \brief Driver for Me 3-Axis Accelerometer and Gyro module.
* @file MeAccelGyro.h
* @author Dr. Keith "Kilo" Watt
* @version V1.0.0
* @date 2022/04/30
* @brief Header for MeAccelGyro.cpp module.
*
* \par Copyright
* This software is Copyright (C), 2012-2016, MakeBlock. Use is subject to license \n
* conditions. The main licensing options available are GPL V2 or Commercial: \n
*
* \par Open Source Licensing GPL V2
* This is the appropriate option if you want to share the source code of your \n
* application with everyone you distribute it to, and you also want to give them \n
* the right to share who uses it. If you wish to use this software under Open \n
* Source Licensing, you must contribute all your source code to the open source \n
* community in accordance with the GPL Version 2 when your application is \n
* distributed. See http://www.gnu.org/copyleft/gpl.html
*
* \par Description
* This file is a driver for Me 3-Axis Accelerometer module, It supports 3-Axis Accelerometer V1.0 device provided
* by MakeBlock. This driver is an extension of MeGyro to expose the accelerometer data.
*
* \par Method List:
*
* ** NOTE: The following methods should be exposed to user with a block for each:
* Reporter Blocks:
* double MeAccelGyro::getAngle(uint8_t index)
* double MeAccelGyro::getAccel(uint8_t index)
* double MeAccelGyro::getSIAccel(uint8_t index)
* double MeAccelGyro::getTemp(uint8_t index)
*
* Command Blocks:
* void MeAccelGyro::setDLPFfreq(uint8_t index)
* void MeAccelGyro::setGyroSensitivity(uint8_t index)
* void MeAccelGyro::setAccelSensitivity(uint8_t index)
*
*
* 1. void MeAccelGyro::setpin(uint8_t AD0, uint8_t INT)
* 2. void MeAccelGyro::begin(void)
* 3. void MeAccelGyro::update(void)
* 4. double MeAccelGyro::getAngle(uint8_t index)
* 5. double MeAccelGyro::getAccel(uint8_t index)
* 6. double MeAccelGyro::getSIAccel(uint8_t index)
* 7. double MeAccelGyro::getTemp(uint8_t index)
* 8. void MeAccelGyro::setDLPFfreq(uint8_t index)
* 9. void MeAccelGyro::setGyroSensitivity(uint8_t index)
* 10. void MeAccelGyro::setAccelSensitivity(uint8_t index)
* 11. void MeAccelGyro::fast_update(void)
* 12. uint8_t MeAccelGyro::getDevAddr(void)
* 13. double MeAccelGyro::getRawTemp(void)
* 14. double MeAccelGyro::getCTemp(void)
* 15. double MeAccelGyro::getKTemp(void)
* 16. double MeAccelGyro::getFTemp(void)
* 17. double MeAccelGyro::getAngleX(void)
* 18. double MeAccelGyro::getAngleY(void)
* 19. double MeAccelGyro::getAngleZ(void)
* 20. double MeAccelGyro::getGyroX(void)
* 21. double MeAccelGyro::getGyroY(void)
* 22. double MeAccelGyro::getAccelX(void)
* 23. double MeAccelGyro::getAccelY(void)
* 24. double MeAccelGyro::getAccelZ(void)
* 25. double MeAccelGyro::getSIAccelX(void)
* 26. double MeAccelGyro::getSIAccelY(void)
* 27. double MeAccelGyro::getSIAccelZ(void)
* 28. double MeAccelGyro::getRawAccelX(void)
* 29. double MeAccelGyro::getRawAccelY(void)
* 30. double MeAccelGyro::getRawAccelZ(void)
* 31. void MeAccelGyro::setDLPFfreq260(void)
* 32. void MeAccelGyro::setDLPFfreq184(void)
* 33. void MeAccelGyro::setDLPFfreq94(void)
* 34. void MeAccelGyro::setDLPFfreq44(void)
* 35. void MeAccelGyro::setDLPFfreq21(void)
* 36. void MeAccelGyro::setDLPFfreq10(void)
* 37. void MeAccelGyro::setDLPFfreq05(void)
* 38. void MeAccelGyro::setGyroSensitivity250(void)
* 39. void MeAccelGyro::setGyroSensitivity500(void)
* 40. void MeAccelGyro::setGyroSensitivity1000(void)
* 41. void MeAccelGyro::setGyroSensitivity2000(void)
* 42. void MeAccelGyro::setAccelSensitivity2G(void)
* 43. void MeAccelGyro::setAccelSensitivity4G(void)
* 44. void MeAccelGyro::setAccelSensitivity8G(void)
* 45. void MeAccelGyro::setAccelSensitivity16G(void)
*
* \par History:
* <pre>
* `<Author>` `<Time>` `<Version>` `<Descr>`
* Kilo Watt 2022/04/30 1.0.0 Initial extension of MeGyro to expose acceleration and temperature data
* </pre>
*
*/
/* Define to prevent recursive inclusion -------------------------------------*/
#ifndef MeAccelGyro_H
#define MeAccelGyro_H
/* Includes ------------------------------------------------------------------*/
#include <stdint.h>
#include <stdbool.h>
#include <Arduino.h>
#include "MeConfig.h"
#ifdef ME_PORT_DEFINED
#include "MePort.h"
#endif // ME_PORT_DEFINED
/* Exported macro ------------------------------------------------------------*/
#define I2C_ERROR (-1)
#define GYRO_DEFAULT_ADDRESS (0x68)
/**
* Class: MeAccelGyro
* \par Description
* Declaration of Class MeAccelGyro
*/
#ifndef ME_PORT_DEFINED
class MeAccelGyro
#else // !ME_PORT_DEFINED
class MeAccelGyro : public MePort
#endif // !ME_PORT_DEFINED
{
public:
#ifdef ME_PORT_DEFINED
/**
* Alternate Constructor which can call your own function to map the MeCompass to arduino port,
* no pins are used or initialized here
*/
MeAccelGyro(void);
/**
* Alternate Constructor which can call your own function to map the MeCompass to arduino port,
* no pins are used or initialized here, but PWM frequency set to 976 Hz
* \param[in]
* port - RJ25 port from PORT_1 to M2
*/
MeAccelGyro(uint8_t port);
/**
* Alternate Constructor which can call your own function to map the MeCompass to arduino port
* and change the i2c device address
* no pins are used or initialized here, but PWM frequency set to 976 Hz
* \param[in]
* port - RJ25 port from PORT_1 to M2
* \param[in]
* address - the i2c address you want to set
*/
MeAccelGyro(uint8_t port, uint8_t address);
#else
/**
* Alternate Constructor which can call your own function to map the _AD0 and _INT to arduino port,
* no pins are used or initialized here
* \param[in]
* _AD0 - arduino gpio number
* \param[in]
* _INT - arduino gpio number
*/
MeAccelGyro(uint8_t AD0, uint8_t INT);
/**
* Alternate Constructor which can call your own function to map the _AD0 and _INT to arduino port
* and change the i2c device address, no pins are used or initialized here
* \param[in]
* _AD0 - arduino gpio number
* \param[in]
* _INT - arduino gpio number
* \param[in]
* address - the i2c address you want to set
*/
MeAccelGyro(uint8_t AD0, uint8_t INT, uint8_t address);
#endif // ME_PORT_DEFINED
/**
* \par Function
* setpin
* \par Description
* Set the PIN of the button module.
* \param[in]
* AD0 - pin mapping for arduino
* \param[in]
* INT - pin mapping for arduino
* \par Output
* None
* \return
* None.
* \par Others
* Set global variable _AD0, _INT, s1 and s2
*/
void setpin(uint8_t AD0, uint8_t INT);
//***********************************************************************
// Setup Functions
/**
* \par Function
* begin
* \par Description
* Initialize the MeAccelGyro.
* \param[in]
* None
* \par Output
* None
* \return
* None
* \par Others
* You can check the MPU6050 datasheet for the registor address.
*/
void begin();
//***********************************************************************
// _Loop Functions
/**
* \par Function
* update
* \par Description
* Update some calculated angle values to the variable.
* \param[in]
* None
* \par Output
* None
* \return
* None
* \par Others
* The angle values are calculated by complementary filter.
* The time constant of filter is set to 0.5 second, but period dt is not a constant,
* so the filter coefficient will be calculated dynamically.
*/
void update(void);
/**
* \par Function
* fast_update
* \par Description
* Fast update some calculated angle values to the variable.
* \param[in]
* None
* \par Output
* None
* \return
* None
* \par Others
* The angle values are calculated by complementary filter.
* The time constant of filter is set to 0.5 second, but period dt is not a constant,
* so the filter coefficient will be calculated dynamically.
*/
void fast_update(void);
/**
* \par Function
* getDevAddr
* \par Description
* Get the device address of Gyro.
* \param[in]
* None
* \par Output
* None
* \return
* The device address of Gyro
* \par Others
* None
*/
uint8_t getDevAddr(void);
//************************************************************
// User-facing functions for blocks
//************************************************************
// Reporter Blocks
/**
* \par Function
* getAngle
* \par Description
* Get the angle value of setting axis.
* \param[in]
* index - Axis settings(1:X-axis, 2:Y-axis, 3:Z-axis)
* \par Output
* None
* \return
* The angle value of setting axis
* \par Others
* Z-axis angle value is integral of Z-axis angular velocity.
*/
double getAngle(uint8_t index);
/**
* \par Function
* getAccel
* \par Description
* Get the acceleration value in g's of setting axis.
* \param[in]
* index - Axis settings(1:X-axis, 2:Y-axis, 3:Z-axis)
* \par Output
* None
* \return
* The acceleration value in g's of setting axis
* \par Others
* None
*/
double getAccel(uint8_t index);
/**
* \par Function
* getSIAccel
* \par Description
* Get the acceleration value in SI units (m/s^2) of setting axis.
* \param[in]
* index - Axis settings(1:X-axis, 2:Y-axis, 3:Z-axis)
* \par Output
* None
* \return
* The acceleration value in SI units (m/s^2) of setting axis
* \par Others
* None
*/
double getSIAccel(uint8_t index);
/**
* \par Function
* getTemp
* \par Description
* Gets the ambient temperature of the MPU6050 chip in various units
* \param[in]
* index - temperature units(1:Celsius, 2:Fahrenheit, 3:Kelvin)
* \par Output
* None
* \return
* The chip temperature in the selected units
* \par Others
* Note that the dropdown in the command block should have Celsius,1; Fahrenheit,2; Kelvin,3
*/
double getTemp(uint8_t index);
//************************************************************
// Command Blocks
/**
* \par Function
* setDLPFfreq
* \par Description
* Sets the frequency of the digital low-pass filter
* \param[in]
* index - Freq settings in Hz(1:260, 2:184, 3:94, 4:44, 5:21, 6:10, 7:5)
* \par Output
* None
* \return
* None
* \par Others
* Note that the dropdown in the command block should have 260Hz,1; 184Hz,2; 94Hz,3; 44Hz,4; 21Hz,5; 10Hz,6; 5Hz,7
*/
void setDLPFfreq(uint8_t index);
/**
* \par Function
* setGyroSensitivity
* \par Description
* Sets the sensitivity of the gyro in deg/sec
* \param[in]
* index - Sensitivity settings in deg/sec(1:250, 2:500, 3:1000, 4:2000)
* \par Output
* None
* \return
* None
* \par Others
* Note that the dropdown in the command block should have 250 deg/s,1; 500 deg/s,2; 1000 deg/s,3; 2000 deg/s,4
*/
void setGyroSensitivity(uint8_t index);
/**
* \par Function
* setAccelSensitivity
* \par Description
* Sets the full scale sensitivity of the accelerometer in g's
* \param[in]
* index - Sensitivity settings in g's(1:2, 2:4, 3:8, 4:16)
* \par Output
* None
* \return
* None
* \par Others
* Note that the dropdown in the command block should have 2g,1; 4g,2; 8g,3; 16,4
*/
void setAccelSensitivity(uint8_t index);
// ***********************************************************************
// * Functions used by the library (could be exposed to user if desired)
/**
* \par Function
* getRawTemp
* \par Description
* Get the raw (Least Significant Bit) temperature of the sensor
* \param[in]
* None
* \par Output
* None
* \return
* The LSB acceleration value of temperature
* \par Others
* None
*/
double getRawTemp(void) ;
/**
* \par Function
* getCTemp
* \par Description
* Get the temperature of the sensor in degrees C
* \param[in]
* None
* \par Output
* None
* \return
* The value of temperature in degrees C
* \par Others
* None
*/
double getCTemp(void) ;
/**
* \par Function
* getKTemp
* \par Description
* Get the temperature of the sensor in degrees K
* \param[in]
* None
* \par Output
* None
* \return
* The value of temperature in degrees K
* \par Others
* None
*/
double getKTemp(void) ;
/**
* \par Function
* getFTemp
* \par Description
* Get the temperature of the sensor in degrees F
* \param[in]
* None
* \par Output
* None
* \return
* The value of temperature in degrees F
* \par Others
* None
*/
double getFTemp(void) ;
/**
* \par Function
* getAccelX
* \par Description
* Get the acceleration value of X-axis converted to g's.
* \param[in]
* None
* \par Output
* None
* \return
* The LSB acceleration value of X-axis
* \par Others
* X-axis angle value is calculated by complementary filter.
* Note that the LSB range is -32768 to +32767 for the default 2g sensitivity
* This implies that 1g = 16384 LSB
*/
double getAccelX(void) ;
/**
* \par Function
* getAccelY
* \par Description
* Get the acceleration value of Y-axis in g's.
* \param[in]
* None
* \par Output
* None
* \return
* The LSB acceleration value of X-axis
* \par Others
* Y-axis angle value is calculated by complementary filter.
* Note that the LSB range is -32768 to +32767 for the default 2g sensitivity
* This implies that 1g = 16384 LSB
*/
double getAccelY(void) ;
/**
* \par Function
* getAccelZ
* \par Description
* Get the acceleration value of Z-axis in g's.
* \param[in]
* None
* \par Output
* None
* \return
* The LSB acceleration value of Z-axis
* \par Others
* Z-axis angle value is calculated by complementary filter.
* Note that the LSB range is -32768 to +32767 for the default 2g sensitivity
* This implies that 1g = 16384 LSB
*/
double getAccelZ(void) ;
/**
* \par Function
* getSIAccelX
* \par Description
* Get the acceleration value of X-axis converted to SI units (m/s^2).
* \param[in]
* None
* \par Output
* None
* \return
* The SI acceleration value of X-axis
* \par Others
* X-axis angle value is calculated by complementary filter.
* Note that the LSB range is -32768 to +32767 for the default 2g sensitivity
* This implies that 9.81m/s^2 = 16384 LSB => 1 m/s^2 = 1670.1
*/
double getSIAccelX(void) ;
/**
* \par Function
* getAccelY
* \par Description
* Get the acceleration value of Y-axis in SI units (m/s^2).
* \param[in]
* None
* \par Output
* None
* \return
* The SI acceleration value of X-axis
* \par Others
* Y-axis angle value is calculated by complementary filter.
* Note that the LSB range is -32768 to +32767 for the default 2g sensitivity
* This implies that 9.81 m/s^2 = 16384 LSB => 1 m/s^2 = 1670.1
*/
double getSIAccelY(void) ;
/**
* \par Function
* getAccelZ
* \par Description
* Get the acceleration value of Z-axis in SI units (m/s^2).
* \param[in]
* None
* \par Output
* None
* \return
* The SI acceleration value of Z-axis
* \par Others
* Z-axis angle value is calculated by complementary filter.
* Note that the LSB range is -32768 to +32767 for the default 2g sensitivity
* This implies that 9.81 m/s^2 = 16384 LSB => 1 m/s^2 = 1670.1
*/
double getSIAccelZ(void) ;
/**
* \par Function
* getRawAccelX
* \par Description
* Get the raw (Least Significant Bit) acceleration value of X-axis.
* \param[in]
* None
* \par Output
* None
* \return
* The LSB acceleration value of X-axis
* \par Others
* X-axis angle value is calculated by complementary filter.
*/
double getRawAccelX(void) ;
/**
* \par Function
* getRawAccelY
* \par Description
* Get the raw (Least Significant Bit) acceleration value of Y-axis.
* \param[in]
* None
* \par Output
* None
* \return
* The LSB acceleration value of X-axis
* \par Others
* Y-axis angle value is calculated by complementary filter.
*/
double getRawAccelY(void) ;
/**
* \par Function
* getRawAccelZ
* \par Description
* Get the raw (Least Significant Bit) acceleration value of Z-axis.
* \param[in]
* None
* \par Output
* None
* \return
* The LSB acceleration value of Z-axis
* \par Others
* Z-axis angle value is calculated by complementary filter.
*/
double getRawAccelZ(void) ;
/**
* \par Function
* getAngleX
* \par Description
* Get the angle value of X-axis.
* \param[in]
* None
* \par Output
* None
* \return
* The angle value of X-axis
* \par Others
* X-axis angle value is calculated by complementary filter.
*/
double getAngleX(void) ;
/**
* \par Function
* getAngleY
* \par Description
* Get the angle value of Y-axis.
* \param[in]
* None
* \par Output
* None
* \return
* The angle value of Y-axis
* \par Others
* Y-axis angle value is calculated by complementary filter.
*/
double getAngleY(void) ;
/**
* \par Function
* getAngleZ
* \par Description
* Get the angle value of Z-axis.
* \param[in]
* None
* \par Output
* None
* \return
* The angle value of Z-axis
* \par Others
* Z-axis angle value is integral of Z-axis angular velocity.
*/
double getAngleZ(void) ;
/**
* \par Function
* getGyroX
* \par Description
* Get the data of gyroXrate.
* \param[in]
* None
* \par Output
* None
* \return
* The data of gyroXrate
* \par Others
* None
*/
double getGyroX(void) ;
/**
* \par Function
* getGyroY
* \par Description
* Get the data of gyroYrate.
* \param[in]
* None
* \par Output
* None
* \return
* The data of gyroYrate
* \par Others
* None
*/
double getGyroY(void) ;
/**
* \par Function
* setDLPFfreq260
* \par Description
* Sets the Digital Low-Pass Filter to 260Hz
* \param[in]
* None
* \par Output
* None
* \return
* None.
* \par Others
* DLPF Frequencies = 0x00=260Hz, 0x01=184Hz, 0x02=94Hz, 0x03=44Hz, 0x04=21Hz, 0x05=10Hz, 0x06=5Hz,,check data sheet p.13
*/
void setDLPFfreq260(void) ;
/**
* \par Function
* setDLPFfreq184
* \par Description
* Sets the Digital Low-Pass Filter to 184Hz
* \param[in]
* None
* \par Output
* None
* \return
* None.
* \par Others
* DLPF Frequencies = 0x00=260Hz, 0x01=184Hz, 0x02=94Hz, 0x03=44Hz, 0x04=21Hz, 0x05=10Hz, 0x06=5Hz,,check data sheet p.13
*/
void setDLPFfreq184(void) ;
/**
* \par Function
* setDLPFfreq94
* \par Description
* Sets the Digital Low-Pass Filter to 184Hz
* \param[in]
* None
* \par Output
* None
* \return
* None.
* \par Others
* DLPF Frequencies = 0x00=260Hz, 0x01=184Hz, 0x02=94Hz, 0x03=44Hz, 0x04=21Hz, 0x05=10Hz, 0x06=5Hz,,check data sheet p.13
*/
void setDLPFfreq94(void) ;
/**
* \par Function
* setDLPFfreq44
* \par Description
* Sets the Digital Low-Pass Filter to 44Hz
* \param[in]
* None
* \par Output
* None
* \return
* None.
* \par Others
* DLPF Frequencies = 0x00=260Hz, 0x01=184Hz, 0x02=94Hz, 0x03=44Hz, 0x04=21Hz, 0x05=10Hz, 0x06=5Hz,,check data sheet p.13
*/
void setDLPFfreq44(void) ;
/**
* \par Function
* setDLPFfreq21
* \par Description
* Sets the Digital Low-Pass Filter to 21Hz
* \param[in]
* None
* \par Output
* None
* \return
* None.
* \par Others
* DLPF Frequencies = 0x00=260Hz, 0x01=184Hz, 0x02=94Hz, 0x03=44Hz, 0x04=21Hz, 0x05=10Hz, 0x06=5Hz,,check data sheet p.13
*/
void setDLPFfreq21(void) ;
/**
* \par Function
* setDLPFfreq10
* \par Description
* Sets the Digital Low-Pass Filter to 10Hz
* \param[in]
* None
* \par Output
* None
* \return
* None.
* \par Others
* DLPF Frequencies = 0x00=260Hz, 0x01=184Hz, 0x02=94Hz, 0x03=44Hz, 0x04=21Hz, 0x05=10Hz, 0x06=5Hz,,check data sheet p.13
*/
void setDLPFfreq10(void) ;
/**
* \par Function
* setDLPFfreq05
* \par Description
* Sets the Digital Low-Pass Filter to 5Hz
* \param[in]
* None
* \par Output
* None
* \return
* None.
* \par Others
* DLPF Frequencies = 0x00=260Hz, 0x01=184Hz, 0x02=94Hz, 0x03=44Hz, 0x04=21Hz, 0x05=10Hz, 0x06=5Hz,,check data sheet p.13
*/
void setDLPFfreq05(void) ;
/**
* \par Function
* setGyroSensitivity250
* \par Description
* Sets the LSB sensitivity of the gyro to 250 deg/s
* \param[in]
* None
* \par Output
* None
* \return
* None.
* \par Others
* LSB Sensitivity for 250 deg/s = 131.0; 500 deg/s = 65.5; 1000 deg/s = 32.8; 2000 deg/s = 16.4, check data sheet p.14
*/
void setGyroSensitivity250(void) ;
/**
* \par Function
* setGyroSensitivityy500
* \par Description
* Sets the LSB sensitivity of the gyro to 500 deg/s
* \param[in]
* None
* \par Output
* None
* \return
* None.
* \par Others
* LSB Sensitivity for 250 deg/s = 131.0; 500 deg/s = 65.5; 1000 deg/s = 32.8; 2000 deg/s = 16.4, check data sheet p.14
*/
void setGyroSensitivity500(void) ;
/**
* \par Function
* setGyroSensitivity1000
* \par Description
* Sets the LSB sensitivity of the gyro to 1000 deg/s
* \param[in]
* None
* \par Output
* None
* \return
* None.
* \par Others
* LSB Sensitivity for 250 deg/s = 131.0; 500 deg/s = 65.5; 1000 deg/s = 32.8; 2000 deg/s = 16.4, check data sheet p.14
*/
void setGyroSensitivity1000(void) ;
/**
* \par Function
* setGyroSensitivity2000
* \par Description
* Sets the LSB sensitivity of the gyro to 2000 deg/s
* \param[in]
* None
* \par Output
* None
* \return
* None.
* \par Others
* LSB Sensitivity for 250 deg/s = 131.0; 500 deg/s = 65.5; 1000 deg/s = 32.8; 2000 deg/s = 16.4, check data sheet p.14
*/
void setGyroSensitivity2000(void) ;
/**
* \par Function
* setAccelSensitivity2G
* \par Description
* Sets the LSB sensitivity of the accelerometer to 2g (default at power-up)
* \param[in]
* None
* \par Output
* None
* \return
* None.
* \par Others
* LSB Sensitivity for 2g = 16384.0; 4g = 8192.0; 8g = 4096.0; 16g = 2048.0, check data sheet p.15,29
*/
void setAccelSensitivity2G(void) ;
/**
* \par Function
* setAccelSensitivity4G
* \par Description
* Sets the LSB sensitivity of the accelerometer to 4g
* \param[in]
* None
* \par Output
* None
* \return
* None.
* \par Others
* LSB Sensitivity for 2g = 16384.0; 4g = 8192.0; 8g = 4096.0; 16g = 2048.0, check data sheet p.15,29
*/
void setAccelSensitivity4G(void) ;
/**
* \par Function
* setAccelSensitivity8G
* \par Description
* Sets the LSB sensitivity of the accelerometer to 8g
* \param[in]
* None
* \par Output
* None
* \return
* None.
* \par Others
* LSB Sensitivity for 2g = 16384.0; 4g = 8192.0; 8g = 4096.0; 16g = 2048.0, check data sheet p.15,29
*/
void setAccelSensitivity8G(void) ;
/**
* \par Function
* setAccelSensitivity16G
* \par Description
* Sets the LSB sensitivity of the accelerometer to 16g
* \param[in]
* None
* \par Output
* None
* \return
* None.
* \par Others
* LSB Sensitivity for 2g = 16384.0; 4g = 8192.0; 8g = 4096.0; 16g = 2048.0, check data sheet p.15,29
*/
void setAccelSensitivity16G(void);
// Full Scale constants for gyroSensitivity
#define DEGS_250 131.0;
#define DEGS_500 65.5;
#define DEGS_1000 32.8;
#define DEGS_2000 16.4;
// Full Scale constants for accelSensitivity
#define ACCEL_2G 16384.0;
#define ACCEL_4G 8192.0;
#define ACCEL_8G 4096.0;
#define ACCEL_16G 2048.0;
private:
volatile uint8_t _AD0;
volatile uint8_t _INT;
mutable double gyroSensitivity; /* LSB Sensitivity for 250 deg/s = 131.0; 500 deg/s = 65.5; 1000 deg/s = 32.8; 2000 deg/s = 16.4, check data sheet p.14*/
double gx, gy, gz;
double gyrX, gyrY, gyrZ;
int16_t accX, accY, accZ;
double gyrXoffs, gyrYoffs, gyrZoffs;
uint8_t i2cData[14]; // Used to read IMU data
uint8_t i2cData2[2]; // Used to read temperature data
uint8_t Device_Address;
int16_t rawTemp; // For on-board temperature sensor
mutable double accelSensitivity; // LSB Sensitivity for 2g = 16384.0; 4g = 8192.0; 8g = 4096.0; 16g = 2048.0, check data sheet p.29
/**
* \par Function
* deviceCalibration
* \par Description
* Calibration function for the MeAccelGyro.
* \param[in]
* None
* \par Output
* None
* \return
* None.
* \par Others
* The calibration function will be called in initial process, please keep the
* device in a rest status at that time.
*/
void deviceCalibration(void);
/**
* \par Function
* writeReg
* \par Description
* Write the registor of i2c device.
* \param[in]
* reg - the address of registor.
* \param[in]
* data - the data that will be written to the registor.
* \par Output
* None
* \return
* Return the error code.
* the definition of the value of variable return_value:
* 0:success
* 1:BUFFER_LENGTH is shorter than size
* 2:address send, nack received
* 3:data send, nack received
* 4:other twi error
* refer to the arduino official library twi.c
* \par Others
* To set the registor for initializing.
*/
int8_t writeReg(int16_t reg, uint8_t data);
/**
* \par Function
* readData
* \par Description
* Write the data to i2c device.
* \param[in]
* start - the address which will write the data to.
* \param[in]
* pData - the head address of data array.
* \param[in]
* size - set the number of data will be written to the devide.
* \par Output
* None
* \return
* Return the error code.
* the definition of the value of variable return_value:
* 0:success
* 1:BUFFER_LENGTH is shorter than size
* 2:address send, nack received
* 3:data send, nack received
* 4:other twi error
* refer to the arduino official library twi.c
* \par Others
* Calling the official i2c library to read data.
*/
int8_t readData(uint8_t start, uint8_t *buffer, uint8_t size);
/**
* \par Function
* writeData
* \par Description
* Write the data to i2c device.
* \param[in]
* start - the address which will write the data to.
* \param[in]
* pData - the head address of data array.
* \param[in]
* size - set the number of data will be written to the devide.
* \par Output
* None
* \return
* Return the error code.
* the definition of the value of variable return_value:
* 0:success
* 1:BUFFER_LENGTH is shorter than size
* 2:address send, nack received
* 3:data send, nack received
* 4:other twi error
* refer to the arduino official library twi.c
* \par Others
* Calling the official i2c library to write data.
*/
//int8_t writeData(uint8_t start, const uint8_t *pData, uint8_t size);
int8_t writeData(uint8_t start, uint8_t* pData, uint8_t size);
};
#endif // MeAccelGyro_H