Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependencies: mbed mbed-rtos MotionSensor EthernetInterface
Revision 9:bd0fb9d17803, committed 2016-04-30
- Comitter:
- Alexandre Seidy
- Date:
- Sat Apr 30 12:57:17 2016 -0300
- Parent:
- 2:fd19f7f45e83
- Child:
- 10:6735a8309f62
- Commit message:
- Added gyroscope sensitivity configuration
Changed in this revision
| SensorsLibrary/FXAS21002.cpp | Show annotated file Show diff for this revision Revisions of this file |
| SensorsLibrary/FXAS21002.h | Show annotated file Show diff for this revision Revisions of this file |
--- a/SensorsLibrary/FXAS21002.cpp Mon Apr 11 05:51:34 2016 +0000
+++ b/SensorsLibrary/FXAS21002.cpp Sat Apr 30 12:57:17 2016 -0300
@@ -17,44 +17,57 @@
*/
#include "FXAS21002.h"
- #include "mbed.h"
+#include "mbed.h"
FXAS21002::FXAS21002(PinName sda, PinName scl) : gyroi2c(sda,scl)
- {
-
- }
-
- void FXAS21002::gyro_config(void)
- {
- char d[2];
- d[0] = FXAS21002_CTRL_REG1; //Puts device in standby mode
- d[1] = 0x08;
- gyroi2c.write(FXAS21002_I2C_ADDRESS, d,2);
-
+{
- d[0] = FXAS21002_CTRL_REG0; //sets FS =+/- 2000 dps
- d[1] = 0x01;
- gyroi2c.write(FXAS21002_I2C_ADDRESS, d, 2);
-
-
- d[0] = FXAS21002_CTRL_REG1; //Puts device in active mode
- d[1] = 0x0A;
- gyroi2c.write(FXAS21002_I2C_ADDRESS, d,2);
-
- }
+}
+
+void FXAS21002::set_gyro(gyro_mode mode){ // Protected method
+ char d[2];
+ d[0] = FXAS21002_CTRL_REG1; //Puts device in standby mode
+ d[1] = 0x08;
+ gyroi2c.write(FXAS21002_I2C_ADDRESS, d,2);
+
+ d[0] = FXAS21002_CTRL_REG0; //Sets FSR and Sensitivity
+ d[1] = mode;
+ gyroi2c.write(FXAS21002_I2C_ADDRESS, d, 2);
+
+ d[0] = FXAS21002_CTRL_REG1; //Puts device in active mode
+ d[1] = 0x0A;
+ gyroi2c.write(FXAS21002_I2C_ADDRESS, d,2);
+}
+
+void FXAS21002::gyro_config(void)
+{
+ set_gyro(MODE_1); //Default implementation
+ sensitivity = 0.03125;
+}
- void FXAS21002::acquire_gyro_data_dps(float * g_data)
- {
+void FXAS21002::gyro_config(gyro_mode mode){
+ set_gyro(mode);
+ switch(mode)
+ {
+ case MODE_1: sensitivity = 0.0625; break;
+ case MODE_2: sensitivity = 0.03125; break;
+ case MODE_3: sensitivity = 0.015625; break;
+ case MODE_4: sensitivity = 0.078125; break;
+ }
+}
+
+void FXAS21002::acquire_gyro_data_dps(float * g_data)
+{
char data_bytes[7];
- gyroi2c.write(FXAS21002_I2C_ADDRESS,FXAS21002_STATUS,1,true); // Read the 6 data bytes - LSB and MSB for X, Y and Z Axes.
- gyroi2c.read(FXAS21002_I2C_ADDRESS,data_bytes,7);
+ gyroi2c.write(FXAS21002_I2C_ADDRESS,FXAS21002_STATUS,1,true); // Read the 6 data bytes - LSB and MSB for X, Y and Z Axes.
+ gyroi2c.read(FXAS21002_I2C_ADDRESS,data_bytes,7);
+
+ g_data[0] = (float)((int16_t)((data_bytes[1]*256) + (data_bytes[2]))) * sensitivity;
+ g_data[1] = (float)((int16_t)((data_bytes[3]*256) + (data_bytes[4]))) * sensitivity;
+ g_data[2] = (float)((int16_t)((data_bytes[5]*256) + (data_bytes[6]))) * sensitivity;
- g_data[0] = (float)((int16_t)((data_bytes[1]*256) + (data_bytes[2]))) * 0.03125;//0.0625;
- g_data[1] = (float)((int16_t)((data_bytes[3]*256) + (data_bytes[4]))) * 0.03125;//0.0625;
- g_data[2] = (float)((int16_t)((data_bytes[5]*256) + (data_bytes[6]))) * 0.03125;//0.0625;
-
- }
+}
--- a/SensorsLibrary/FXAS21002.h Mon Apr 11 05:51:34 2016 +0000
+++ b/SensorsLibrary/FXAS21002.h Sat Apr 30 12:57:17 2016 -0300
@@ -28,6 +28,21 @@
#define FXAS21002_CTRL_REG1 0x13
#define FXAS21002_WHO_AM_I_VALUE 0xD1
+/* Gyroscope mechanical modes
+* Mode Full-scale range [Deg/s] Sensitivity [(mDeg/s)/LSB]
+* 1 +- 2000 62.5
+* 2 +- 1000 31.25
+* 3 +- 500 15.625
+* 4 +- 250 7.8125
+*/
+enum gyro_mode
+{
+ MODE_1 = 0x00,
+ MODE_2 = 0x01,
+ MODE_3 = 0x02,
+ MODE_4 = 0x03
+}
+
class FXAS21002
{
public:
@@ -35,12 +50,13 @@
FXAS21002(PinName sda, PinName scl);
void gyro_config(void);
+ void gyro_config(gyro_mode mode);
void acquire_gyro_data_dps(float * du);
private:
I2C gyroi2c;
-
+ float sensivity;
};
#endif
\ No newline at end of file