MatrixMiniR4 1.1.4
Matrix Mini R4 Arduino Library API Documentation
Loading...
Searching...
No Matches
MiniR4MotionExt.cpp
Go to the documentation of this file.
1
7#include "MiniR4MotionExt.h"
8
10{
11 _pWire->begin();
12 i2cMUXSelect();
13 delay(50);
14 if (i2cReadData(Device_ID) == 0x44) {
15 i2cWriteData(Device_CONFIG, 0x02); // reset
16 delay(500);
17 i2cWriteData(Device_CONFIG, 0x01); // enable
18 return true;
19 } else {
20 return false;
21 }
22}
23
25{
26 i2cMUXSelect();
27 int data = (int16_t)(i2cReadData(ROLL_H) << 8 | i2cReadData(ROLL_L));
28 return data;
29}
30
32{
33 i2cMUXSelect();
34 int data = (int16_t)(i2cReadData(PITCH_H) << 8 | i2cReadData(PITCH_L));
35 return data;
36}
37
39{
40 i2cMUXSelect();
41 int data = (int16_t)(i2cReadData(YAW_H) << 8 | i2cReadData(YAW_L));
42 return data;
43}
44
46{
47 i2cMUXSelect();
48 int data = 0;
49 switch (axis) {
50 case x: data = (int16_t)(i2cReadData(GYRO_X_H) << 8 | i2cReadData(GYRO_X_L)); break;
51 case y: data = (int16_t)(i2cReadData(GYRO_Y_H) << 8 | i2cReadData(GYRO_Y_L)); break;
52 case z: data = (int16_t)(i2cReadData(GYRO_Z_H) << 8 | i2cReadData(GYRO_Z_L)); break;
53 default: break;
54 }
55 return data;
56}
57
59{
60 i2cMUXSelect();
61 int data = 0;
62 switch (axis) {
63 case x: data = (int16_t)(i2cReadData(ACCEL_X_H) << 8 | i2cReadData(ACCEL_X_L)); break;
64 case y: data = (int16_t)(i2cReadData(ACCEL_Y_H) << 8 | i2cReadData(ACCEL_Y_L)); break;
65 case z: data = (int16_t)(i2cReadData(ACCEL_Z_H) << 8 | i2cReadData(ACCEL_Z_L)); break;
66 default: break;
67 }
68 return data;
69}
70
71void MatrixMotion::i2cMUXSelect()
72{
73 if (_ch < 0) return; // no MUX
74 _pWire->beginTransmission(ADDR_PCA954X);
75 _pWire->write((1 << _ch));
76 _pWire->endTransmission(1);
77 delayMicroseconds(300);
78}
79
80uint8_t MatrixMotion::i2cReadData(MotionRegType reg)
81{
82 _pWire->beginTransmission(MatrixMotion_ADDR);
83 _pWire->write(reg);
84 _pWire->endTransmission(1);
85
86 delay(1);
87 _pWire->requestFrom(MatrixMotion_ADDR, 1);
88 delay(1);
89
90 return _pWire->read();
91}
92
93void MatrixMotion::i2cWriteData(MotionRegType reg, uint8_t data)
94{
95
96 _pWire->beginTransmission(MatrixMotion_ADDR);
97
98 _pWire->write(reg);
99 _pWire->write(data);
100
101 _pWire->endTransmission(1);
102}
Handling Matrix Motion Sensor functions.
#define ADDR_PCA954X
#define MatrixMotion_ADDR
@ z
@ x
@ y
enum __AxisType AxisType
bool begin()
Initializes the MatrixMotion sensor.
int getAccel(AxisType axis)
Gets the accelerometer value for a specified axis.
int getGyro(AxisType axis)
Gets the gyro value for a specified axis.
int getRoll()
Gets the roll angle from the motion sensor.
int getYaw()
Gets the yaw angle from the motion sensor.
int getPitch()
Gets the pitch angle from the motion sensor.
TwoWire * _pWire