반응형
6 자유도 IMU 센서 -LSM6DS3(SparkFun 6 Degrees of Freedom Breakout - LSM6DS3)
본 센서 모듈은 많은 어플리케이션에애플리케이션에 사용이 가능하게 디자인되었으며, 충격을 검출하건, 기울이기, 움직임, 탭, 걸음 카운트, 온도 측정 등의 애플리케이션에서 사용할 수 있는 IMU 센서(Inertial Measurement Unit은 직역하면 관성 측정장치입니다. 또한 IMU는 자이로스코프 / 가속도계 / 지자기 센서로 구성된 센서)입니다.
특징은 아래와 같습니다.
- 본 제품은 LSM6DS3 칩을 탑재한 가속도계 및 자이로 센서입니다.
- 8kb의 큰 FIFO 버퍼, 임베디드 프로세싱 인터럽트 펑션을 가지고 있습니다.
- 본 센서 모듈은 많은 어플리케이션에애플리케이션에 사용이 가능하게 디자인되었으며, 충격을 검출하건, 기울이기, 움직임, 탭, 걸음 카운트, 온도 측정 등의 애플리케이션에서 사용할 수 있습니다.
- LSM6DS3은 가속도계 데이터를 6.7kS/s, 자이로스코프 데이터를 1.7kS/s로 읽을 수 있어 좀 더 정교한 움직임 감지가 가능합니다.
- 읽은 데이터는 8Kb까지 버퍼링 할 수 있으며, 인터럽트 핀을 동작시킬 수 있습니다.
- 핀 패드를 통해 LSM6DS3의 각 핀에 접근할 수 있으며, 보드의 한쪽은 전원 및 I2C, 다른 한쪽은 SPI 기능과 인터럽트 출력을 제어하는 핀이 나와 있습니다.
- LSM6DS3은 3.3V용입니다. 3.3V 이상을 입력하면 IC는 망가지게 됩니다.
- 5V 마이크로컨트롤러와는 레벨 쉬프터를 이용하여 사용하십시오.
- FifoExample - Demonstrates using the built-in buffer to burst-collect data - Good demonstration of settings
/******************************************************************************
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( I2C_MODE, 0x6A );
void setup( void ) {
//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 = 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 = 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;
//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 = 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)
// 1 (Stop when full)
// 3 (Continuous during trigger)
// 4 (Bypass until trigger)
// 6 (Continous mode)
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("Configuring FIFO with no error checking...");
myIMU.fifoBegin();
Serial.print("Done!\n");
Serial.print("Clearing out the FIFO...");
myIMU.fifoClear();
Serial.print("Done!\n");
}
void loop()
{
float temp; //This is to hold read data
uint16_t tempUnsigned;
while( ( myIMU.fifoGetStatus() & 0x8000 ) == 0 ) {}; //Wait for watermark
//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());
Serial.print(temp);
Serial.print(",");
temp = myIMU.calcGyro(myIMU.fifoRead());
Serial.print(temp);
Serial.print(",");
temp = myIMU.calcGyro(myIMU.fifoRead());
Serial.print(temp);
Serial.print(",");
temp = myIMU.calcAccel(myIMU.fifoRead());
Serial.print(temp);
Serial.print(",");
temp = myIMU.calcAccel(myIMU.fifoRead());
Serial.print(temp);
Serial.print(",");
temp = myIMU.calcAccel(myIMU.fifoRead());
Serial.print(temp);
Serial.print("\n");
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");
}
- LowLevelExample - Demonstrates using only the core driver without math and settings overhead
/******************************************************************************
LowLevelExample.ino
Marshall Taylor @ SparkFun Electronics
May 20, 2015
https://github.com/sparkfun/LSM6DS3_Breakout
https://github.com/sparkfun/SparkFun_LSM6DS3_Arduino_Library
Description:
Example using the LSM6DS3 with ONLY read and write methods. It's up to you to
read the datasheets and get the sensor to behave as you will.
This sketch saves a significant amount of memory because the settings and complex
math (such as floating point variables) don't exist. The cost of saved memory is
that the values are in 'counts', or raw data from the register. The user is
responsible for converting these raw values into something meaningful.
Use the register words from SparkFunLSM6DS3.h to manually configure the IC.
Resources:
Uses Wire.h for i2c operation
Uses SPI.h for SPI operation
Development environment specifics:
Arduino IDE 1.6.4
Teensy loader 1.23
Hardware connections:
Connect I2C SDA line to A4
Connect I2C SCL line to A5
Connect GND and 3.3v power to the IMU
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"
uint16_t errorsAndWarnings = 0;
LSM6DS3Core myIMU( I2C_MODE, 0x6A );
//LSM6DS3Core myIMU( SPI_MODE, 10 );
void setup() {
// put your setup code here, to run once:
Serial.begin(9600);
delay(1000); //relax...
Serial.println("Processor came out of reset.\n");
//Call .beginCore() to configure the IMU
if( myIMU.beginCore() != 0 )
{
Serial.print("Error at beginCore().\n");
}
else
{
Serial.print("\nbeginCore() passed.\n");
}
uint8_t dataToWrite = 0; //Temporary variable
//Setup the accelerometer******************************
dataToWrite = 0; //Start Fresh!
dataToWrite |= LSM6DS3_ACC_GYRO_BW_XL_100Hz;
dataToWrite |= LSM6DS3_ACC_GYRO_FS_XL_8g;
dataToWrite |= LSM6DS3_ACC_GYRO_ODR_XL_104Hz;
//Now, write the patched together data
errorsAndWarnings += myIMU.writeRegister(LSM6DS3_ACC_GYRO_CTRL1_XL, dataToWrite);
//Set the ODR bit
errorsAndWarnings += myIMU.readRegister(&dataToWrite, LSM6DS3_ACC_GYRO_CTRL4_C);
dataToWrite &= ~((uint8_t)LSM6DS3_ACC_GYRO_BW_SCAL_ODR_ENABLED);
}
void loop()
{
int16_t temp;
//Get all parameters
Serial.print("\nAccelerometer Counts:\n");
Serial.print(" X = ");
//Read a register into the temp variable.
if( myIMU.readRegisterInt16(&temp, LSM6DS3_ACC_GYRO_OUTX_L_XL) != 0 )
{
errorsAndWarnings++;
}
Serial.println(temp);
Serial.print(" Y = ");
//Read a register into the temp variable.
if( myIMU.readRegisterInt16(&temp, LSM6DS3_ACC_GYRO_OUTY_L_XL) != 0 )
{
errorsAndWarnings++;
}
Serial.println(temp);
Serial.print(" Z = ");
//Read a register into the temp variable.
if( myIMU.readRegisterInt16(&temp, LSM6DS3_ACC_GYRO_OUTZ_L_XL) != 0 )
{
errorsAndWarnings++;
}
Serial.println(temp);
Serial.println();
Serial.print("Total reported Errors and Warnings: ");
Serial.println(errorsAndWarnings);
delay(1000);
}
- InterruptFreeFall - Embedded function demonstrating free-fall detection
/******************************************************************************
InterruptFreeFallConfig.ino
Marshall Taylor @ SparkFun Electronics
May 20, 2015
https://github.com/sparkfun/LSM6DS3_Breakout
https://github.com/sparkfun/SparkFun_LSM6DS3_Arduino_Library
Description:
This sketch demonstrates detecting the free-fall condition.
Run the sketch, open a serial window at 9600 baud, then drop your
sensor / arduino (And catch it!). The sketch will report the free-fall to
the monitor.
The configuration is determined by reading the LSM6DS3 datasheet and application
note, then driving hex values to the registers of interest to set the appropriate
bits. The sketch is based of the "LowLevelExampe" sketch.
Resources:
Uses Wire.h for i2c operation
Uses SPI.h for SPI operation
Development environment specifics:
Arduino IDE 1.6.4
Teensy loader 1.23
Hardware connections:
Connect I2C SDA line to A4
Connect I2C SCL line to A5
Connect GND and 3.3v power to the IMU
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"
LSM6DS3Core myIMU( I2C_MODE, 0x6A );
//LSM6DS3Core myIMU( SPI_MODE, 10 );
void setup() {
// put your setup code here, to run once:
Serial.begin(9600);
delay(1000); //relax...
Serial.println("Sketch came out of reset.\n");
//Call .beginCore() to configure the IMU
if( myIMU.beginCore() != 0 )
{
Serial.print("Error at beginCore().\n");
}
else
{
Serial.print("\nbeginCore() passed.\n");
}
//Error accumulation variable
uint8_t errorAccumulator = 0;
uint8_t dataToWrite = 0; //Temporary variable
//Setup the accelerometer******************************
dataToWrite = 0; //Start Fresh!
dataToWrite |= LSM6DS3_ACC_GYRO_BW_XL_200Hz;
dataToWrite |= LSM6DS3_ACC_GYRO_FS_XL_2g;
dataToWrite |= LSM6DS3_ACC_GYRO_ODR_XL_416Hz;
// //Now, write the patched together data
errorAccumulator += myIMU.writeRegister(LSM6DS3_ACC_GYRO_CTRL1_XL, dataToWrite);
//Set the ODR bit
errorAccumulator += myIMU.readRegister(&dataToWrite, LSM6DS3_ACC_GYRO_CTRL4_C);
dataToWrite &= ~((uint8_t)LSM6DS3_ACC_GYRO_BW_SCAL_ODR_ENABLED);
// Write 00h into WAKE_UP_DUR
errorAccumulator += myIMU.writeRegister( LSM6DS3_ACC_GYRO_WAKE_UP_DUR, 0x00 );
// Set FF threshold (FF_THS[2:0] = 011b)
// Set six samples event duration (FF_DUR[5:0] = 000110b)
// Write 33h into FREE_FALL
errorAccumulator += myIMU.writeRegister(LSM6DS3_ACC_GYRO_FREE_FALL, 0x33);
// FF interrupt driven to INT1 pin
// Write 10h into MD1_CFG
errorAccumulator += myIMU.writeRegister( LSM6DS3_ACC_GYRO_MD1_CFG, 0x10 );
// Also route to INT2 pin
// Write 10h into MD1_CFG
errorAccumulator += myIMU.writeRegister( LSM6DS3_ACC_GYRO_MD2_CFG, 0x10 );
// Latch interrupt
// Write 01h into TAP_CFG
errorAccumulator += myIMU.writeRegister(LSM6DS3_ACC_GYRO_TAP_CFG1, 0x01);
if( errorAccumulator )
{
Serial.println("Problem configuring the device.");
}
else
{
Serial.println("Device O.K.");
}
}
void loop()
{
uint8_t readDataByte = 0;
//Read the wake-up source register
myIMU.readRegister(&readDataByte, LSM6DS3_ACC_GYRO_WAKE_UP_SRC);
//Mask off the FF_IA bit for free-fall detection
readDataByte &= 0x20;
//Check for free-fall
if( readDataByte )
{
//debounce
delay(10);
Serial.println("Interrupt caught. Free fall detected.");
}
}
- InterruptHWTapConfig - Embedded function demonstrating tap and double-tap detection
/******************************************************************************
InterruptHWTapConfig.ino
Marshall Taylor @ SparkFun Electronics
May 20, 2015
https://github.com/sparkfun/LSM6DS3_Breakout
https://github.com/sparkfun/SparkFun_LSM6DS3_Arduino_Library
Description:
Example using the LSM6DS3 interrupts.
This sketch demonstrates one way to detect single and double-tap events using
hardware interrupt pins. The LSM6DS3 pulses the int1 line once after the first
tap, then again if a second tap comes in.
The configuration is determined by reading the LSM6DS3 datasheet and application
note, then driving hex values to the registers of interest to set the appropriate
bits. The sketch is based of the "LowLevelExampe" sketch.
Resources:
Uses Wire.h for i2c operation
Uses SPI.h for SPI operation
Development environment specifics:
Arduino IDE 1.6.4
Teensy loader 1.23
Hardware connections:
Connect I2C SDA line to A4
Connect I2C SCL line to A5
Connect GND and 3.3v power to the IMU
Connect INT1 to pin 2 -- Note: the atmega has 5v input and the LSM6DS3 is 3.3v
output. This is OK because the input is high impedance and 3.3v is a logic '1'
for 5v processors. The signal is correctly detected and nothing is damaged.
Do not configure pin 2 as OUTPUT!
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"
//Interrupt variables
#define int1Pin 2 //Use pin 2 for int.0 on uno
uint8_t int1Status = 0;
LSM6DS3Core myIMU( I2C_MODE, 0x6A );
//LSM6DS3Core myIMU( SPI_MODE, 10 );
void setup()
{
Serial.begin(9600);
delay(1000); //relax...
Serial.println("Processor came out of reset.\n");
//Call .beginCore() to configure the IMU
if( myIMU.beginCore() != 0 )
{
Serial.print("Error at beginCore().\n");
}
else
{
Serial.print("\nbeginCore() passed.\n");
}
//Error accumulation variable
uint8_t errorAccumulator = 0;
uint8_t dataToWrite = 0; //Temporary variable
//Setup the accelerometer******************************
dataToWrite = 0; //Start Fresh!
dataToWrite |= LSM6DS3_ACC_GYRO_BW_XL_200Hz;
dataToWrite |= LSM6DS3_ACC_GYRO_FS_XL_2g;
dataToWrite |= LSM6DS3_ACC_GYRO_ODR_XL_416Hz;
// //Now, write the patched together data
errorAccumulator += myIMU.writeRegister(LSM6DS3_ACC_GYRO_CTRL1_XL, dataToWrite);
//Set the ODR bit
errorAccumulator += myIMU.readRegister(&dataToWrite, LSM6DS3_ACC_GYRO_CTRL4_C);
dataToWrite &= ~((uint8_t)LSM6DS3_ACC_GYRO_BW_SCAL_ODR_ENABLED);
// Enable tap detection on X, Y, Z axis, but do not latch output
errorAccumulator += myIMU.writeRegister( LSM6DS3_ACC_GYRO_TAP_CFG1, 0x0E );
// Set tap threshold
// Write 0Ch into TAP_THS_6D
errorAccumulator += myIMU.writeRegister( LSM6DS3_ACC_GYRO_TAP_THS_6D, 0x03 );
// Set Duration, Quiet and Shock time windows
// Write 7Fh into INT_DUR2
errorAccumulator += myIMU.writeRegister( LSM6DS3_ACC_GYRO_INT_DUR2, 0x7F );
// Single & Double tap enabled (SINGLE_DOUBLE_TAP = 1)
// Write 80h into WAKE_UP_THS
errorAccumulator += myIMU.writeRegister( LSM6DS3_ACC_GYRO_WAKE_UP_THS, 0x80 );
// Single tap interrupt driven to INT1 pin -- enable latch
// Write 08h into MD1_CFG
errorAccumulator += myIMU.writeRegister( LSM6DS3_ACC_GYRO_MD1_CFG, 0x48 );
if( errorAccumulator )
{
Serial.println("Problem configuring the device.");
}
else
{
Serial.println("Device O.K.");
}
//Configure the atmega interrupt pin
pinMode(int1Pin, INPUT);
attachInterrupt(0, int1ISR, RISING);
}
void loop()
{
if( int1Status > 0 ) //If ISR has been serviced at least once
{
//Wait for a window (in case a second tap is coming)
delay(300);
//Check if there are more than one interrupt pulse
if( int1Status == 1 )
{
Serial.print("Single-tap event\n");
}
if( int1Status > 1 )
{
Serial.print("Double-tap event\n");
}
//Clear the ISR counter
int1Status = 0;
}
}
void int1ISR()
{
//Serial.println("Interrupt serviced.");
int1Status++;
}
- MemoryPagingExample - Demonstrates switching between memory pages
/******************************************************************************
MemoryPagingExample.ino
Marshall Taylor @ SparkFun Electronics
May 20, 2015
https://github.com/sparkfun/LSM6DS3_Breakout
https://github.com/sparkfun/SparkFun_LSM6DS3_Arduino_Library
Description:
This sketch switches between the base memory page and the embedded page.
The test writes to a base address, switches pages, writes to a embedded location
at the same numerical address, switches back and reads the original value.
This sketch doesn't do any meaningful configuration for the LSM6DS3, just tests.
Resources:
Uses Wire.h for i2c operation
Uses SPI.h for SPI operation
Development environment specifics:
Arduino IDE 1.6.4
Teensy loader 1.23
Hardware connections:
Connect I2C SDA line to A4
Connect I2C SCL line to A5
Connect GND and 3.3v power to the IMU
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"
uint16_t errorsAndWarnings = 0;
LSM6DS3Core myIMU( I2C_MODE, 0x6A );
//LSM6DS3Core myIMU( SPI_MODE, 10 );
void setup()
{
Serial.begin(9600);
delay(1000); //relax...
Serial.println("Processor came out of reset.\n");
//Call .beginCore() to configure the IMU
if( myIMU.beginCore() != 0 )
{
Serial.print("Error at beginCore().\n");
}
else
{
Serial.print("\nbeginCore() passed.\n");
}
uint8_t dataVariable = 0; //Temporary variable
//Write something to a base page location to make sure it gets preserved
//Then, read it back
if( myIMU.writeRegister( LSM6DS3_ACC_GYRO_FIFO_CTRL1, 0xF0 ) != 0 )
{
errorsAndWarnings++;
}
if( myIMU.readRegister(&dataVariable, LSM6DS3_ACC_GYRO_FIFO_CTRL1) != 0 )
{
errorsAndWarnings++;
}
Serial.print("FIFO_CTRL1 (should read 0xF0): 0x");
Serial.println(dataVariable, HEX);
//Switch to the embedded page
if( myIMU.embeddedPage() != 0 )
{
errorsAndWarnings++;
}
//Write something to a the embedded page at the same address
//Then, read it back
if( myIMU.writeRegister( LSM6DS3_ACC_GYRO_SLV1_SUBADD, 0xA5 ) != 0 )
{
errorsAndWarnings++;
}
//Now read it back and display it
if( myIMU.readRegister(&dataVariable, LSM6DS3_ACC_GYRO_SLV1_SUBADD) != 0 )
{
errorsAndWarnings++;
}
Serial.print("SUBADD (should read 0xA5): 0x");
Serial.println(dataVariable, HEX);
//Switch back to the base page
//Then, read back to see if our value has been preserved
if( myIMU.basePage() != 0 )
{
errorsAndWarnings++;
}
if( myIMU.readRegister(&dataVariable, LSM6DS3_ACC_GYRO_FIFO_CTRL1) != 0 )
{
errorsAndWarnings++;
}
Serial.print("FIFO_CTRL1 (should read 0xF0): 0x");
Serial.println(dataVariable, HEX);
Serial.print("Number of errors: ");
Serial.println(errorsAndWarnings);
}
void loop()
{
while(1);
}
- MinimalistExample - The easiest configuration
/******************************************************************************
MinimalistExample.ino
Marshall Taylor @ SparkFun Electronics
May 20, 2015
https://github.com/sparkfun/LSM6DS3_Breakout
https://github.com/sparkfun/SparkFun_LSM6DS3_Arduino_Library
Description:
Most basic example of use.
Example using the LSM6DS3 with basic settings. This sketch collects Gyro and
Accelerometer data every second, then presents it on the serial monitor.
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:
Connect I2C SDA line to A4
Connect I2C SCL line to A5
Connect GND and 3.3v power to the IMU
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; //Default constructor is I2C, addr 0x6B
LSM6DS3 myIMU (I2C_MODE, 0x6A); /* Careful in nano 33 iot */
void setup() {
// put your setup code here, to run once:
Serial.begin(9600);
delay(1000); //relax...
Serial.println("Processor came out of reset.\n");
//Call .begin() to configure the IMU
myIMU.begin();
}
void loop()
{
//Get all parameters
Serial.print("\nAccelerometer:\n");
Serial.print(" X = ");
Serial.println(myIMU.readFloatAccelX(), 4);
Serial.print(" Y = ");
Serial.println(myIMU.readFloatAccelY(), 4);
Serial.print(" Z = ");
Serial.println(myIMU.readFloatAccelZ(), 4);
Serial.print("\nGyroscope:\n");
Serial.print(" X = ");
Serial.println(myIMU.readFloatGyroX(), 4);
Serial.print(" Y = ");
Serial.println(myIMU.readFloatGyroY(), 4);
Serial.print(" Z = ");
Serial.println(myIMU.readFloatGyroZ(), 4);
Serial.print("\nThermometer:\n");
Serial.print(" Degrees C = ");
Serial.println(myIMU.readTempC(), 4);
Serial.print(" Degrees F = ");
Serial.println(myIMU.readTempF(), 4);
delay(1000);
}
아래 예제는 오류나는 듯
/******************************************************************************
MinimalistExample.ino
Owen Lyke @ SparkFun Electronics
March 13, 2019
https://github.com/sparkfun/LSM6DS3_Breakout
https://github.com/sparkfun/SparkFun_LSM6DS3_Arduino_Library
Description:
Most basic example of use - except now you can see if your settings got changed
Example using the LSM6DS3 with basic settings. This sketch collects Gyro and
Accelerometer data every second, then presents it on the serial monitor.
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:
Connect I2C SDA line to A4
Connect I2C SCL line to A5
Connect GND and 3.3v power to the IMU
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; //Default constructor is I2C, addr 0x6B
void setup() {
// put your setup code here, to run once:
Serial.begin(9600);
delay(1000); //relax...
Serial.println("Processor came out of reset.\n");
// Let's choose an unsupported setting...
myIMU.settings.accelSampleRate = 404; // Typo, 'meant' to type '104'
// Make a SensorSettings object to remember what you wanted to set everyhting to
SensorSettings settingsIWanted;
//Call .begin() to configure the IMU - supplying pointer to the SensorSettings structure
myIMU.begin(&settingsIWanted);
// Compare the sensor settings structure to know if anything was changed
compareSettings(settingsIWanted);
}
void loop()
{
//Get all parameters
Serial.print("\nAccelerometer:\n");
Serial.print(" X = ");
Serial.println(myIMU.readFloatAccelX(), 4);
Serial.print(" Y = ");
Serial.println(myIMU.readFloatAccelY(), 4);
Serial.print(" Z = ");
Serial.println(myIMU.readFloatAccelZ(), 4);
Serial.print("\nGyroscope:\n");
Serial.print(" X = ");
Serial.println(myIMU.readFloatGyroX(), 4);
Serial.print(" Y = ");
Serial.println(myIMU.readFloatGyroY(), 4);
Serial.print(" Z = ");
Serial.println(myIMU.readFloatGyroZ(), 4);
Serial.print("\nThermometer:\n");
Serial.print(" Degrees C = ");
Serial.println(myIMU.readTempC(), 4);
Serial.print(" Degrees F = ");
Serial.println(myIMU.readTempF(), 4);
delay(1000);
}
void compareSettings(SensorSettings desiredSettings){
if(myIMU.settings.accelBandWidth != desiredSettings.accelBandWidth ) { Serial.println("'accelBandWidth' was changed!"); }
if(myIMU.settings.accelRange != desiredSettings.accelRange ) { Serial.println("'accelRange' was changed!"); }
if(myIMU.settings.accelSampleRate != desiredSettings.accelSampleRate ) { Serial.println("'accelSampleRate' was changed!"); }
if(myIMU.settings.gyroRange != desiredSettings.gyroRange ) { Serial.println("'gyroRange' was changed!"); }
if(myIMU.settings.gyroSampleRate != desiredSettings.gyroSampleRate ) { Serial.println("'gyroSampleRate' was changed!"); }
// That's all the settings that might get changed in 'begin()'
}
- MultiI2C - Using two LSM6DS3s over I2C
- MultiSPI - Using two LSM6DS3s over SPI
- Pedometer - Embedded function demonstrating step-counting feature
/******************************************************************************
Pedometer.ino
Marshall Taylor @ SparkFun Electronics
May 20, 2015
https://github.com/sparkfun/LSM6DS3_Breakout
https://github.com/sparkfun/SparkFun_LSM6DS3_Arduino_Library
Description:
This sketch counts steps taken.
Run the sketch and open a serial window at 9600 baud. The sketch will display
the number of steps taken since reset. lightly tap the sensor on something at the
rate of walking to simulate having the device in your pocket. Note that you must
take 7 regularly spaced steps before the counter starts reporting.
Push the reset button to reset the device and count.
The configuration is determined by reading the LSM6DS3 datasheet and application
note, then driving hex values to the registers of interest to set the appropriate
bits. The sketch is based of the "LowLevelExampe" sketch.
Resources:
Uses Wire.h for i2c operation
Uses SPI.h for SPI operation
Development environment specifics:
Arduino IDE 1.6.4
Teensy loader 1.23
Hardware connections:
Connect I2C SDA line to A4
Connect I2C SCL line to A5
Connect GND and 3.3v power to the IMU
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"
LSM6DS3Core myIMU( I2C_MODE, 0x6A );
//LSM6DS3Core myIMU( SPI_MODE, 10 );
void setup()
{
Serial.begin(9600);
delay(1000); //relax...
Serial.println("Processor came out of reset.\n");
//Call .beginCore() to configure the IMU
if( myIMU.beginCore() != 0 )
{
Serial.print("Error at beginCore().\n");
}
else
{
Serial.print("\nbeginCore() passed.\n");
}
//Error accumulation variable
uint8_t errorAccumulator = 0;
uint8_t dataToWrite = 0; //Temporary variable
//Setup the accelerometer******************************
dataToWrite = 0; //Start Fresh!
// dataToWrite |= LSM6DS3_ACC_GYRO_BW_XL_200Hz;
dataToWrite |= LSM6DS3_ACC_GYRO_FS_XL_2g;
dataToWrite |= LSM6DS3_ACC_GYRO_ODR_XL_26Hz;
// //Now, write the patched together data
errorAccumulator += myIMU.writeRegister(LSM6DS3_ACC_GYRO_CTRL1_XL, dataToWrite);
//Set the ODR bit
errorAccumulator += myIMU.readRegister(&dataToWrite, LSM6DS3_ACC_GYRO_CTRL4_C);
dataToWrite &= ~((uint8_t)LSM6DS3_ACC_GYRO_BW_SCAL_ODR_ENABLED);
// Enable embedded functions -- ALSO clears the pdeo step count
errorAccumulator += myIMU.writeRegister(LSM6DS3_ACC_GYRO_CTRL10_C, 0x3E);
// Enable pedometer algorithm
errorAccumulator += myIMU.writeRegister(LSM6DS3_ACC_GYRO_TAP_CFG1, 0x40);
// Step Detector interrupt driven to INT1 pin
errorAccumulator += myIMU.writeRegister( LSM6DS3_ACC_GYRO_INT1_CTRL, 0x10 );
if( errorAccumulator )
{
Serial.println("Problem configuring the device.");
}
else
{
Serial.println("Device O.K.");
}
delay(200);
}
void loop()
{
uint8_t readDataByte = 0;
uint16_t stepsTaken = 0;
//Read the 16bit value by two 8bit operations
myIMU.readRegister(&readDataByte, LSM6DS3_ACC_GYRO_STEP_COUNTER_H);
stepsTaken = ((uint16_t)readDataByte) << 8;
myIMU.readRegister(&readDataByte, LSM6DS3_ACC_GYRO_STEP_COUNTER_L);
stepsTaken |= readDataByte;
//Display steps taken
Serial.print("Steps taken: ");
Serial.println(stepsTaken);
//Wait 1 second
delay(1000);
}
반응형
'개발자 > Arduino' 카테고리의 다른 글
Nano 33 IoT 보드 간단한 서버 만들고 AP로 동작 (0) | 2020.10.03 |
---|---|
Nano 33 IoT 보드 WiFi 스캔 코드 (0) | 2020.10.03 |
nano 33 IoT 보드에 0.96 ssd1306 i2c OLED 연결하기 (0) | 2020.09.29 |
ssd1306 Oled 화면 안 나올 때 점검 사항 (0) | 2020.09.29 |
고정밀 온도 습도 센서 DHT21 AM2301 Digital Temperature Humidity Sensor (0) | 2020.09.22 |
nano 33 IoT 보드로 구현한 스마트 가든 예제 (0) | 2020.09.21 |
Arduino Nano 33 IoT 개발 가이드 1-1 Blink Test (0) | 2020.09.18 |
컴퓨터에서 직접 Arduino 제어하는 Firmata 사용법 (3) | 2020.09.17 |
더욱 좋은 정보를 제공하겠습니다.~ ^^