Skip to content
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

Softwarewire #82

Open
wants to merge 12 commits into
base: master
Choose a base branch
from
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
/*
BME280_I2C_SoftwareWire_Test.ino

This code shows how to record data from the BME280 environmental sensor
using I2C SoftwareWire interface. This file is an example file, part of the Arduino
BME280 library.

GNU General Public License

Written: Dec 30 2015.
Last Updated: Oct 07 2017.

Connecting the BME280 Sensor:
Sensor -> Board
-----------------------------
Vin (Voltage In) -> 3.3V
Gnd (Ground) -> Gnd
SDA (Serial Data) -> 2
SCK (Serial Clock) -> 3

*/

#include <BME280I2CSoftwareWire.h>
#include <SoftwareWire.h>

#define SERIAL_BAUD 115200

#define SDA 2
#define SCK 3

SoftwareWire softwareWire(SDA, SCK);


BME280I2CSoftwareWire bme(softwareWire); // Default : forced mode, standby time = 1000 ms
// Oversampling = pressure ×1, temperature ×1, humidity ×1, filter off,

//////////////////////////////////////////////////////////////////
void setup()
{
Serial.begin(SERIAL_BAUD);

while(!Serial) {} // Wait

softwareWire.begin();

while(!bme.begin())
{
Serial.println("Could not find BME280 sensor!");
delay(1000);
}

switch(bme.chipModel())
{
case BME280::ChipModel_BME280:
Serial.println("Found BME280 sensor! Success.");
break;
case BME280::ChipModel_BMP280:
Serial.println("Found BMP280 sensor! No Humidity available.");
break;
default:
Serial.println("Found UNKNOWN sensor! Error!");
}
}

//////////////////////////////////////////////////////////////////
void loop()
{
printBME280Data(&Serial);
delay(500);
}

//////////////////////////////////////////////////////////////////
void printBME280Data
(
Stream* client
)
{
float temp(NAN), hum(NAN), pres(NAN);

BME280::TempUnit tempUnit(BME280::TempUnit_Celsius);
BME280::PresUnit presUnit(BME280::PresUnit_Pa);

bme.read(pres, temp, hum, tempUnit, presUnit);

client->print("Temp: ");
client->print(temp);
client->print("°"+ String(tempUnit == BME280::TempUnit_Celsius ? 'C' :'F'));
client->print("\t\tHumidity: ");
client->print(hum);
client->print("% RH");
client->print("\t\tPressure: ");
client->print(pres);
client->println("Pa");

delay(1000);
}
2 changes: 0 additions & 2 deletions src/BME280.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,6 @@ of www.endmemo.com, altitude equation courtesy of NOAA, and dew point equation
courtesy of Brian McNoldy at http:https://andrew.rsmas.miami.edu.
*/

#include <Wire.h>

#include "BME280.h"


Expand Down
2 changes: 1 addition & 1 deletion src/BME280.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ along with this program. If not, see <http:https://www.gnu.org/licenses/>.
Written: Dec 30 2015.
Last Updated: Oct 07 2017.

This code is licensed under the GNU LGPL and is open for ditrbution
This code is licensed under the GNU LGPL and is open for distrbution
and copying in accordance with the license.
This header must be included in any derived code or copies of the code.

Expand Down
10 changes: 8 additions & 2 deletions src/BME280I2C.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,13 @@ of www.endmemo.com, altitude equation courtesy of NOAA, and dew point equation
courtesy of Brian McNoldy at http:https://andrew.rsmas.miami.edu.
*/

#include <Wire.h>

#include "BME280I2C.h"

#include "Config.h"

#ifdef USING_WIRE
#include <Wire.h>
#endif

/****************************************************************/
BME280I2C::BME280I2C
Expand Down Expand Up @@ -61,6 +64,7 @@ const BME280I2C::Settings& BME280I2C::getSettings() const
}


#ifdef USING_WIRE
/****************************************************************/
bool BME280I2C::WriteRegister
(
Expand Down Expand Up @@ -100,3 +104,5 @@ bool BME280I2C::ReadRegister

return ord == length;
}

#endif
2 changes: 1 addition & 1 deletion src/BME280I2C.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ along with this program. If not, see <http:https://www.gnu.org/licenses/>.
Written: Sep 19 2016.
Last Updated: Oct 07 2017.

This code is licensed under the GNU LGPL and is open for ditrbution
This code is licensed under the GNU LGPL and is open for distrbution
and copying in accordance with the license.
This header must be included in any derived code or copies of the code.

Expand Down
90 changes: 90 additions & 0 deletions src/BME280I2CSoftwareWire.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
/*
BME280I2CSoftwareWireI2C.cpp
This code records data from the BME280I2CSoftwareWire sensor and provides an API.
This file is part of the Arduino BME280I2CSoftwareWire library.
Copyright (C) 2016 Tyler Glenn

This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with this program. If not, see <http:https://www.gnu.org/licenses/>.

Written: Dec 30 2015.
Last Updated: Jan 1 2016. - Happy New year!

This header must be included in any derived code or copies of the code.

Based on the data sheet provided by Bosch for the BME280I2CSoftwareWire environmental sensor,
calibration code based on algorithms providedBosch, some unit conversations courtesy
of www.endmemo.com, altitude equation courtesy of NOAA, and dew point equation
courtesy of Brian McNoldy at http:https://andrew.rsmas.miami.edu.
*/

#include "Config.h"

#ifdef USING_SOFTWARE_WIRE

#include "SoftwareWire.h"

#include "BME280I2CSoftwareWire.h"


/****************************************************************/
BME280I2CSoftwareWire::BME280I2CSoftwareWire
(
SoftwareWire& softwareWire,
const Settings& settings
):BME280I2C(settings),
m_softwareWire(softwareWire)
{
}

/****************************************************************/
bool BME280I2CSoftwareWire::WriteRegister
(
uint8_t addr,
uint8_t data
)
{
m_softwareWire.beginTransmission(getSettings().bme280Addr);
m_softwareWire.write(addr);
m_softwareWire.write(data);
m_softwareWire.endTransmission();

return true; // TODO: Chech return values from wire calls.
}


/****************************************************************/
bool BME280I2CSoftwareWire::ReadRegister
(
uint8_t addr,
uint8_t data[],
uint8_t length
)
{
uint8_t ord(0);

m_softwareWire.beginTransmission(getSettings().bme280Addr);
m_softwareWire.write(addr);
m_softwareWire.endTransmission();

m_softwareWire.requestFrom(static_cast<uint8_t>(getSettings().bme280Addr), length);

while(m_softwareWire.available())
{
data[ord++] = m_softwareWire.read();
}

return ord == length;
}

#endif
69 changes: 69 additions & 0 deletions src/BME280I2CSoftwareWire.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
/*
BME280I2CSoftwareWire.h
This code records data from the BME280 sensor and provides an API.
This file is part of the Arduino BME280 library.
Copyright (C) 2016 Tyler Glenn

This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with this program. If not, see <http:https://www.gnu.org/licenses/>.

Written: Mar 13 2018.

This code is licensed under the GNU LGPL and is open for distrbution
and copying in accordance with the license.
This header must be included in any derived code or copies of the code.

Based on the data sheet provided by Bosch for the Bme280 environmental sensor.
*/

#ifndef TG_BME_280_I2C_SOFTWARE_WIRE_H
#define TG_BME_280_I2C_SOFTWARE_WIRE_H

#include "BME280I2C.h"

class SoftwareWire;

//////////////////////////////////////////////////////////////////
/// BME280I2CSoftwareWire - SoftwareWire I2C Implementation of BME280.
class BME280I2CSoftwareWire: public BME280I2C
{

public:

///////////////////////////////////////////////////////////////
/// Constructor used to create the class. All parameters have
/// default values.
BME280I2CSoftwareWire(
SoftwareWire& softwareWire,
const BME280I2C::Settings& settings = BME280I2C::Settings());


protected:
private:
SoftwareWire& m_softwareWire;

//////////////////////////////////////////////////////////////////
/// Write values to BME280 registers.
virtual bool WriteRegister(
uint8_t addr,
uint8_t data);

/////////////////////////////////////////////////////////////////
/// Read values from BME280 registers.
virtual bool ReadRegister(
uint8_t addr,
uint8_t data[],
uint8_t length);

};
#endif // TG_BME_280_I2C_H
2 changes: 2 additions & 0 deletions src/BME280I2C_BRZO.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ courtesy of Brian McNoldy at http:https://andrew.rsmas.miami.edu.

#include "BME280I2C_BRZO.h"

#include "Config.h"

#ifdef USING_BRZO

#include "brzo_i2c.h"
Expand Down
2 changes: 1 addition & 1 deletion src/BME280I2C_BRZO.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ along with this program. If not, see <http:https://www.gnu.org/licenses/>.
Written: Sep 19 2016.
Last Updated: Oct 07 2017.

This code is licensed under the GNU LGPL and is open for ditrbution
This code is licensed under the GNU LGPL and is open for distrbution
and copying in accordance with the license.
This header must be included in any derived code or copies of the code.

Expand Down
8 changes: 7 additions & 1 deletion src/BME280Spi.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,14 @@ of www.endmemo.com, altitude equation courtesy of NOAA, and dew point equation
courtesy of Brian McNoldy at http:https://andrew.rsmas.miami.edu.
*/

#include "Arduino.h"
#include "BME280Spi.h"

#include "Config.h"

#ifdef USING_SPI

#include <SPI.h>
#include "Arduino.h"

/****************************************************************/
BME280Spi::BME280Spi
Expand Down Expand Up @@ -132,3 +136,5 @@ bool BME280Spi::WriteRegister

return true;
}

#endif
2 changes: 1 addition & 1 deletion src/BME280SpiSw.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ along with this program. If not, see <http:https://www.gnu.org/licenses/>.
Written: Dec 18 2016. - Happy Holidays!
Last Updated: Oct 07 2017.

This code is licensed under the GNU LGPL and is open for ditrbution
This code is licensed under the GNU LGPL and is open for distrbution
and copying in accordance with the license.
This header must be included in any derived code or copies of the code.

Expand Down
Loading