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

Brzo I2C support. #33

Merged
merged 2 commits into from
Sep 20, 2017
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Now the brzo_i2c library on ESP8266 supported
  • Loading branch information
alexshavlovsky committed Sep 9, 2017
commit c6268e2360f1efd0d0f99d197a778eb2abaa26ec
21 changes: 12 additions & 9 deletions examples/BME_280_BRZO_I2C_Test/BME_280_BRZO_I2C_Test.ino
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@
/*
BME280 I2C Test.ino
BME280 BRZO I2C Test.ino
This code shows how to record data from the BME280 environmental sensor
using I2C interface. This file is an example file, part of the Arduino
BME280 library.
using I2C interface and https://github.com/pasko-zh/brzo_i2c library
on ESP8266.
This file is an example file, part of the Arduino BME280 library.

Copyright (C) 2016 Tyler Glenn
Forked by Alex Shavlovsky
to support https://github.com/pasko-zh/brzo_i2c library on ESP8266.

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
Expand All @@ -26,24 +30,23 @@ Sensor -> Board
-----------------------------
Vin (Voltage In) -> 3.3V
Gnd (Ground) -> Gnd
SDA (Serial Data) -> A4 on Uno/Pro-Mini, 20 on Mega2560/Due, 2 Leonardo/Pro-Micro
SCK (Serial Clock) -> A5 on Uno/Pro-Mini, 21 on Mega2560/Due, 3 Leonardo/Pro-Micro
SDA (Serial Data) -> D2 on ESP8266
SCK (Serial Clock) -> D1 on ESP8266

*/

/* ==== Includes ==== */
#include <BME280I2C.h>
#include <Wire.h> // Needed for legacy versions of Arduino.
#include <BME280BRZO_I2C.h>
/* ==== END Includes ==== */

/* ==== Defines ==== */
#define SERIAL_BAUD 115200
/* ==== END Defines ==== */

/* ==== Global Variables ==== */
BME280I2C bme; // Default : forced mode, standby time = 1000 ms
BME280BRZO_I2C bme; // Default : forced mode, standby time = 1000 ms
// Oversampling = pressure ×1, temperature ×1, humidity ×1, filter off,
bool metric = false;
bool metric = true;
/* ==== END Global Variables ==== */


Expand Down
66 changes: 28 additions & 38 deletions src/BME280BRZO_I2C.cpp
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
/*
BME280I2CI2C.cpp
This code records data from the BME280I2C sensor and provides an API.
This file is part of the Arduino BME280I2C library.
BME280BRZO_I2C.cpp
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
Forked by Alex Shavlovsky
to support https://github.com/pasko-zh/brzo_i2c library on ESP8266.

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
Expand All @@ -22,18 +25,17 @@ 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 BME280I2C environmental sensor,
Based on the data sheet provided by Bosch for the BME280BRZO_I2C 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 https://andrew.rsmas.miami.edu.
*/

#include <Wire.h>

#include "BME280I2C.h"
#include "brzo_i2c.h"
#include "BME280BRZO_I2C.h"

/****************************************************************/
BME280I2C::BME280I2C
BME280BRZO_I2C::BME280BRZO_I2C
(
uint8_t tosr,
uint8_t hosr,
Expand All @@ -50,73 +52,61 @@ BME280I2C::BME280I2C


/****************************************************************/
bool BME280I2C::WriteRegister
bool BME280BRZO_I2C::WriteRegister
(
uint8_t addr,
uint8_t data
)
{
Wire.beginTransmission(bme_280_addr);
Wire.write(addr);
Wire.write(data);
Wire.endTransmission();

return true; // TODO: Chech return values from wire calls.
uint8_t bf[2];
bf[0] = addr;
bf[1] = data;
brzo_i2c_start_transaction(bme_280_addr, I2C_CLOCK_RATE);
brzo_i2c_write(bf, 2, false);
return (brzo_i2c_end_transaction()==0);
}


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

Wire.beginTransmission(bme_280_addr);
Wire.write(addr);
Wire.endTransmission();

Wire.requestFrom(bme_280_addr, length);

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

return ord == length;
brzo_i2c_start_transaction(bme_280_addr, I2C_CLOCK_RATE);
brzo_i2c_write(&addr, 1, true);
brzo_i2c_read(data, length, false);
brzo_i2c_end_transaction();
return (brzo_i2c_end_transaction()==0);
}


/****************************************************************/
#if defined(ARDUINO_ARCH_ESP8266)
bool BME280I2C::begin
bool BME280BRZO_I2C::begin
(
int SDA,
int SCL
)
{
// allow config of pins
Wire.begin(SDA,SCL);

brzo_i2c_setup(SDA,SCL,I2C_ACK_TIMEOUT);
return BME280::Initialize();
}


/****************************************************************/
bool BME280I2C::begin()
bool BME280BRZO_I2C::begin()
{
return Initialize();
}
#endif


/****************************************************************/
bool BME280I2C::Initialize()
bool BME280BRZO_I2C::Initialize()
{
Wire.begin();

brzo_i2c_setup(D2,D1,I2C_ACK_TIMEOUT);
return BME280::Initialize();
}
25 changes: 18 additions & 7 deletions src/BME280BRZO_I2C.h
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
/*
BME280I2C.h
BME280BRZO_I2C.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
Forked by Alex Shavlovsky
to support https://github.com/pasko-zh/brzo_i2c library on ESP8266.

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
Expand All @@ -26,22 +29,30 @@ 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_H
#define TG_BME_280_I2C_H
#ifndef BME280BRZO_I2C_H
#define BME280BRZO_I2C_H

#ifndef I2C_CLOCK_RATE
#define I2C_CLOCK_RATE 400
#endif

#ifndef I2C_ACK_TIMEOUT
#define I2C_ACK_TIMEOUT 2000
#endif

#include "BME280.h"

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

public:

///////////////////////////////////////////////////////////////
/// Constructor used to create the class. All parameters have
/// default values.
BME280I2C(
BME280BRZO_I2C(
uint8_t tosr = 0x1,
uint8_t hosr = 0x1,
uint8_t posr = 0x1,
Expand Down Expand Up @@ -87,4 +98,4 @@ class BME280I2C: public BME280
uint8_t length);

};
#endif // TG_BME_280_I2C_H
#endif // BME280BRZO_I2C_H