Skip to content

Commit b95e99f

Browse files
author
Cesarbautista10
committed
chore: add simple code for spi interface
1 parent 3f73982 commit b95e99f

2 files changed

Lines changed: 109 additions & 0 deletions

File tree

software/examples/i2c/example1.ino

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
#include <Arduino.h>
2+
#include "bme68xLibrary.h"
3+
#include <Wire.h>
4+
5+
#define SDA_PIN 21
6+
#define SCL_PIN 22
7+
8+
Bme68x bme;
9+
10+
void setup() {
11+
Serial.begin(115200);
12+
while (!Serial) delay(10);
13+
14+
Wire.begin(SDA_PIN, SCL_PIN);
15+
Wire.setClock(100000); // 100 kHz
16+
17+
// ✅ Solo llama a begin, sin usar if
18+
bme.begin(0x77, Wire);
19+
20+
// Verifica estado del sensor
21+
if (bme.checkStatus() == BME68X_ERROR) {
22+
Serial.println("❌ Error: BME688 no detectado.");
23+
while (1);
24+
}
25+
26+
Serial.println("✅ Sensor BME688 inicializado correctamente.");
27+
28+
bme.setTPH(); // Temp, Pressure, Humidity
29+
bme.setHeaterProf(300, 100); // Heater: 300°C, 100 ms
30+
31+
Serial.println("Time(ms), Temp(°C), Pressure(Pa), Humidity(%), Gas(Ω), Status");
32+
}
33+
34+
void loop() {
35+
bme68xData data;
36+
37+
bme.setOpMode(BME68X_FORCED_MODE);
38+
delayMicroseconds(bme.getMeasDur());
39+
40+
if (bme.fetchData()) {
41+
bme.getData(data);
42+
43+
Serial.print(millis()); Serial.print(", ");
44+
Serial.print(data.temperature); Serial.print(", ");
45+
Serial.print(data.pressure); Serial.print(", ");
46+
Serial.print(data.humidity); Serial.print(", ");
47+
Serial.print(data.gas_resistance); Serial.print(", ");
48+
Serial.println(data.status, HEX);
49+
}
50+
51+
delay(100);
52+
}
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
#include <Arduino.h>
2+
#include <SPI.h>
3+
#include "bme68xLibrary.h"
4+
5+
// Pines personalizados para ESP32-C6
6+
#define PIN_MOSI 7
7+
#define PIN_MISO 2
8+
#define PIN_SCK 6
9+
#define PIN_CS 18
10+
11+
SPIClass mySPI(0); // Bus SPI #0 para ESP32-C6
12+
Bme68x bme;
13+
14+
void setup() {
15+
Serial.begin(115200);
16+
while (!Serial);
17+
18+
// Inicializar SPI con pines personalizados
19+
mySPI.begin(PIN_SCK, PIN_MISO, PIN_MOSI, PIN_CS);
20+
21+
// Iniciar BME688 en modo SPI
22+
bme.begin(PIN_CS, mySPI);
23+
24+
if (bme.checkStatus() == BME68X_ERROR) {
25+
Serial.println("❌ Error: no se pudo inicializar el sensor.");
26+
while (1);
27+
} else if (bme.checkStatus() == BME68X_WARNING) {
28+
Serial.println("⚠️ Advertencia: " + bme.statusString());
29+
} else {
30+
Serial.println("✅ Sensor BME688 SPI listo.");
31+
}
32+
33+
bme.setTPH();
34+
bme.setHeaterProf(300, 100);
35+
36+
Serial.println("Time(ms), Temp(°C), Pressure(Pa), Humidity(%), Gas(Ω), Status");
37+
}
38+
39+
void loop() {
40+
bme68xData data;
41+
42+
bme.setOpMode(BME68X_FORCED_MODE);
43+
delayMicroseconds(bme.getMeasDur());
44+
45+
if (bme.fetchData()) {
46+
bme.getData(data);
47+
48+
Serial.print(millis()); Serial.print(", ");
49+
Serial.print(data.temperature); Serial.print(", ");
50+
Serial.print(data.pressure); Serial.print(", ");
51+
Serial.print(data.humidity); Serial.print(", ");
52+
Serial.print(data.gas_resistance); Serial.print(", ");
53+
Serial.println(data.status, HEX);
54+
}
55+
56+
delay(1000);
57+
}

0 commit comments

Comments
 (0)