I am trying to read BME680 on ESP32-CAM with following code :
(Before trying BME680, I have suscessfully connected BME280 to ESP32-CAM over S/W SPI)
#include <Wire.h>
#include <SPI.h>
#include <Adafruit_Sensor.h>
#include "Adafruit_BME680.h"
#define SEALEVELPRESSURE_HPA (1013.25)
#define BME_SCK 12 //Connected SCL to IO12
#define BME_MISO 15 //Connected SDO to IO15
#define BME_MOSI 13 //Connected SDA to IO13
#define BME_CS 14 //Connected CS to IO14
//Adafruit_BME280 bme; // I2C
Adafruit_BME680 bme(BME_CS, BME_MOSI, BME_MISO, BME_SCK); // software SPI
//float temperature = 0;
//float humidity = 0;
//float pressure = 0;
void setup() {
Serial.begin(115200);
while (!Serial);
Serial.println(F("BME680 test"));
if (!bme.begin(0x76))
{
Serial.println("Could not find a valid BME680 sensor, check wiring!");
while (1);
}
// Set up oversampling and filter initialization
bme.setTemperatureOversampling(BME680_OS_8X);
bme.setHumidityOversampling(BME680_OS_2X);
bme.setPressureOversampling(BME680_OS_4X);
bme.setIIRFilterSize(BME680_FILTER_SIZE_3);
bme.setGasHeater(320, 150); // 320*C for 150 ms
}
void loop()
{
if (! bme.performReading())
{
Serial.println("Failed to perform reading :(");
return;
}
Serial.print("Temperature = ");
Serial.print(bme.temperature);
Serial.println(" *C");
Serial.print("Pressure = ");
Serial.print(bme.pressure / 100.0);
Serial.println(" hPa");
Serial.print("Humidity = ");
Serial.print(bme.humidity);
Serial.println(" %");
Serial.print("Gas = ");
Serial.print(bme.gas_resistance / 1000.0);
Serial.println(" KOhms");
Serial.print("Approx. Altitude = ");
Serial.print(bme.readAltitude(SEALEVELPRESSURE_HPA));
Serial.println(" m");
Serial.println();
delay(2000);
}
When I try to upload the code to ESP32-CAM while BME680 is connected I get following error
esptool.py v2.6
Serial port /dev/ttyUSB0
Connecting....
Chip is ESP32D0WDQ6 (revision 1)
Features: WiFi, BT, Dual Core, 240MHz, VRef calibration in efuse, Coding Scheme None
MAC: a4:cf:12:99:b5:70
Uploading stub...
Running stub...
Stub running...
Configuring flash size...
Warning: Could not auto-detect Flash size (FlashID=0xffffff, SizeID=0xff), defaulting to 4MB
Compressed 8192 bytes to 47...
A fatal error occurred: Timed out waiting for packet content
A fatal error occurred: Timed out waiting for packet content
Then I tried to disconnect BME680 and uploaded the code to ESP32-CAM which worked, then connected BME680 back to ESP32-CAM.
But now I see following error in Serial Monitor :
ets Jun 8 2016 00:22:57
rst:0x1 (POWERON_RESET),boot:0x33 (SPI_FAST_FLASH_BOOT)
flash read err, 1000
ets_main.c 371
ets Jn 8 2016 00:22:57
rst:0x10 (RTCWDT_RTC_RESET),boot:0x33 (SPI_FAST_FLASH_BOOT)
flash read err, 1000
ets_main.c 371
ets Jun 8 2016 00:22:57
rst:0x10 (RTCWDT_RTC_RESET),boot0x33 SPI_FAST_FLASH_BOT)
lash read err, 1000
et_main.c 371
ets Jun 8 2016 00:22:57
rst:0x10 (RTCWDT_RTC_RESET),boot:0x33 (SPI_FAST_FLASH_BOOT)
flash read err, 1000
ets_main.c 371
ets Jun 8 2016 00:22:57
rst:0x10 (RTCWDT_RTC_RESET),boot:0x33 (SPI_FAST_FLASH_BOOT)
flash read err, 1000
ets_main.c 371
ets Jun 8 2016 00:22:57
Any idea what is wrong here ?
Update :
I switched #define BME_SCK 12
to #define BME_SCK 16
, now getting following message
ts Jun 8 2016 00:2:57
rst:0x1 (POWEON_REST),boot:0x13 (PI_FAT_FLASH_BOOT)
cnfigsi: 0, SPIWP:0xee
clk_dv:0x00,q_drv:0x0,d_drv0x00,cs0_drv:0x00,d_drv0x00,wp_drv:0x0
mod:DIO, clock div:
loa:0x3fff0018,len:4
load0x3fff001c,len:1216
ho 0 tail 12 room 4
lod:0x40078000,len:9720
h 0 tail 12 room 4
load0x40080400,len:6352
etry 0x400806b8
[D][esp32-hal-psram.c:47] psramInit(): PSRAM enabled