Giter Site home page Giter Site logo

Comments (6)

caternuson avatar caternuson commented on August 18, 2024

Only call begin() once for each sensor in setup. There's no need to call it again to "switch" between them.

from adafruit_bmp280_library.

ilya7zz avatar ilya7zz commented on August 18, 2024

It's bad that you can't call begin() multiple times. Most, seeing this flaw in the library, said that the implementation was bad and needed some work.
I need to implement a task where there are many I2C devices. Everyone has different pins and different addresses. Without calling begin () again after calling Wire.begin (SDA, SCL), it is not possible to change the sensor initialization address.

An example of my code working:

void initLCD() {
  Wire.begin (SDA, SCL); //D2,D1 Выбираем дисплей
}


void getBMP1() {
  Wire.begin (14, 12); //D5,D6 Wire.begin(esda, escl);
  if (!bmp.begin(0x76)) {
    Serial.print("\nДатчик 0x76 не найден. Проверить интерфейс I2C или адрес.");
    sendNoDataLCD();
  }
  else {
    temperature = bmp.readTemperature();
    pressure_Hg = pressure * 0.0075006F; //1Па = 0.0075006168 мм рт.ст.
    sendDataLCD1();
  }
}

void getBMP2() {...}

void getBMP3() {
  Wire.begin (13, 2); //D7,D4 Wire.begin(esda, escl); где в скобках указаны пины!
  if (!bmp.begin(0x77)) Serial.println("\nДатчик 0x77 не найден. Проверить интерфейс I2C или адрес.");
  else {
    temperature = bmp.readTemperature();
    pressure_Hg = pressure * 0.0075006F; 
    sendDataLCD3();
  }
}

void getBMP4() {...}

void sendDataLCD() {
  initLCD();
  lcd.setCursor(0,0);
  lcd.print(temperature, 2);
  }
  lcd.setCursor(0,1);
  lcd.print(pressure_Hg, 1);
  lcd.print("mmHg");
}

void sendNoDataLCD() {
  initLCD();
  lcd.clear();
  lcd.setCursor(0,0);
  lcd.print("  No Connected  ");
}

from adafruit_bmp280_library.

caternuson avatar caternuson commented on August 18, 2024

I need to implement a task where there are many I2C devices.

This library supports multiple sensors. Call begin() once for each instance.

Everyone has different pins and different addresses

Why do they have different pins? Are they not all on the same I2C bus?

The example above is not complete. Where are your void setup() and void loop()?

from adafruit_bmp280_library.

ilya7zz avatar ilya7zz commented on August 18, 2024

This library supports multiple sensors. Call begin() once for each instance.

If I unplug the sensor and plug it back in, it won't work! So I call begin() before every read!

Why do they have different pins? Are they not all on the same I2C bus?

Because no more than two sensors can be connected to one bus.

The example above is not complete. Where are your void setup() and void loop()?

void setup() - like everyone else.
void loop() - calls the measurement script with an interval of once per second. The project is large, it makes no sense to upload it entirely. I have shown the used construction to show that the library is not working properly.

from adafruit_bmp280_library.

ladyada avatar ladyada commented on August 18, 2024

you have to use a multiplexor or something, what you're doing is not supported - call begin() once per sensor.

from adafruit_bmp280_library.

caternuson avatar caternuson commented on August 18, 2024

@ilya7zz You can try the 2.4.1 release when it becomes available:
https://github.com/adafruit/Adafruit_BMP280_Library/releases/tag/2.4.1
It adds the suggested basic checks for the dynamic memory allocation. Agree that doing that basic check is generally a good idea and worth adding. But no guarantee it will solve the issues for your use case.

from adafruit_bmp280_library.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.