dps310 test — Xiao Esp32C6 simulation

An interactive Xiao Esp32C6 circuit simulation you can run free in your browser on Velxio, by itsmebenn.

Components

Sketch code

// Grove - DPS310 barometer on XIAO ESP32-C6
// Adapted from the Seeed wiki (MIT). SDA -> D4 (GPIO22), SCL -> D5 (GPIO23).
// #include <Wire.h>

// const uint8_t ADDR = 0x77;

// void setup() {
//   Serial.begin(115200);
//   Wire.begin(22, 23);
//   Serial.println("Grove - DPS310 barometer");
// }

// void loop() {
//   // The raw registers, as the library reads them before applying the
//   // calibration polynomial.
//   Wire.beginTransmission(ADDR);
//   Wire.write(0x00);
//   Wire.endTransmission();
//   Wire.requestFrom(ADDR, (uint8_t)6);
//   long praw = ((long)Wire.read() << 16) | ((long)Wire.read() << 8) | Wire.read();
//   long traw = ((long)Wire.read() << 16) | ((long)Wire.read() << 8) | Wire.read();
//   Serial.print("pressure raw = ");
//   Serial.print(praw);
//   Serial.print("   temperature raw = ");
//   Serial.println(traw);
//   delay(1000);
// }

#include <Wire.h>
#include <Adafruit_DPS310.h>

// I2C PIN CONFIGURATION
#define I2C_SDA_PIN 22
#define I2C_SCL_PIN 23

// Create sensor object
Adafruit_DPS310 dps;

void setup() {
  Serial.begin(115200);
  
  // Initialize I2C specifically on pins 22 and 23
  Wire.begin(I2C_SDA_PIN, I2C_SCL_PIN);
  
  Serial.println("Initializing DPS310 sensor...");

  // Initialize sensor using the library (using the configured Wire instance)
  // The default I2C address for Grove DPS310 is 0x77
  if (!dps.begin_I2C(0x77, &Wire)) {
    Serial.println("Failed to find DPS310! Please check your SDA and SCL wiring.");
    while (1) delay(10); // Halt program if sensor is not detected
  }
  
  Serial.println("DPS310 sensor successfully connected!");

  // (Optional) Configure sensor for high precision mode
  // Takes 64 samples per measurement for highly stable results
  dps.configurePressure(DPS310_64HZ, DPS310_64SAMPLES);
  dps.configureTemperature(DPS310_64HZ, DPS310_64SAMPLES);
  
  Serial.println("Starting measurements...\n");
}

void loop() {
  // Prepare containers to store processed data (not raw data)
  sensors_event_t temp_event, pressure_event;
  
  // Instruct the library to read and calculate calibration polynomials
  if (dps.getEvents(&temp_event, &pressure_event)) {
    // Print the results to the Serial Monitor
    Serial.print("Temperature (T) = ");
    Serial.print(temp_event.temperature, 2); // Unit in Celsius
    Serial.print(" C   |   Pressure (P) = ");
    Serial.print(pressure_event.pressure, 2); // Unit in hPa (HectoPascal) / millibar
    Serial.println(" hPa");
  } else {
    Serial.println("Failed to read data from DPS310!");
  }
  
  // 1-second delay
  delay(1000);
}

More projects by itsmebenn