// void setup() {
// // put your setup code here, to run once:
// Serial.begin(115200);
// Serial.println("Hello, ESP32!");
// }
// // pin-21 SDA Pink
// // pin-22 SCL (6) Blue
// void loop() {
// // put your main code here, to run repeatedly:
// delay(10); // this speeds up the simulation
// }
// #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();
// Serial.println(bme.temperature);
// 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);
// }
/*
Rui Santos
Complete project details at https://RandomNerdTutorials.com/esp32-i2c-communication-arduino-ide/
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files.
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
*/
#include <Wire.h>
#include <Adafruit_Sensor.h>
#include <Adafruit_MPU6050.h>
#define I2C_SDA 21
#define I2C_SCL 22
#define SEALEVELPRESSURE_HPA (1013.25)
TwoWire I2CBME = TwoWire(0);
Adafruit_MPU6050 bme;
unsigned long delayTime;
void setup() {
Serial.begin(115200);
Serial.println(F("BME280 test"));
I2CBME.begin(I2C_SDA, I2C_SCL, 100000);
bool status;
// default settings
// (you can also pass in a Wire library object like &Wire2)
status = bme.begin(0x68, &I2CBME);
if (!status) {
Serial.println("Could not find a valid BME280 sensor, check wiring!");
while (1);
}
Serial.println("-- Default Test --");
delayTime = 1000;
Serial.println();
}
void loop() {
// bme.update();
printValues();
delay(delayTime);
}
void printValues() {
Serial.print("Temperature = ");
Serial.print(bme.temperature);
// Serial.println(" *C");
// Convert temperature to Fahrenheit
/*Serial.print("Temperature = ");
Serial.print(1.8 * bme.readTemperature() + 32);
Serial.println(" *F");*/
// Serial.print("Pressure = ");
// Serial.print(bme.readPressure() / 100.0F);
// Serial.println(" hPa");
// Serial.print("Approx. Altitude = ");
// Serial.print(bme.readAltitude(SEALEVELPRESSURE_HPA));
// Serial.println(" m");
// Serial.print("Humidity = ");
// Serial.print(bme.readHumidity());
// Serial.println(" %");
Serial.println();
}