Skip to content

Commit 5303f50

Browse files
update for QC, debugged and partially commented
1 parent ebe41ca commit 5303f50

File tree

16 files changed

+2212
-1306
lines changed

16 files changed

+2212
-1306
lines changed

LICENSE.md

Lines changed: 52 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,57 @@
1+
SparkFun License Information
2+
============================
13

2-
License Information
3-
-------------------
4+
SparkFun uses two different licenses for our files - one for hardware and one for code.
45

5-
The hardware is released under [Creative Commons Share-alike 3.0](http://creativecommons.org/licenses/by-sa/3.0/).
6+
Hardware
7+
---------
68

7-
All other code is open source so please feel free to do anything you want with it; you buy me a beer if you use this and we meet someday ([Beerware license](http://en.wikipedia.org/wiki/Beerware)).
9+
**SparkFun hardware is released under [Creative Commons Share-alike 4.0 International](http://creativecommons.org/licenses/by-sa/4.0/).**
10+
11+
Note: This is a human-readable summary of (and not a substitute for) the [license](http://creativecommons.org/licenses/by-sa/4.0/legalcode).
12+
13+
You are free to:
14+
15+
Share — copy and redistribute the material in any medium or format
16+
Adapt — remix, transform, and build upon the material
17+
for any purpose, even commercially.
18+
The licensor cannot revoke these freedoms as long as you follow the license terms.
19+
Under the following terms:
20+
21+
Attribution — You must give appropriate credit, provide a link to the license, and indicate if changes were made. You may do so in any reasonable manner, but not in any way that suggests the licensor endorses you or your use.
22+
ShareAlike — If you remix, transform, or build upon the material, you must distribute your contributions under the same license as the original.
23+
No additional restrictions — You may not apply legal terms or technological measures that legally restrict others from doing anything the license permits.
24+
Notices:
25+
26+
You do not have to comply with the license for elements of the material in the public domain or where your use is permitted by an applicable exception or limitation.
27+
No warranties are given. The license may not give you all of the permissions necessary for your intended use. For example, other rights such as publicity, privacy, or moral rights may limit how you use the material.
28+
29+
30+
Code
31+
--------
32+
33+
**SparkFun code, firmware, and software is released under the [MIT License](http://opensource.org/licenses/MIT).**
34+
35+
The MIT License (MIT)
36+
37+
Copyright (c) 2015 SparkFun Electronics
38+
39+
Permission is hereby granted, free of charge, to any person obtaining a copy
40+
of this software and associated documentation files (the "Software"), to deal
41+
in the Software without restriction, including without limitation the rights
42+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
43+
copies of the Software, and to permit persons to whom the Software is
44+
furnished to do so, subject to the following conditions:
45+
46+
The above copyright notice and this permission notice shall be included in all
47+
copies or substantial portions of the Software.
48+
49+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
50+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
51+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
52+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
53+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
54+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
55+
SOFTWARE.
856

9-
->Additional Licenses and attributions to original authors as needed.<-
1057

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,9 +40,9 @@ License Information
4040

4141
This product is _**open source**_!
4242

43-
The **code** is beerware; if you see me (or any other SparkFun employee) at the local, and you've found our code helpful, please buy us a round!
43+
Please review the LICENSE.md file for license information.
4444

45-
Please use, reuse, and modify these files as you see fit. Please maintain attribution to SparkFun Electronics and release anything derivative under the same license.
45+
If you have any questions or concerns on licensing, please contact [email protected].
4646

4747
Distributed as-is; no warranty is given.
4848

examples/FifoExample/FifoExample.ino

Lines changed: 87 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -1,42 +1,82 @@
1+
/******************************************************************************
2+
FifoExample.ino
3+
Example using the FIFO over SPI.
4+
5+
Marshall Taylor @ SparkFun Electronics
6+
May 20, 2015
7+
https://github.com/sparkfun/LSM6DS3_Breakout
8+
https://github.com/sparkfun/SparkFun_LSM6DS3_Arduino_Library
9+
10+
Description:
11+
The FIFO is configured to take readings at 50Hz. When 100 samples have
12+
accumulated (when the "watermark" is reached), the sketch dumps the float values to the serial terminal.
13+
14+
The FIFO can sample much faster but the serial port isn't fast enough to get
15+
that data out before another 100 samples get queued up. There is a 10ms delay
16+
placed after each line ("1.40,-4.41,-3.22,-0.01,0.01,0.99") so that the
17+
internal serial buffer is guaranteed to empty and not overflow.
18+
19+
Cranking the sample rate up to 800Hz will result in the FIFO dumping routine
20+
never getting the FIFO back down to zero.
21+
22+
Removing the 10ms delay allows the FIFO to be emptied, but then too much data
23+
gets placed in the serial write buffer and stability suffers.
24+
25+
Resources:
26+
Uses Wire.h for I2C operation
27+
Uses SPI.h for SPI operation
28+
Either can be omitted if not used
29+
30+
Development environment specifics:
31+
Arduino IDE 1.6.4
32+
Teensy loader 1.23
33+
34+
Hardware connections:
35+
***CAUTION -- SPI pins can not be connected directly to 5V IO***
36+
37+
Connect SDA/SDI line to pin 11 through a level shifter (MOSI)
38+
Connect SCL pin line to pin 13 through a level shifter (SCLK)
39+
Connect SDO/SA0 line to pin 12 through a level shifter (MISO)
40+
Connect CS to a free pin through a level shifter. This example uses pin 10.
41+
Connect GND and ***3.3v*** power to the IMU. The sensors are not 5v tolerant.
42+
43+
This code is released under the [MIT License](http://opensource.org/licenses/MIT).
44+
45+
Please review the LICENSE.md file included with this example. If you have any questions
46+
or concerns with licensing, please contact [email protected].
47+
48+
Distributed as-is; no warranty is given.
49+
******************************************************************************/
50+
151
#include "SparkFunLSM6DS3.h"
252
#include "Wire.h"
353
#include "SPI.h"
454

5-
LSM6DS3 myIMU;
55+
LSM6DS3 myIMU( SPI_MODE, 10 );
656

757
void setup( void ) {
8-
Serial.begin(57600); // start serial for output
9-
1058
//Over-ride default settings if desired
1159
myIMU.settings.gyroEnabled = 1; //Can be 0 or 1
1260
myIMU.settings.gyroRange = 2000; //Max deg/s. Can be: 125, 245, 500, 1000, 2000
13-
myIMU.settings.gyroSampleRate = 208; //Hz. Can be: 13, 26, 52, 104, 208, 416, 833, 1666
14-
myIMU.settings.gyroBandWidth = 400; //Hz. Can be: 50, 100, 200, 400;
61+
myIMU.settings.gyroSampleRate = 833; //Hz. Can be: 13, 26, 52, 104, 208, 416, 833, 1666
62+
myIMU.settings.gyroBandWidth = 200; //Hz. Can be: 50, 100, 200, 400;
1563
myIMU.settings.gyroFifoEnabled = 1; //Set to include gyro in FIFO
1664
myIMU.settings.gyroFifoDecimation = 1; //set 1 for on /1
1765

1866
myIMU.settings.accelEnabled = 1;
1967
myIMU.settings.accelRange = 16; //Max G force readable. Can be: 2, 4, 8, 16
20-
myIMU.settings.accelSampleRate = 208; //Hz. Can be: 13, 26, 52, 104, 208, 416, 833, 1666, 3332, 6664, 13330
21-
myIMU.settings.accelBandWidth = 50; //Hz. Can be: 50, 100, 200, 400;
68+
myIMU.settings.accelSampleRate = 833; //Hz. Can be: 13, 26, 52, 104, 208, 416, 833, 1666, 3332, 6664, 13330
69+
myIMU.settings.accelBandWidth = 200; //Hz. Can be: 50, 100, 200, 400;
2270
myIMU.settings.accelFifoEnabled = 1; //Set to include accelerometer in the FIFO
2371
myIMU.settings.accelFifoDecimation = 1; //set 1 for on /1
2472
myIMU.settings.tempEnabled = 1;
2573

26-
//Select interface mode
27-
myIMU.settings.commInterface = SPI_MODE; //Can be I2C_MODE, SPI_MODE
28-
myIMU.settings.commMode = 1; //Can be modes 1, 2 or 3
29-
//Select address for I2C. Does nothing for SPI
30-
myIMU.settings.I2CAddress = 0x6B; //Ignored for SPI_MODE
31-
//Select CS pin for SPI. Does nothing for I2C
32-
myIMU.settings.chipSelectPin = 10;
33-
34-
//Non-basic mode settings
74+
//Non-basic mode settings
3575
myIMU.settings.commMode = 1;
3676

3777
//FIFO control settings
3878
myIMU.settings.fifoThreshold = 100; //Can be 0 to 4096 (16 bit bytes)
39-
myIMU.settings.fifoSampleRate = 200; //Hz. Can be: 10, 25, 50, 100, 200, 400, 800, 1600, 3300, 6600
79+
myIMU.settings.fifoSampleRate = 50; //Hz. Can be: 10, 25, 50, 100, 200, 400, 800, 1600, 3300, 6600
4080
myIMU.settings.fifoModeWord = 6; //FIFO mode.
4181
//FIFO mode. Can be:
4282
// 0 (Bypass mode, FIFO off)
@@ -45,11 +85,24 @@ void setup( void ) {
4585
// 4 (Bypass until trigger)
4686
// 6 (Continous mode)
4787

48-
uint8_t c = myIMU.begin(); //Can be called again to load new settings
49-
myIMU.fifoBegin();
88+
89+
Serial.begin(57600); // start serial for output
90+
delay(1000); //relax...
91+
Serial.println("Processor came out of reset.\n");
92+
93+
//Call .begin() to configure the IMUs
94+
if( myIMU.begin() != 0 )
95+
{
96+
Serial.println("Problem starting the sensor with CS @ Pin 10.");
97+
}
98+
else
99+
{
100+
Serial.println("Sensor with CS @ Pin 10 started.");
101+
}
50102

51-
Serial.print("begin() ran. Returns WHO_AM_I of: 0x");
52-
Serial.println(c, HEX);
103+
Serial.print("Configuring FIFO with no error checking...");
104+
myIMU.fifoBegin();
105+
Serial.print("Done!\n");
53106

54107
Serial.print("Clearing out the FIFO...");
55108
myIMU.fifoClear();
@@ -64,13 +117,10 @@ void loop()
64117
uint16_t tempUnsigned;
65118

66119
while( ( myIMU.fifoGetStatus() & 0x8000 ) == 0 ) {}; //Wait for watermark
67-
68-
//Get the divisor for the gyro
69-
uint8_t gyroRangeDivisor = myIMU.settings.gyroRange / 125;
70-
if ( myIMU.settings.gyroRange == 245 ) {
71-
gyroRangeDivisor = 2;
72-
}
73-
120+
121+
//Now loop until FIFO is empty. NOTE: As the FIFO is only 8 bits wide,
122+
//the channels must be synchronized to a known position for the data to align
123+
//properly. Emptying the fifo is one way of doing this (this example)
74124
while( ( myIMU.fifoGetStatus() & 0x1000 ) == 0 ) {
75125

76126
temp = myIMU.calcGyro(myIMU.fifoRead());
@@ -96,10 +146,14 @@ void loop()
96146
temp = myIMU.calcAccel(myIMU.fifoRead());
97147
Serial.print(temp);
98148
Serial.print("\n");
99-
// tempUnsigned = myIMU.fifoGetStatus();
100-
// Serial.print("Fifo Status 1 and 2 (16 bits): 0x");
101-
// Serial.println(tempUnsigned, HEX);
102-
}
103149

104-
delay(1000);
150+
delay(10); //Wait for the serial buffer to clear (~50 bytes worth of time @ 57600baud)
151+
152+
}
153+
154+
tempUnsigned = myIMU.fifoGetStatus();
155+
Serial.print("\nFifo Status 1 and 2 (16 bits): 0x");
156+
Serial.println(tempUnsigned, HEX);
157+
Serial.print("\n");
158+
105159
}

0 commit comments

Comments
 (0)