Skip to content

Commit

Permalink
update for QC, debugged and partially commented
Browse files Browse the repository at this point in the history
  • Loading branch information
marshalltaylorSFE committed Aug 6, 2015
1 parent ebe41ca commit 5303f50
Show file tree
Hide file tree
Showing 16 changed files with 2,212 additions and 1,306 deletions.
57 changes: 52 additions & 5 deletions LICENSE.md
@@ -1,10 +1,57 @@
SparkFun License Information
============================

License Information
-------------------
SparkFun uses two different licenses for our files - one for hardware and one for code.

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

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)).
**SparkFun hardware is released under [Creative Commons Share-alike 4.0 International](http://creativecommons.org/licenses/by-sa/4.0/).**

Note: This is a human-readable summary of (and not a substitute for) the [license](http://creativecommons.org/licenses/by-sa/4.0/legalcode).

You are free to:

Share — copy and redistribute the material in any medium or format
Adapt — remix, transform, and build upon the material
for any purpose, even commercially.
The licensor cannot revoke these freedoms as long as you follow the license terms.
Under the following terms:

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.
ShareAlike — If you remix, transform, or build upon the material, you must distribute your contributions under the same license as the original.
No additional restrictions — You may not apply legal terms or technological measures that legally restrict others from doing anything the license permits.
Notices:

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.
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.


Code
--------

**SparkFun code, firmware, and software is released under the [MIT License](http://opensource.org/licenses/MIT).**

The MIT License (MIT)

Copyright (c) 2015 SparkFun Electronics

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.

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

4 changes: 2 additions & 2 deletions README.md
Expand Up @@ -40,9 +40,9 @@ License Information

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

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!
Please review the LICENSE.md file for license information.

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.
If you have any questions or concerns on licensing, please contact techsupport@sparkfun.com.

Distributed as-is; no warranty is given.

Expand Down
120 changes: 87 additions & 33 deletions examples/FifoExample/FifoExample.ino
@@ -1,42 +1,82 @@
/******************************************************************************
FifoExample.ino
Example using the FIFO over SPI.
Marshall Taylor @ SparkFun Electronics
May 20, 2015
https://github.com/sparkfun/LSM6DS3_Breakout
https://github.com/sparkfun/SparkFun_LSM6DS3_Arduino_Library
Description:
The FIFO is configured to take readings at 50Hz. When 100 samples have
accumulated (when the "watermark" is reached), the sketch dumps the float values to the serial terminal.
The FIFO can sample much faster but the serial port isn't fast enough to get
that data out before another 100 samples get queued up. There is a 10ms delay
placed after each line ("1.40,-4.41,-3.22,-0.01,0.01,0.99") so that the
internal serial buffer is guaranteed to empty and not overflow.
Cranking the sample rate up to 800Hz will result in the FIFO dumping routine
never getting the FIFO back down to zero.
Removing the 10ms delay allows the FIFO to be emptied, but then too much data
gets placed in the serial write buffer and stability suffers.
Resources:
Uses Wire.h for I2C operation
Uses SPI.h for SPI operation
Either can be omitted if not used
Development environment specifics:
Arduino IDE 1.6.4
Teensy loader 1.23
Hardware connections:
***CAUTION -- SPI pins can not be connected directly to 5V IO***
Connect SDA/SDI line to pin 11 through a level shifter (MOSI)
Connect SCL pin line to pin 13 through a level shifter (SCLK)
Connect SDO/SA0 line to pin 12 through a level shifter (MISO)
Connect CS to a free pin through a level shifter. This example uses pin 10.
Connect GND and ***3.3v*** power to the IMU. The sensors are not 5v tolerant.
This code is released under the [MIT License](http://opensource.org/licenses/MIT).
Please review the LICENSE.md file included with this example. If you have any questions
or concerns with licensing, please contact techsupport@sparkfun.com.
Distributed as-is; no warranty is given.
******************************************************************************/

#include "SparkFunLSM6DS3.h"
#include "Wire.h"
#include "SPI.h"

LSM6DS3 myIMU;
LSM6DS3 myIMU( SPI_MODE, 10 );

void setup( void ) {
Serial.begin(57600); // start serial for output

//Over-ride default settings if desired
myIMU.settings.gyroEnabled = 1; //Can be 0 or 1
myIMU.settings.gyroRange = 2000; //Max deg/s. Can be: 125, 245, 500, 1000, 2000
myIMU.settings.gyroSampleRate = 208; //Hz. Can be: 13, 26, 52, 104, 208, 416, 833, 1666
myIMU.settings.gyroBandWidth = 400; //Hz. Can be: 50, 100, 200, 400;
myIMU.settings.gyroSampleRate = 833; //Hz. Can be: 13, 26, 52, 104, 208, 416, 833, 1666
myIMU.settings.gyroBandWidth = 200; //Hz. Can be: 50, 100, 200, 400;
myIMU.settings.gyroFifoEnabled = 1; //Set to include gyro in FIFO
myIMU.settings.gyroFifoDecimation = 1; //set 1 for on /1

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

//Select interface mode
myIMU.settings.commInterface = SPI_MODE; //Can be I2C_MODE, SPI_MODE
myIMU.settings.commMode = 1; //Can be modes 1, 2 or 3
//Select address for I2C. Does nothing for SPI
myIMU.settings.I2CAddress = 0x6B; //Ignored for SPI_MODE
//Select CS pin for SPI. Does nothing for I2C
myIMU.settings.chipSelectPin = 10;

//Non-basic mode settings
//Non-basic mode settings
myIMU.settings.commMode = 1;

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

uint8_t c = myIMU.begin(); //Can be called again to load new settings
myIMU.fifoBegin();

Serial.begin(57600); // start serial for output
delay(1000); //relax...
Serial.println("Processor came out of reset.\n");

//Call .begin() to configure the IMUs
if( myIMU.begin() != 0 )
{
Serial.println("Problem starting the sensor with CS @ Pin 10.");
}
else
{
Serial.println("Sensor with CS @ Pin 10 started.");
}

Serial.print("begin() ran. Returns WHO_AM_I of: 0x");
Serial.println(c, HEX);
Serial.print("Configuring FIFO with no error checking...");
myIMU.fifoBegin();
Serial.print("Done!\n");

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

while( ( myIMU.fifoGetStatus() & 0x8000 ) == 0 ) {}; //Wait for watermark

//Get the divisor for the gyro
uint8_t gyroRangeDivisor = myIMU.settings.gyroRange / 125;
if ( myIMU.settings.gyroRange == 245 ) {
gyroRangeDivisor = 2;
}


//Now loop until FIFO is empty. NOTE: As the FIFO is only 8 bits wide,
//the channels must be synchronized to a known position for the data to align
//properly. Emptying the fifo is one way of doing this (this example)
while( ( myIMU.fifoGetStatus() & 0x1000 ) == 0 ) {

temp = myIMU.calcGyro(myIMU.fifoRead());
Expand All @@ -96,10 +146,14 @@ void loop()
temp = myIMU.calcAccel(myIMU.fifoRead());
Serial.print(temp);
Serial.print("\n");
// tempUnsigned = myIMU.fifoGetStatus();
// Serial.print("Fifo Status 1 and 2 (16 bits): 0x");
// Serial.println(tempUnsigned, HEX);
}

delay(1000);
delay(10); //Wait for the serial buffer to clear (~50 bytes worth of time @ 57600baud)

}

tempUnsigned = myIMU.fifoGetStatus();
Serial.print("\nFifo Status 1 and 2 (16 bits): 0x");
Serial.println(tempUnsigned, HEX);
Serial.print("\n");

}

0 comments on commit 5303f50

Please sign in to comment.