Skip to content

Ability to specify I2C pins in .begin() #23

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion library.properties
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name=SparkFun LSM6DS3 Breakout
version=1.0.3
version=1.0.4
author=SparkFun Electronics <[email protected]>
maintainer=SparkFun Electronics <sparkfun.com>
sentence=A library to drive the STmicro LSM6DS3 by SPI or I2C.
15 changes: 9 additions & 6 deletions src/SparkFunLSM6DS3.cpp
Original file line number Diff line number Diff line change
@@ -45,7 +45,7 @@ Distributed as-is; no warranty is given.
// Default construction is I2C mode, address 0x6B.
//
//****************************************************************************//
LSM6DS3Core::LSM6DS3Core( uint8_t busType, uint8_t inputArg) : commInterface(I2C_MODE), I2CAddress(0x6B), chipSelectPin(10)
LSM6DS3Core::LSM6DS3Core( uint8_t busType, uint8_t inputArg ) : commInterface(I2C_MODE), I2CAddress(0x6B), chipSelectPin(10)
{
commInterface = busType;
if( commInterface == I2C_MODE )
@@ -59,15 +59,18 @@ LSM6DS3Core::LSM6DS3Core( uint8_t busType, uint8_t inputArg) : commInterface(I2C

}

status_t LSM6DS3Core::beginCore(void)
status_t LSM6DS3Core::beginCore( int8_t inputSDA, int8_t inputSCL )
{
status_t returnError = IMU_SUCCESS;
uint32_t spiPortSpeed = 5000000;
uint32_t spiPortSpeed = 5000000;

switch (commInterface) {

case I2C_MODE:
Wire.begin();
if( inputSDA != -1 && inputSCL != -1 )
Wire.begin( inputSDA, inputSCL );
else
Wire.begin();
break;

case SPI_MODE:
@@ -378,13 +381,13 @@ LSM6DS3::LSM6DS3( uint8_t busType, uint8_t inputArg ) : LSM6DS3Core( busType, in
// "myIMU.settings.accelEnabled = 1;" to configure before calling .begin();
//
//****************************************************************************//
status_t LSM6DS3::begin(SensorSettings* pSettingsYouWanted)
status_t LSM6DS3::begin(SensorSettings* pSettingsYouWanted, int8_t inputSDA, int8_t inputSCL)
{
//Check the settings structure values to determine how to setup the device
uint8_t dataToWrite = 0; //Temporary variable

//Begin the inherited core. This gets the physical wires connected
status_t returnError = beginCore();
status_t returnError = beginCore(inputSDA,inputSCL);

// Copy the values from the user's settings into the output 'pSettingsYouWanted'
// compare settings with 'pSettingsYouWanted' after 'begin' to see if anything changed
8 changes: 4 additions & 4 deletions src/SparkFunLSM6DS3.h
Original file line number Diff line number Diff line change
@@ -58,7 +58,7 @@ class LSM6DS3Core
LSM6DS3Core( uint8_t, uint8_t );
~LSM6DS3Core() = default;

status_t beginCore( void );
status_t beginCore( int8_t, int8_t );

//The following utilities read and write to the IMU

@@ -81,7 +81,7 @@ class LSM6DS3Core

//Change to base page
status_t basePage( void );
SPISettings mySpiSettings;
SPISettings mySpiSettings;

private:

@@ -146,11 +146,11 @@ class LSM6DS3 : public LSM6DS3Core

//Constructor generates default SensorSettings.
//(over-ride after construction if desired)
LSM6DS3( uint8_t busType = I2C_MODE, uint8_t inputArg = 0x6B );
LSM6DS3( uint8_t busType = I2C_MODE, uint8_t inputArg = 0x6B);
~LSM6DS3() = default;

//Call to apply SensorSettings
status_t begin(SensorSettings* pSettingsYouWanted = NULL);
status_t begin(SensorSettings* pSettingsYouWanted = NULL, int8_t inputSDA = -1, int8_t inputSCL = -1);

//Returns the raw bits from the sensor cast as 16-bit signed integers
int16_t readRawAccelX( void );