Skip to content
This repository was archived by the owner on Aug 29, 2025. It is now read-only.
This repository was archived by the owner on Aug 29, 2025. It is now read-only.

1.2.0 version have issue with compilation for MKRWAN 1310, versions below - 1.1 etc. works fine #57

Description

@WeSpeakEnglish

sketch:
#include <sps30.h>
#include <Wire.h>

// Uncomment for serial plotter format
// #define PLOTTER_FORMAT

void setup() {
int16_t ret;
uint8_t auto_clean_days = 4;

SerialUSB.begin(115200); // Use SerialUSB for MKR boards
while (!SerialUSB) {
; // Wait for USB Serial to be ready
}
delay(2000);

// Initialize I2C on default pins (SDA/SCL on MKR ONE 1310)
Wire.begin();

// Initialize Sensirion I2C layer (usually calls Wire.begin internally)
sensirion_i2c_init();

while (sps30_probe() != 0) {
SerialUSB.println("SPS sensor probing failed");
delay(500);
}

#ifndef PLOTTER_FORMAT
SerialUSB.println("SPS sensor probing successful");
#endif

ret = sps30_set_fan_auto_cleaning_interval_days(auto_clean_days);
if (ret) {
SerialUSB.print("error setting the auto-clean interval: ");
SerialUSB.println(ret);
}

ret = sps30_start_measurement();
if (ret < 0) {
SerialUSB.println("error starting measurement");
}

#ifndef PLOTTER_FORMAT
SerialUSB.println("measurements started");
#endif

#ifdef SPS30_LIMITED_I2C_BUFFER_SIZE
SerialUSB.println("Your Arduino hardware has a limitation that only allows reading the mass concentrations.");
SerialUSB.println("See https://github.com/Sensirion/arduino-sps#esp8266-partial-legacy-support");
delay(2000);
#endif

delay(1000);
}

void loop() {
struct sps30_measurement m;
uint16_t data_ready;
int16_t ret;

do {
ret = sps30_read_data_ready(&data_ready);
if (ret < 0) {
SerialUSB.print("error reading data-ready flag: ");
SerialUSB.println(ret);
} else if (!data_ready) {
SerialUSB.println("data not ready, no new measurement available");
} else
break;
delay(100);
} while (1);

ret = sps30_read_measurement(&m);
if (ret < 0) {
SerialUSB.println("error reading measurement");
} else {

#ifndef PLOTTER_FORMAT
SerialUSB.print("PM 1.0: ");
SerialUSB.println(m.mc_1p0);
SerialUSB.print("PM 2.5: ");
SerialUSB.println(m.mc_2p5);
SerialUSB.print("PM 4.0: ");
SerialUSB.println(m.mc_4p0);
SerialUSB.print("PM 10.0: ");
SerialUSB.println(m.mc_10p0);

#ifndef SPS30_LIMITED_I2C_BUFFER_SIZE
SerialUSB.print("NC 0.5: ");
SerialUSB.println(m.nc_0p5);
SerialUSB.print("NC 1.0: ");
SerialUSB.println(m.nc_1p0);
SerialUSB.print("NC 2.5: ");
SerialUSB.println(m.nc_2p5);
SerialUSB.print("NC 4.0: ");
SerialUSB.println(m.nc_4p0);
SerialUSB.print("NC 10.0: ");
SerialUSB.println(m.nc_10p0);

SerialUSB.print("Typical particle size: ");
SerialUSB.println(m.typical_particle_size);

#endif

SerialUSB.println();

#else
SerialUSB.print(m.nc_0p5);
SerialUSB.print(" ");
SerialUSB.print(m.nc_1p0 - m.nc_0p5);
SerialUSB.print(" ");
SerialUSB.print(m.nc_2p5 - m.nc_1p0);
SerialUSB.print(" ");
SerialUSB.print(m.nc_4p0 - m.nc_2p5);
SerialUSB.print(" ");
SerialUSB.print(m.nc_10p0 - m.nc_4p0);
SerialUSB.println();
#endif

}

delay(1000);
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions