Skip to content

Commit 8597007

Browse files
author
Jim Lindblom
committed
Squashed 'Libraries/Particle/' content from commit ecfc112
git-subtree-dir: Libraries/Particle git-subtree-split: ecfc112d754a973d1518fb4fa33e839a53bcadf1
0 parents  commit 8597007

File tree

10 files changed

+2586
-0
lines changed

10 files changed

+2586
-0
lines changed

LICENSE

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
The MIT License (MIT)
2+
3+
Copyright (c) 2015 SparkFun Electronics
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.
22+

README.md

Lines changed: 139 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,139 @@
1+
## SparkFun LSM9DS1 Particle Library
2+
3+
Firmware library SparkFun's Photon IMU Shield and the LSM9DS1 Breakout.
4+
5+
About
6+
-------------------
7+
8+
This is a firmware library for [SparkFun's Photon IMU Shield](https://www.sparkfun.com/products/13629).
9+
10+
[![Photon IMU Shield](https://cdn.sparkfun.com//assets/parts/1/1/0/1/6/13629-01a.jpg)](https://www.sparkfun.com/products/13629).
11+
12+
The Photon IMU Shield connects the Photon WiFi development board up to an [ST LSM9DS1](http://www.st.com/web/catalog/sense_power/FM89/SC1448/PF259998) 9DOF IMU - providing it access to an accelerometer, gyroscope, and magnetometer.
13+
14+
Repository Contents
15+
-------------------
16+
17+
* **/doc** - Additional documentation for the user. These files are ignored by the IDE.
18+
* **/firmware** - Source files for the library (.cpp, .h).
19+
* **/firmware/examples** - Example sketches for the library (.cpp). Run these from the Particle IDE.
20+
* **spark.json** - General library properties for the Particel library manager.
21+
22+
Example Usage
23+
-------------------
24+
25+
#### Initializing the Library
26+
27+
Include the library, declare an IMU object, and set it up with these snippets of code:
28+
29+
#include "SparkFunLSM9DS1/SparkFunLSM9DS1.h"
30+
31+
// Use the LSM9DS1 class to create an object. [imu] can be
32+
// named anything, we'll refer to that throught the sketch.
33+
LSM9DS1 imu;
34+
35+
// SDO_XM and SDO_G are both pulled high, so our addresses are:
36+
#define LSM9DS1_M 0x1E // Would be 0x1C if SDO_M is LOW
37+
#define LSM9DS1_AG 0x6B // Would be 0x6A if SDO_AG is LOW
38+
39+
void setup()
40+
{
41+
Serial.begin(115200);
42+
43+
// Before initializing the IMU, there are a few settings
44+
// we may need to adjust. Use the settings struct to set
45+
// the device's communication mode and addresses:
46+
imu.settings.device.commInterface = IMU_MODE_I2C;
47+
imu.settings.device.mAddress = LSM9DS1_M;
48+
imu.settings.device.agAddress = LSM9DS1_AG;
49+
// The above lines will only take effect AFTER calling
50+
// imu.begin(), which verifies communication with the IMU
51+
// and turns it on.
52+
if (!imu.begin())
53+
{
54+
Serial.println("Failed to communicate with LSM9DS1.");
55+
Serial.println("Double-check wiring.");
56+
Serial.println("Default settings in this sketch will " \
57+
"work for an out of the box LSM9DS1 " \
58+
"Breakout, but may need to be modified " \
59+
"if the board jumpers are.");
60+
while (1)
61+
;
62+
}
63+
}
64+
65+
#### Reading Sensor Data
66+
67+
To get data out of the IMU, call `imu.readAccel()`, `imu.readGyro()`, and `imu.readMag()`. Those functions will update the objects member variables: `imu.ax`, `imu.ay`, `imu.az`, `imu.gx`, `imu.gy`, `imu.gz`, `imu.mx`, `imu.my`, and`imu.mz`. Here, some example functions can probably make it more clear:
68+
69+
void printAccel()
70+
{
71+
// To read from the accelerometer, you must first call the
72+
// readAccel() function. When this exits, it'll update the
73+
// ax, ay, and az variables with the most current data.
74+
imu.readAccel();
75+
76+
// Now we can use the ax, ay, and az variables as we please.
77+
Serial.print("A: ");
78+
Serial.print(imu.ax);
79+
Serial.print(", ");
80+
Serial.print(imu.ay);
81+
Serial.print(", ");
82+
Serial.println(imu.az);
83+
}
84+
85+
void printGyro()
86+
{
87+
// To read from the gyroscope, you must first call the
88+
// readGyro() function. When this exits, it'll update the
89+
// gx, gy, and gz variables with the most current data.
90+
imu.readGyro();
91+
92+
// Now we can use the gx, gy, and gz variables as we please.
93+
Serial.print("G: ");
94+
Serial.print(imu.gx);
95+
Serial.print(", ");
96+
Serial.print(imu.gy);
97+
Serial.print(", ");
98+
Serial.println(imu.gz);
99+
}
100+
101+
void printMag()
102+
{
103+
// To read from the magnetometer, you must first call the
104+
// readMag() function. When this exits, it'll update the
105+
// mx, my, and mz variables with the most current data.
106+
imu.readMag();
107+
108+
// Now we can use the mx, my, and mz variables as we please.
109+
Serial.print("M: ");
110+
Serial.print(imu.mx);
111+
Serial.print(", ");
112+
Serial.print(imu.my);
113+
Serial.print(", ");
114+
Serial.println(imu.mz);
115+
}
116+
117+
---
118+
119+
Check out the example files in the [examples directory](https://github.com/sparkfun/SparkFun_LSM9DS1_Particle_Library/tree/master/firmware/examples) for more guidance.
120+
121+
Recommended Components
122+
-------------------
123+
124+
* [Particle Photon](https://www.sparkfun.com/products/13345)
125+
* [SparkFun Photon IMU Shield](https://www.sparkfun.com/products/13629)
126+
127+
128+
License Information
129+
-------------------
130+
131+
This product is _**open source**_!
132+
133+
Please review the LICENSE.md file for license information.
134+
135+
If you have any questions or concerns on licensing, please contact [email protected].
136+
137+
Distributed as-is; no warranty is given.
138+
139+
- Your friends at SparkFun.

doc/LSM9DS1 Datasheet.pdf

1.88 MB
Binary file not shown.

firmware/LSM9DS1_Registers.h

Lines changed: 111 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,111 @@
1+
/******************************************************************************
2+
LSM9DS1_Registers.h
3+
SparkFunLSM9DS1 Particle Library - LSM9DS1 Register Map
4+
Jim Lindblom @ SparkFun Electronics
5+
Original Creation Date: April 21, 2015
6+
https://github.com/sparkfun/SparkFun_LSM9DS1_Particle_Library
7+
8+
This file defines all registers internal to the gyro/accel and magnetometer
9+
devices in the LSM9DS1.
10+
11+
Development environment specifics:
12+
IDE: Particle Build
13+
Hardware Platform: Particle Photon
14+
SparkFun Photon IMU Shield
15+
16+
This code is released under the MIT license.
17+
18+
Distributed as-is; no warranty is given.
19+
******************************************************************************/
20+
21+
#ifndef __LSM9DS1_Registers_H__
22+
#define __LSM9DS1_Registers_H__
23+
24+
/////////////////////////////////////////
25+
// LSM9DS1 Accel/Gyro (XL/G) Registers //
26+
/////////////////////////////////////////
27+
#define ACT_THS 0x04
28+
#define ACT_DUR 0x05
29+
#define INT_GEN_CFG_XL 0x06
30+
#define INT_GEN_THS_X_XL 0x07
31+
#define INT_GEN_THS_Y_XL 0x08
32+
#define INT_GEN_THS_Z_XL 0x09
33+
#define INT_GEN_DUR_XL 0x0A
34+
#define REFERENCE_G 0x0B
35+
#define INT1_CTRL 0x0C
36+
#define INT2_CTRL 0x0D
37+
#define WHO_AM_I_XG 0x0F
38+
#define CTRL_REG1_G 0x10
39+
#define CTRL_REG2_G 0x11
40+
#define CTRL_REG3_G 0x12
41+
#define ORIENT_CFG_G 0x13
42+
#define INT_GEN_SRC_G 0x14
43+
#define OUT_TEMP_L 0x15
44+
#define OUT_TEMP_H 0x16
45+
#define STATUS_REG_0 0x17
46+
#define OUT_X_L_G 0x18
47+
#define OUT_X_H_G 0x19
48+
#define OUT_Y_L_G 0x1A
49+
#define OUT_Y_H_G 0x1B
50+
#define OUT_Z_L_G 0x1C
51+
#define OUT_Z_H_G 0x1D
52+
#define CTRL_REG4 0x1E
53+
#define CTRL_REG5_XL 0x1F
54+
#define CTRL_REG6_XL 0x20
55+
#define CTRL_REG7_XL 0x21
56+
#define CTRL_REG8 0x22
57+
#define CTRL_REG9 0x23
58+
#define CTRL_REG10 0x24
59+
#define INT_GEN_SRC_XL 0x26
60+
#define STATUS_REG_1 0x27
61+
#define OUT_X_L_XL 0x28
62+
#define OUT_X_H_XL 0x29
63+
#define OUT_Y_L_XL 0x2A
64+
#define OUT_Y_H_XL 0x2B
65+
#define OUT_Z_L_XL 0x2C
66+
#define OUT_Z_H_XL 0x2D
67+
#define FIFO_CTRL 0x2E
68+
#define FIFO_SRC 0x2F
69+
#define INT_GEN_CFG_G 0x30
70+
#define INT_GEN_THS_XH_G 0x31
71+
#define INT_GEN_THS_XL_G 0x32
72+
#define INT_GEN_THS_YH_G 0x33
73+
#define INT_GEN_THS_YL_G 0x34
74+
#define INT_GEN_THS_ZH_G 0x35
75+
#define INT_GEN_THS_ZL_G 0x36
76+
#define INT_GEN_DUR_G 0x37
77+
78+
///////////////////////////////
79+
// LSM9DS1 Magneto Registers //
80+
///////////////////////////////
81+
#define OFFSET_X_REG_L_M 0x05
82+
#define OFFSET_X_REG_H_M 0x06
83+
#define OFFSET_Y_REG_L_M 0x07
84+
#define OFFSET_Y_REG_H_M 0x08
85+
#define OFFSET_Z_REG_L_M 0x09
86+
#define OFFSET_Z_REG_H_M 0x0A
87+
#define WHO_AM_I_M 0x0F
88+
#define CTRL_REG1_M 0x20
89+
#define CTRL_REG2_M 0x21
90+
#define CTRL_REG3_M 0x22
91+
#define CTRL_REG4_M 0x23
92+
#define CTRL_REG5_M 0x24
93+
#define STATUS_REG_M 0x27
94+
#define OUT_X_L_M 0x28
95+
#define OUT_X_H_M 0x29
96+
#define OUT_Y_L_M 0x2A
97+
#define OUT_Y_H_M 0x2B
98+
#define OUT_Z_L_M 0x2C
99+
#define OUT_Z_H_M 0x2D
100+
#define INT_CFG_M 0x30
101+
#define INT_SRC_M 0x30
102+
#define INT_THS_L_M 0x32
103+
#define INT_THS_H_M 0x33
104+
105+
////////////////////////////////
106+
// LSM9DS1 WHO_AM_I Responses //
107+
////////////////////////////////
108+
#define WHO_AM_I_AG_RSP 0x68
109+
#define WHO_AM_I_M_RSP 0x3D
110+
111+
#endif

0 commit comments

Comments
 (0)