Chat here is you are connecting ESP-xx type modules to existing AVR based Arduino

Moderator: igrr

User avatar
By Azat
#72431 Hello.
I have some BMP280 modules like this (robotdyn)
And can't connect it to any esp. I have no that problem with any other BMP280 module. How to connect it? Help me pleese.
I use NodeMCU with Arduino IDE.
NodeMCU - BMP280
3V-------------3V
GND----------GND
D1-------------SCK
D2-------------SDI
3V-------------CS
Code: Select all#include <Wire.h>
#include <ESP8266WiFi.h>
#include <Adafruit_Sensor.h>
#include <Adafruit_BMP280.h>
#include <SPI.h>
#include <ArduinoJson.h>

Adafruit_BMP280 bmp; // I2C

// Replace with your network details
const char* ssid = "ssid";
const char* password = "pwd";
float t, p;
char temperatureString[6];
char pressureString[7];

StaticJsonBuffer<300> JSONbuffer;
JsonObject& JSONencoder = JSONbuffer.createObject();
// Web Server on port 80
WiFiServer server(80);

// only runs once on boot
void setup() {
  // Initializing serial port for debugging purposes
  Serial.begin(115200);
  delay(10);
  //Wire.begin(0, 2);
  Wire.begin(5, 4); delay(10);
  Wire.setClock(100000);
  // Connecting to WiFi network
  Serial.println();
  Serial.print("Connecting to ");
  Serial.println(ssid);
 
  WiFi.begin(ssid, password);
 
  while (WiFi.status() != WL_CONNECTED) {
    delay(500);
    Serial.print(".");
  }
  Serial.println("");
  Serial.println("WiFi connected");
 
  // Starting the web server
  server.begin();
  Serial.println("Web server running. Waiting for the ESP IP...");
  delay(10000);
 
  // Printing the ESP IP address
  Serial.println(WiFi.localIP());
  Serial.println(F("BMP280 test"));

  if (!bmp.begin()) {
    Serial.println("Could not find a valid BMP280 sensor, check wiring!");
    while (1);
  }
}

void getWeather() {

    t = bmp.readTemperature();
    p = (bmp.readPressure() * 7.5006e-3);
    dtostrf(t, 5, 1, temperatureString);
    dtostrf(p, 6, 1, pressureString);
    delay(100);
 
}

// runs over and over again
void loop() {

  // Listenning for new clients 
  WiFiClient client = server.available();
 
  //StaticJsonBuffer<300> JSONbuffer;
  //JsonObject& JSONencoder = JSONbuffer.createObject();
 
  if (client) {
    Serial.println("New client");
    // bolean to locate when the http request ends
    boolean blank_line = true;
    while (client.connected()) {
      if (client.available()) {
        char c = client.read();
       
        if (c == '\n' && blank_line) {
            getWeather();
            JSONencoder["Place"] = "Mub, 7";
            JSONencoder["Snum"] = "1";
            JSONencoder["Temp"] = temperatureString;
            JSONencoder["Pres"] = pressureString;
            client.println("HTTP/1.1 200 OK");
            client.println("Content-Type: text/html");
            client.println("Connection: close");
            client.println();
            // your actual web page that displays temperature
            client.println("<!DOCTYPE HTML>");
            client.println("<html>");
            client.println("<head><meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\"></head>");
            client.println("<body>");
            String out;
            JSONencoder.printTo(out);
            client.println(out);
            client.println("</body></html>"); 
            break;
        }
        if (c == '\n') {
          // when starts reading a new line
          blank_line = true;
        }
        else if (c != '\r') {
          // when finds a character on the current line
          blank_line = false;
        }
      }
    } 
    // closing the client connection
    delay(1);
    client.stop();
    Serial.println("Client disconnected.");
  }
}

And I get in console
Code: Select allConnecting to ssid
..
WiFi connected
Web server running. Waiting for the ESP IP...
192.168.0.114
BMP280 test
Could not find a valid BMP280 sensor, check wiring!

Soft WDT reset

ctx: cont
sp: 3ffef760 end: 3ffef950 offset: 01b0

>>>stack>>>
3ffef910:  3ffe84c4 3ffee838 3ffef990 4020244c 
3ffef920:  3ffe89e8 7200a8c0 feefeffe feefeffe 
3ffef930:  3fffdad0 00000000 3ffee920 40204990 
3ffef940:  feefeffe feefeffe 3ffee930 40100718 
<<<stack<<<

 ets Jan  8 2013,rst cause:2, boot mode:(3,7)

load 0x4010f000, len 1384, room 16
tail 8
chksum 0x2d
csum 0x2d
v00000000
~ld

Thank you.
You do not have the required permissions to view the files attached to this post.
User avatar
By dragondaud
#72451 CS (chip select) is part of SPI, not I2C, and connecting it will silence the chip unless pulled high and probably tells the sensor you want to communicate using SPI, which requires SCK/SDO/SDI/CS whereas I2C just needs SDI/SCK. Additionally, if you device's ID isn't the default the library expects you can specify the correct ID during the initialization, like bmp.begin(0x76).