Skip to content

Commit bc6b044

Browse files
committed
Ability to specify I2C pins in .begin()
1 parent fa686db commit bc6b044

File tree

3 files changed

+14
-11
lines changed

3 files changed

+14
-11
lines changed

library.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
name=SparkFun LSM6DS3 Breakout
2-
version=1.0.3
2+
version=1.0.4
33
author=SparkFun Electronics <[email protected]>
44
maintainer=SparkFun Electronics <sparkfun.com>
55
sentence=A library to drive the STmicro LSM6DS3 by SPI or I2C.

src/SparkFunLSM6DS3.cpp

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ Distributed as-is; no warranty is given.
4545
// Default construction is I2C mode, address 0x6B.
4646
//
4747
//****************************************************************************//
48-
LSM6DS3Core::LSM6DS3Core( uint8_t busType, uint8_t inputArg) : commInterface(I2C_MODE), I2CAddress(0x6B), chipSelectPin(10)
48+
LSM6DS3Core::LSM6DS3Core( uint8_t busType, uint8_t inputArg ) : commInterface(I2C_MODE), I2CAddress(0x6B), chipSelectPin(10)
4949
{
5050
commInterface = busType;
5151
if( commInterface == I2C_MODE )
@@ -59,15 +59,18 @@ LSM6DS3Core::LSM6DS3Core( uint8_t busType, uint8_t inputArg) : commInterface(I2C
5959

6060
}
6161

62-
status_t LSM6DS3Core::beginCore(void)
62+
status_t LSM6DS3Core::beginCore( int8_t inputSDA, int8_t inputSCL )
6363
{
6464
status_t returnError = IMU_SUCCESS;
65-
uint32_t spiPortSpeed = 5000000;
65+
uint32_t spiPortSpeed = 5000000;
6666

6767
switch (commInterface) {
6868

6969
case I2C_MODE:
70-
Wire.begin();
70+
if( inputSDA != -1 && inputSCL != -1 )
71+
Wire.begin( inputSDA, inputSCL );
72+
else
73+
Wire.begin();
7174
break;
7275

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

386389
//Begin the inherited core. This gets the physical wires connected
387-
status_t returnError = beginCore();
390+
status_t returnError = beginCore(inputSDA,inputSCL);
388391

389392
// Copy the values from the user's settings into the output 'pSettingsYouWanted'
390393
// compare settings with 'pSettingsYouWanted' after 'begin' to see if anything changed

src/SparkFunLSM6DS3.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ class LSM6DS3Core
5858
LSM6DS3Core( uint8_t, uint8_t );
5959
~LSM6DS3Core() = default;
6060

61-
status_t beginCore( void );
61+
status_t beginCore( int8_t, int8_t );
6262

6363
//The following utilities read and write to the IMU
6464

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

8282
//Change to base page
8383
status_t basePage( void );
84-
SPISettings mySpiSettings;
84+
SPISettings mySpiSettings;
8585

8686
private:
8787

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

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

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

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

0 commit comments

Comments
 (0)