Hi
I am probably missing something really obvious , but have hit a dead end trying to resolve issue this so hoping you guys can help !
I have an Expresiff ESP32-S breadboarded with an BME280 sensor connected as per the BuildWeb Servers tutorial.
Running the following code from the Arduino IDE I get the sensor data output to the serial monitor as expected implying thew sensor is found ok. The data looks correct and varies as expected.
Arduino IDE Code :
#include <Wire.h>
#include <Adafruit_Sensor.h>
#include <Adafruit_BME280.h>
#define SEALEVELPRESSURE_HPA (1013.25)
#define LED 2
Adafruit_BME280 bme; // I2C
unsigned long delayTime;
void setup() {
Serial.begin(9600);
pinMode(LED, OUTPUT);
Serial.println(F(“BME280 test”));
bool status;
// default settings
// (you can also pass in a Wire library object like &Wire2)
status = bme.begin(0x76);
if (!status) {
Serial.println(“Could not find a valid BME280 sensor, check wiring!”);
while (1);
}
Serial.println(“– Default Test –“);
delayTime = 5000;
Serial.println();
}
void loop() {
printValues();
digitalWrite(LED, HIGH);
delay(delayTime);
digitalWrite(LED, LOW);
delay(delayTime);
}
void printValues() {
Serial.print(“Temperature = “);
Serial.print(bme.readTemperature());
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();
}
To me this proves the ESP is ok , the BME is ok and the wiring ok ?
Then I run this code ( same intended functionality ) from VSCode/PlatformIO :
#include <Arduino.h>
#include <SPI.h>
#include <Wire.h>
#include <Adafruit_BME280.h>
#include <Adafruit_Sensor.h>
Adafruit_BME280 bme280; // I2C
void setup() {
Serial.begin(9600);
Serial.println(F(“BME280 test”));
if (!bme280.begin(0x76)) {
Serial.println(“Could not find a valid BME280 sensor, check wiring!”);
while (1);
}
}
void loop() {
}
It prints “Could not find a valid BME280 sensor, check wiring!” in the serial monitor.
platformio.ini :
[env:fm-devkit]
platform = espressif32
board = fm-devkit
framework = arduino
lib_deps =
adafruit/Adafruit BME280 Library@^2.1.2
adafruit/Adafruit Unified Sensor@^1.1.4
I am confident I have the same librarys loaded in each environment.
Can anyone explain why one IDE ( Arduino ) can see the sensor , but not the other ( VSCode )?
Thanks
Hi Graham.
That’ a very weird issue.
I’ve just tried your code with an ESP32 and a BME280 sensor and it works just fine on VS Code.
Do you have more than one board connected to your computer? You may be uploading code to another board than the one that has the BME280 wired.
Regards,
Sara
Thanks for the reply.
I confirm only one ESP32 is connected , and I make sure the IDE in use is stopped fully before changing to the other one in case of conflicts.
When using VSCode , the sketch compiles and uploads sucessfully and clearly starts running – I have even had it turning an LED on and off to prove code has been loaded and is running the latest version.
As well as the Adafruit BME280 library and the Adafruit Unified Sensor Library installed, I have libraries for the DHT22 sensor installed in the VSCode IDE, I will try uninstalling these next but as they are not referenced in the sketch I dont see why they should matter.
Thanks
Hi Graham.
I have no idea what might be causing such a weird issue.
The libraries you want to include in your code should go on the platformio.ini file. Don’t include any libraries on that file that aren’t used in your code.
Regards,
Sara
Hi
Given the Arduino IDE worked ok I figured it had to be something in the way I had done the VSCode install , so I uninstalled VSCode – not easy as the windows uninstall leaves things behind – this helped me out get rid of it completely : https://superuser.com/questions/1380208/how-to-completely-uninstall-visual-studio-code-from-windows-10
Then I reinstalled VSCode and PlatformIO and the BME280 libraries – and it works ok 🙂
Its all a learning curve !
Thanks