logo elektroda
logo elektroda
X
logo elektroda

[Solved] Title: Nodemcu V3 Not Communicating with BME280 & BMP280 Sensors: Connection & Code Issues

zomb 4590 9
ADVERTISEMENT
Treść została przetłumaczona polish » english Zobacz oryginalną wersję tematu
  • #1 17010983
    zomb
    Level 8  
    Hello
    I have a bme280 sensor and the hell I can't get it to cooperate.

    It is connected to nodemcu v3.

    I do not know what's going on. I have 2 BME280 sensors and another 2 BMP280 and I have no reading of any of them.
    Other elements are rather ok, because I have a complex particulate matter sensor (PMS5003 + NodeMCU + DHT22 + LCD2x16) and everything works.


    The connection looks like this:

    BME - NodeMCU
    ---------------------
    VCC - 3.3V
    GND - GND
    SCL - D1
    SDA - D2


    Program code
    -------------------------

    
    #include 
    #include 
    #include 
    #include 
    #include 
    
    Adafruit_BME280 bme;
    
    void setup() {
      Serial.begin(9600);
      Wire.begin(D1, D2);
      Wire.setClock(100000);
    }
    
    void loop() {
    
      if (bme.begin()) {
        Serial.println("OK");  
      } 
      else  {
        Serial.println("DUPA");
      }
      delay (2000);
      
    }
    
    


    I also tried to connect the sensor to 3.3V on the Arduino Uno and also sneezes.
    What could be wrong?
  • ADVERTISEMENT
  • Helpful post
    #2 17011099
    piterek-23
    Level 33  
    Look for a program to scan devices connected to i2c
    Scan and see if it finds anything.
  • Helpful post
    #3 17011151
    chemik22
    Level 14  
    A common problem with the BME / P280 is that the library has a device address of 0x77 while these sensors may also have an address of 0x76 depending on the configuration.


    Go to the file Adafruit_BME280.h (or something like that) and look there in one of the first lines should be the address of the device and change from 0x76 to 0x77 (or vice versa) and it should go. If you use the Arduino IDE, unfortunately the library file (Adafruit_BME280.h) must be searched through Windows and edited in the notebook.


    And check to be sure, because in the definition of wire.begin (), the first argument is probably SDA and the second is SCL, and you have the opposite in the code ...


    Should be: Wire.begin (D2, D1)
  • ADVERTISEMENT
  • #4 17012419
    tos18
    Level 42  
    I use the library with the D1 mini wemos https://www.github.com/finitespace/BME280 For i2c you need to attach the library: #include . The rest in the library documentation.
    It runs on hardware i2c so wire.begin (); I have no parameters.
    Sensor address also defaults.
    Connection:
    power supply 3.3V
    SCL - D1
    SDA - D2
    GND - you know

    I put together something similar as the author, but I have PMS3003 and BME280 and they are read by wemos D1 mini (electrode gadget). It displays the data in the form of a simple html and issues a json package for other devices. The previous version with DHT22, GPY ... and oled display was much worse.
    The json data is received by the server and displays a nicer website and a TFT LCD display and a second wemos.
  • ADVERTISEMENT
  • #5 17012575
    zomb
    Level 8  
    Thank you gentlemen ... it has started ;-) ) and BME and BMP ;-) )

    1st scanner good thing
    2. in fact, there was an address 0x77 in the library ... I changed it

    and it's ok

    I have a question.
    why the sensor is visible only for the SCL-D1, SDA-D2 connection ??

    When connected to other exits, it is not visible (D3, D4).

    I have more devices plugged in and it would be more convenient for me to plug them into other outputs.

    PS. i also use PMS5003. for now, I have DHT22 plugged in and I want to exchange it for BME because it sometimes hangs. In addition, I have two more switches (LCD on / off and the second send / do not send data)
    ---------------
    Oh, ... here's an example of how a visitor plugs a sensor into D3-D4.
    http://robinw.de/2017/08/01/der-erste-sensor-bme280-am-nodemcu/
    For me, the scanner will not see anything in this configuration.
  • Helpful post
    #6 17012826
    piterek-23
    Level 33  
    After changing the pins for i2c, you also need to change the code.
  • #7 17013273
    zomb
    Level 8  
    My guess is that I change the i2c pins in the code in the library.
    I'm looking but I can't see anything that points to D1 (gpio5) and D2 (gpio4)
    any hint?

    BTW. Can communication via i2c take place with only one device? After i2c, it also communicates with 2x16 LCDs and I will use D1, D2 for this.

    I need to set two pairs of pins for i2c communication.
  • ADVERTISEMENT
  • Helpful post
    #8 17013281
    piterek-23
    Level 33  
    You can add multiple devices to i2c. The condition is that each device must have a different address.
  • #9 17013488
    zomb
    Level 8  
    They don't have separate addresses

    - bme 0x76
    - lcd 0x3F

    but both are visible (i2c scanner) only when plugged into D1 D2.

    How to make one of the devices visible on D3 D4?

    Added after 32 [minutes]:

    Okay, I already have it.
    I read in the i2c assumptions that many devices communicate on a common bus.

    I've plugged both in and the scanner can see both.
    thank you.
  • #10 17038810
    zomb
    Level 8  
    Changing the address from 0x77 to 0x76 in the library fixed the problem.
    Thank you

Topic summary

The discussion revolves around issues with connecting BME280 and BMP280 sensors to a NodeMCU V3. The user initially faced communication problems with the sensors, despite successful operation of other components. Key troubleshooting steps included using an I2C scanner to detect connected devices and adjusting the sensor address in the Adafruit_BME280 library from 0x77 to 0x76. The user also corrected the pin configuration in the code, ensuring that SDA and SCL were correctly assigned. After these adjustments, the sensors began functioning properly. The conversation also touched on the ability to connect multiple I2C devices on a common bus, provided they have unique addresses.
Summary generated by the language model.
ADVERTISEMENT