Skip to content

Commit

Permalink
Merge pull request xoseperez#1647 from CraigMarkwardt/bmx280-second-s…
Browse files Browse the repository at this point in the history
…ensor

sensors - allow a second BMX280 sensor
  • Loading branch information
xoseperez authored Mar 29, 2019
2 parents 175fcbf + 0f8f3a1 commit b74e02e
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 2 deletions.
9 changes: 7 additions & 2 deletions code/espurna/config/sensors.h
Original file line number Diff line number Diff line change
Expand Up @@ -158,9 +158,14 @@
#define BMX280_SUPPORT 0
#endif

#ifndef BMX280_ADDRESS
#define BMX280_ADDRESS 0x00 // 0x00 means auto
#ifndef BMX280_NUMBER
#define BMX280_NUMBER 2 // Number of sensors present. Either 1 or 2 allowed
#endif
#ifndef BMX280_ADDRESS
#define BMX280_ADDRESS 0x00 // 0x00 means auto (0x76 or 0x77 allowed) for sensor #0
#endif // If (BMX280_NUMBER == 2) and
// (BMX280_ADDRESS == 0x00) then sensor #1 is auto-discovered
// (BMX280_ADDRESS != 0x00) then sensor #1 is the unnamed address

#define BMX280_MODE 1 // 0 for sleep mode, 1 or 2 for forced mode, 3 for normal mode
#define BMX280_STANDBY 0 // 0 for 0.5ms, 1 for 62.5ms, 2 for 125ms
Expand Down
9 changes: 9 additions & 0 deletions code/espurna/sensor.ino
Original file line number Diff line number Diff line change
Expand Up @@ -484,6 +484,15 @@ void _sensorLoad() {
BMX280Sensor * sensor = new BMX280Sensor();
sensor->setAddress(BMX280_ADDRESS);
_sensors.push_back(sensor);

#if (BMX280_NUMBER == 2)
// Up to two BME sensors allowed on one I2C bus
BMX280Sensor * sensor2 = new BMX280Sensor();
// For second sensor, if BMX280_ADDRESS is 0x00 then auto-discover
// otherwise choose the other unnamed sensor address
sensor->setAddress( (BMX280_ADDRESS == 0x00) ? 0x00 : (0x76 + 0x77 - BMX280_ADDRESS));
_sensors.push_back(sensor2);
#endif
}
#endif

Expand Down

0 comments on commit b74e02e

Please sign in to comment.