BMP280 - code

BrunaoGati
Posts: 1
Joined: Thu Feb 25, 2021 12:42 am

BMP280 - code

Postby BrunaoGati » Thu Feb 25, 2021 1:01 am

Good evening guys! Hope you are well

I'm doing a project that uses a BMP280. When I tested this code with an Arduino Uno, it worked well. But, when I tried using the ESP32 I have these problems:
/*

In file included from sketch\BMP280_-_CODIGO.ino.cpp:1:0:
C:\Users\Bru\Documents\Arduino\libraries\I2C-Sensor-Lib_iLib\src/i2c.h: In constructor 'WirePlus::WirePlus()':
C:\Users\Bru\Documents\Arduino\libraries\I2C-Sensor-Lib_iLib\src/i2c.h:70:12: error: 'PORTC' was not declared in this scope
bitSet(PORTC, 4); // deactivate internal pull-ups for twi
^
C:\Users\Bru\AppData\Local\Arduino15\packages\esp32\hardware\esp32\1.0.4\cores\esp32/Arduino.h:89:30: note: in definition of macro 'bitSet'
#define bitSet(value, bit) ((value) |= (1UL << (bit)))
^
In file included from C:\Users\Bru\Desktop\BMP280_-_CODIGO\BMP280_-_CODIGO.ino:2:0:
C:\Users\Bru\Documents\Arduino\libraries\I2C-Sensor-Lib_iLib\src/i2c.h:73:5: error: 'TWBR' was not declared in this scope
TWBR = ((F_CPU / 400000L) - 16) / 2; // see twi_init in Wire/utility/twi.c
^
exit status 1
Error compiling for the ESP32 Dev Module

*/

I tested a MPU6050 in this ESP32 and it worked well. But the code I tried for the BMP280 didn't have the same lucky.

The code is:

"
#include <Wire.h>
#include "i2c.h"
#include "i2c_Sensor.h";
#include "i2c_BMP280.h"

BMP280 bmp280;

void setup()
{
Serial.begin(9600);

Serial.print("Situacao do BMP280: ");
if (bmp280.initialize()) Serial.println("BMP280 DETECTADO"); //Detected
else
{
Serial.println("BMP280 não detectado"); //Not detected
while (1) {}
}

//Medida para setar os dados
bmp280.setEnabled(0);
bmp280.triggerMeasurement();
}

void loop()
{
//Espera medicao
bmp280.awaitMeasurement();

//Declara temperatura e pega ela
float temperature;
bmp280.getTemperature(temperature);

//Pega a pressao em pascal
float pascal;
bmp280.getPressure(pascal);

static float meters, metersold;
bmp280.getAltitude(meters);
metersold = (metersold * 10 + meters)/11;

bmp280.triggerMeasurement();

Serial.print(" Alt média: ");
Serial.print(metersold);
Serial.print(" m; Alt atual: ");
Serial.print(meters);
Serial.print(" Pressao: ");
Serial.print(pascal);
Serial.print(" Pa; T: ");
Serial.print(temperature);
Serial.println(" C");


delay(100);
}

''
Do you have any suggestions that I could do to solve it?

From now, thank you for your time!

Att, Bruno

Who is online

Users browsing this forum: No registered users and 84 guests