Use this forum to chat about hardware specific topics for the ESP8266 (peripherals, memory, clocks, JTAG, programming)
User avatar
By theMusicMan
#65093 Hi All

Trying to get the BMP280 temperature and pressure sensor working on my NodeMCU ESP8266 board, and I seem to be having issues!

Managed to get it working fine on the Arduino yesterday, but when I run the sketch on the ESP8266 I can't seem to get any output from the BMP280.

I wanted to check I have it wired correctly, becase on studying the Pinout diagram of the board, I cannot see which pins are assigned to SCL and SDA for the I2C pins. On the Arduino they are A4 and A5, but I am uncertain as to which are the correct I2C pins on the NodeMCU.

Can someone please confirm for me please which pins I should be using because at the moment the sketch is reporting 'Could not find a valid BMP280 sensor, check wiring!'

Here's the code I am using. Can anyone help please. Thanks

Code: Select all/***************************************************************************
  This is a library for the BMP280 humidity, temperature & pressure sensor

  Designed specifically to work with the Adafruit BMEP280 Breakout
  ----> http://www.adafruit.com/products/2651

  These sensors use I2C or SPI to communicate, 2 or 4 pins are required
  to interface.

  Adafruit invests time and resources providing this open source code,
  please support Adafruit andopen-source hardware by purchasing products
  from Adafruit!

  Written by Limor Fried & Kevin Townsend for Adafruit Industries.
  BSD license, all text above must be included in any redistribution
 ***************************************************************************/

#include <Wire.h>
#include <SPI.h>
#include <Adafruit_Sensor.h>
#include <Adafruit_BMP280.h>

#define BMP_SCK 13
#define BMP_MISO 12
#define BMP_MOSI 11
#define BMP_CS 10

int altitude;

Adafruit_BMP280 bme; // I2C
//Adafruit_BMP280 bme(BMP_CS); // hardware SPI
//Adafruit_BMP280 bme(BMP_CS, BMP_MOSI, BMP_MISO,  BMP_SCK);

void setup() {
  Serial.begin(9600);
  Serial.println(F("BMP280 test"));

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

void loop() {
  Serial.print("Temperature = ");
  Serial.print(bme.readTemperature()*9/5+32);
  Serial.println(" *f");

  Serial.print("Pressure = ");
  Serial.print(bme.readPressure() / 100);
  Serial.println(" mB");

  Serial.print("Approx altitude = ");
  Serial.print(bme.readAltitude(1035)); // this should be adjusted to your local forcase
  Serial.println(" m");

  Serial.println();
  delay(2000);
}
User avatar
By Mitchell QTT
#65147 Hope I can help.

You're using a NodeMCU board. I did some googling and checked my own code.
I could not find the default I2C pins but I may be able to point you in the direction.

1. Adafruit library uses 'wire.h' which will default the I2C pins to 'SDA' and 'SDC'.
I think they default to 2 and 14:

Code: Select allWire – The ESP8266 should work with any I2C sensor you can throw at it – just use the same Wire API calls you’re used to. There are a few differences:

Pin definition: The ESP2866 doesn’t actually have any hardware I2C pins – those labeled on the Thing are the default, but you can actually use any two pins as SDA and SCL. Calling Wire.begin() will assume pins 2 and 14 are SDA and SCL


Note that these absolute values '2' and '14' will map to D4 and D5 on your NodeMCU board.


2. You can manually set SDA and SCL to any other pin by calling Wire.begin([SDA], [SCL]).
I suggest using the D-mappings so your code corresponds to the D-numbers on your board.
Wire.begin(D4, D5);
for instance.

Does this help?
User avatar
By schufti
#65159 with the infos from
...\\esp8266\variants\nodemcu\pins_arduino.h

Code: Select all#define PIN_WIRE_SDA (4)
#define PIN_WIRE_SCL (5)

static const uint8_t SDA = PIN_WIRE_SDA;
static const uint8_t SCL = PIN_WIRE_SCL;

static const uint8_t LED_BUILTIN = 16;
static const uint8_t BUILTIN_LED = 16;

static const uint8_t D0   = 16;
static const uint8_t D1   = 5;
static const uint8_t D2   = 4;
static const uint8_t D3   = 0;
static const uint8_t D4   = 2;
static const uint8_t D5   = 14;
static const uint8_t D6   = 12;
static const uint8_t D7   = 13;
static const uint8_t D8   = 15;
static const uint8_t D9   = 3;
static const uint8_t D10  = 1;


on a correctly set up nodemcu project this defaults to sda=D2 (or gpio4) and scl=D1 (or gpio5)
as gpio4 and gpio5 don't have internal pull-up, don't forget to use external!