I recently bought a Wemos Lolin32 and a BMP280 for a school project. I'm having no luck connecting BMP280 with Lolin32. I connected,
SDA -> SDA (GPIO 21)
SCL -> SCL (GPIO 22)
VCC to a 3.3v pin
GND to GND
And used two types of I2C detect scripts on it but it does not return an address.
This is the default I2C detect code.
#include <Wire.h>
#include <i2cdetect.h>
void setup() {
Wire.begin();
Serial.begin(9600);
Serial.println("i2cdetect example\n");
Serial.print("Scanning address range 0x03-0x77\n\n");
}
void loop() {
i2cdetect(); // default range from 0x03 to 0x77
delay(2000);
}
Then I used the code below,
#include <Wire.h>
void setup() {
Wire.begin();
Serial.begin(115200);
Serial.println("\nI2C Scanner");
}
void loop() {
byte error, address;
int nDevices;
Serial.println("Scanning...");
nDevices = 0;
for(address = 1; address < 127; address++ ) {
Wire.beginTransmission(address);
error = Wire.endTransmission();
if (error == 0) {
Serial.print("I2C device found at address 0x");
if (address<16) {
Serial.print("0");
}
Serial.println(address,HEX);
nDevices++;
}
else if (error==4) {
Serial.print("Unknow error at address 0x");
if (address<16) {
Serial.print("0");
}
Serial.println(address,HEX);
}
}
if (nDevices == 0) {
Serial.println("No I2C devices found\n");
}
else {
Serial.println("done\n");
}
delay(5000);
}
I used the same BMP280 with my nano board and it returned 0x76 as the address but Wemos Lolin32 returns empty in both codes.
What could be the problem? Please help.
Did you just stop reading there? That tutorial goes on to suggest and demonstrate the use of alternate pins… might be worth trying.
My trouble with the LOLIN32 is not having a good idea yet of what GPIO pins are used - mine has a build-in OLED and I won't ever admit to how long trying to use digital 16 was making trouble only to finally realize it is used as the OLED reset.