Skip to content

Commit

Permalink
Add v3 library function to set alternate I2C addr
Browse files Browse the repository at this point in the history
Illustrate how to do this for LIDAR-Lite v3

Change-Id: I89d6f14d86937c0d8dd61ee26e64abcb8d334184
  • Loading branch information
jmseitz committed Nov 15, 2018
1 parent 080f81c commit 7cfff77
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 0 deletions.
38 changes: 38 additions & 0 deletions src/LIDARLite.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,44 @@ void LIDARLite::configure(int configuration, char lidarliteAddress)
}
} /* LIDARLite::configure */

/*------------------------------------------------------------------------------
Set I2C Address
Set Alternate I2C Device Address. See Operation Manual for additional info.
Parameters
------------------------------------------------------------------------------
newAddress: desired secondary I2C device address
disableDefault: a non-zero value here means the default 0x62 I2C device
address will be disabled.
lidarliteAddress: Default 0x62. Fill in new address here if changed. See
operating manual for instructions.
------------------------------------------------------------------------------*/
void LIDARLite::setI2Caddr(char newAddress, char disableDefault, char lidarliteAddress)
{
byte dataBytes[2];

// Read UNIT_ID serial number bytes and write them into I2C_ID byte locations
read ((0x16 | 0x80), 2, dataBytes, false, lidarliteAddress);
write(0x18, dataBytes[0], lidarliteAddress);
write(0x19, dataBytes[1], lidarliteAddress);

// Write the new I2C device address to registers
dataBytes[0] = newAddress;
write(0x1a, dataBytes[0], lidarliteAddress);

// Enable the new I2C device address using the default I2C device address
dataBytes[0] = 0;
write(0x1e, dataBytes[0], lidarliteAddress);

// If desired, disable default I2C device address (using the new I2C device address)
if (disableDefault)
{
dataBytes[0] = (1 << 3); // set bit to disable default address
write(0x1e, dataBytes[0], newAddress);
}
} /* LIDARLite::setI2Caddr */

/*------------------------------------------------------------------------------
Reset
Expand Down
1 change: 1 addition & 0 deletions src/LIDARLite.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ class LIDARLite
LIDARLite();
void begin(int = 0, bool = false, char = LIDARLITE_ADDR_DEFAULT);
void configure(int = 0, char = LIDARLITE_ADDR_DEFAULT);
void setI2Caddr(char, char, char = LIDARLITE_ADDR_DEFAULT);
void reset(char = LIDARLITE_ADDR_DEFAULT);
int distance(bool = true, char = LIDARLITE_ADDR_DEFAULT);
void write(char, char, char = LIDARLITE_ADDR_DEFAULT);
Expand Down

0 comments on commit 7cfff77

Please sign in to comment.