GithubHelp home page GithubHelp logo

paulvha / sps30 Goto Github PK

View Code? Open in Web Editor NEW
65.0 12.0 27.0 10.56 MB

Sensirion SPS30 driver for ESP32, SODAQ, MEGA2560, UNO,UNO-R4 ESP8266, Particle-photon on UART OR I2C coummunication

License: GNU General Public License v3.0

C++ 100.00%
sps30 sensirion esp32 uno arduino-uno mega2560 sensor bme280 ds18x20 particle-photon

sps30's Introduction

Sensirion SPS30

===========================================================

A program to set instructions and get information from an SPS30. It has been tested to run either UART or I2C communication on ESP32, MEGA2560, ESP8266, UNO, Due, nRF52840 and Apollo3. In the meantime many other boards have been added to the test as well as extended interface options. (see below)
A detailed description of the options and findings are in SPS30.odt

Getting Started

As part of a larger project I am looking at analyzing and understanding the air quality. I have done a number of projects on air-sensors. This is a version of a working driver + examples. More work continues to happen to create examples and compare against other sensors.

A word of warning: the SPS30 needs a female plug of ZHR-5 from JST Sales America Inc. I have not been able to find a good source for that and was glad to buy the Sparkfun version (https://www.sparkfun.com/products/15103) which does include a cable with this plug.


May 2019 : there is also a library available for Raspberry Pi (https://github.com/paulvha/sps30_on_raspberry)
January 2023 : there is also SPS30 BLE-peripheral, BLE-central and Android BLE-APP (https://github.com/paulvha/apollo3/tree/master/ArduinoBLE_special)

Prerequisites

Examples 4, 5, 7, 8, 10, 15 and 16 have a dependency on other libraries. Documented in sketch.

Software installation

Obtain the zip and install like any other

Program usage

Program options

Please see the description in the top of the sketch and read the documentation (odt)

Communication channel selection

From the start I had decided to take an embedded communication channel setup. This made it much easier for the user to select and have the right setup for Serial or I2C. It was initially tested on an UNO, MEGA, ESP32, ESP8266, Due (1.4.4) and works well. Overtime code has been adjusted to support more boards with different pin-outs based on user request and feedback. Given the large number of new boards that continue to hit the market, with different pin-outs, as well as boards with multiple I2C channels, I have decided to add the option for the user provide the communication channel also differently. This means the user will perform in the sketch the initialization of the channel (serial or I2C) and provide that to the SP30 library. Example12 (for serial communication) and Example13 (for I2C communication) has been added to demonstrate the usage. The embedded approach, and thus backward compatibility, continue to be available.

Versioning

Version 1.4.17 / October 2023

  • added support for UNO-R4 WIFI in SERIALPORT1
  • added support (adding extra reset delay) for UNO-R4 WIFI /UNO-R4 MINIMA on I2C
  • updated documentation

Version 1.4.16 / Janaury 2023

  • fixed compile error in the embedded approach as Serial2 is not defined by default for ESP32C3 over Espressif 5.0.0 and also over Espressif 6.0.0

Version 1.4.15 / January 2023

  • autodetection added for Nano MBED i2C size (needed for NANO BLE 33 and nRF52480)

version 1.4.14 / May 2022

  • changed ERR_xxx to SPS30_ERR_xxx due to conflict with other program

version 1.4.13 / January 2022

  • Different corrections in SPS30.odt

version 1.4.12 / October 2021

  • Updated example13 and example16 to allow lower I2C speed for stability

version 1.4.11 / July 2021

  • Fixed error handling in Getvalues()

version 1.4.10 / February 2021

  • Fixed typos in autodetection for Nano BLE 33 / Apollo3 for SoftwareSerial detection

version 1.4.9 / October 2020

  • added example15 and Example16 to display the SPS30 output on an LCD

version 1.4.8 / October 2020

  • added check on return code in GetStatusReg()
  • added support for Artemis / Apollo3
  • added setClock() for I2C as the Artemis/Apollo3 is standard 400K. SPS30 can handle up to 100K
  • added flushing in case of chk_zero() (handling a problem in Artemis library 2.0.1)

version 1.4.7 / September 2020

  • corrected another return code in instruct() (Thanks for pointing out Robert R. Fenichel)

version 1.4.6 / September 2020

  • corrected return code in instruct() (Thanks for pointing out Robert R. Fenichel)

version 1.4.5 / August 2020

  • added example20 for connecting multiple SPS30 (5!) to single board
  • updated sps30.odt around multiple SPS30 connected to Mega2560, DUE and ESP32

version 1.4.4 / July 2020

  • added embedded support for Arduino Due
  • as I now have a SPS30 firmware level 2.2 to test, corrected GetStatusReg() and SetOpMode()
  • changed Example11 to demonstrate reading status register only
  • added Example14 to demonstrate sleep and wakeup function.

version 1.4.3 / June 2020

  • update to I2C_WAKEUP code

version 1.4.2 / May 2020

  • added NANO 33 IOT board = SAMD21G18A (addition from Firepoo)
  • added option to select in sketch any serial or wire channel to use (many user requests)
  • added example12 and example13 sketches to demonstrate any channel selection option

version 1.4.1 / May 2020

  • Fixed issue in setOpmode() when NO UART is available, only I2C.
  • Added setOpmode() to exclude in small footprint

version 1.4 / April 2020

  • Based on the new SPS30 datasheet (March 2020) a number of functions are added or updated. Some are depending on the new firmware.
  • Added sleep() and wakeup(). Requires firmware 2.0
  • Added GetVersion() to obtain the current firmware / hardware / library info
  • Added structure SPS30_version for GetVersion()
  • Added GetStatusReg() to obtain SPS30 status information. Requires firmware 2.2
  • Added internal function to check on correct firmware level
  • Added INCLUDE_FWCHECK in SPS30.h to enable /disable check.
  • Changed probe() to obtain firmware levels instead of serial number.
  • Changed on how to obtaining product-type
  • Depreciated GetArticleCode(). Still supporting backward compatibility
  • Update the example sketches to include version levels
  • Added example11 for sleep(), wakeup() and GetStatusreg()
  • Update to documentation
  • Added the new datasheet in extras-folder

version 1.3.10 / April 2020

  • Updated examples for new compile errors and warnings wih IDE 1.8.12
  • support for SODAQ AFF/SARA board (examples on https://github.com/paulvha/sodaq
  • changed debug message handling
  • Added DEBUGSERIAL to define the Serial port for messages
  • fixed some typo's and cosmetic update
  • still fully backward compatible with earlier sketches
  • updated documentation

version 1.3.9 / February 2020

  • optimized autodetection for SAMx1D SERCOM and ESP32 to undef softwareSerial

version 1.3.8 / January 2020

  • optimized the fix from October 2019 for I2C max bytes

version 1.3.7 / December 2019

  • fixed ESP32 serial connection / flushing

version 1.3.6 / September 2019

  • fixed I2C_Max_bytes error when I2C is excluded in sps30.h
  • improve receive buffer checks larger than 3 bytes
  • A special version for Feather Lora 32U4 has been created https://github.com/paulvha/SPS30_lora

version 1.3.5 / May 2019

  • added support for MKRZERO/SAMD I2C buffer detection and disable softerial
  • updated documentation for PROMINI I2C buffer adjustment in odt-file (thanks to input Bert Heusinkveld)

version 1.3.4 / April 2019

  • corrected the stop measurement command (spotted by detamend)

version 1.3.3 / March 2019

  • Added example 10 for ESP32 only: use SPS30 to create an airquality index by region
  • update documentation to 1.3

version 1.3.2 / February 2019

  • Added example 9 (with compare typical size)
  • Updated the documentation with compare results to SDS011 and Dylos-1700
  • Update all examples to have prototypes upfront as the ESP32 pre-processor sometimes does not create

version 1.3.1 / February 2019

  • fixed the PM10 number always showing 0 issue.

version 1.3.0 / February 2019

  • Added check on the I2C receive buffer. If at least 64 bytes it try to read ALL information else only MASS results
  • Updated examples / documentation / instructions
  • Added example 8 (SPS30 + SCD30 + BME280)
  • Added || defined(AVR_ATmega32U4) || defined(AVR_ATmega16U4) for boards with small footprint (thanks Just van den Broecke)
  • Although the AVR_ATmega32U4 has a UART, it does NOT support 115K and can only be connected over I2C.

version 1.2.1 / February 2019

  • Added example 7 (with SCD)
  • Added flag in sps30.h SOFTI2C_ESP32 to use SoftWire on ESP32 in case of SCD30 and SPS30 working on I2C
  • Update documentation / instructions

version 1.2 / January 2019

  • Added force serial1 when TX = RX = 8
  • Added flag INCLUDE_SOFTWARE_SERIAL to optionally exclude software Serial
  • Tested by Ryan Brown on a Sparkfun Photon RED board and the code should also work with the Photon, P1, and Electrons

version 1.1.0 / January 2019

  • Added example 6 (plotting data)
  • Added ESP8266 support info

version 1.0.1 / January 2019

  • Added examples 4 (with DS18x20) and 5 (with BME280)

version 1.0 / January 2019

  • Initial version Arduino, ESP32, UNO

Author

License

This project is licensed under the GNU GENERAL PUBLIC LICENSE 3.0

Acknowledgments

Make sure to read the datasheet from Sensirion, March 2020 version.

In case you are new to electronics and wonder about pull-up resistors for I2C, see below (thanks to Shane Diller)

Uno and SP30

June 2021, Input from CCDZAPPER:

This is not an issue - just a note to help others that may have damaged or lost the flimsy cable with the ZHR-5 connector. It is available inexpensively on eBay: https://www.ebay.com/itm/114551266422 Make sure you pick the correct type, which is 1.25mm 5 Pin. (10 Sets JST SH 1.0 ZH 1.5 PH 2.0 XH 2.5 Housing Connector Female Male Wire)

October 2021: Input from Urs Utzinger

Reducing the I2C speed to 50K instead of 100K improves longer time stability.

October 2021 : Input from Nkea

I also found another compatible connector. I also recommend buying spare crimp contacts as they are very small and fragile. Needs a crimp tool. I use a Connector Pliers model PA-09 by Engineer I had from other works. It may be useful if special lengths are needed of there is no stock on JST ones

Housing: https://www.mouser.es/ProductDetail/Wurth-Elektronik/648005113322?qs=%2Fha2pyFaduguH2zIpdkgUWxmzUvrTES979PXEupx7lQusLC5mK%2FQfQ%3D%3D

crimp contacts https://www.mouser.es/ProductDetail/Wurth-Elektronik/64800113722DEC?qs=%2Fha2pyFaduguH2zIpdkgUUfd6dp6pTTujW8FuBzdSDO2pxvJN95p5w%3D%3D

sps30's People

Contributors

paulvha avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

sps30's Issues

Example5_sps30_bme280_BasicReadings

Hello - thanks for the library. I found a superfluous curly bracket on line 248 in Example5_sps30_bme280_BasicReadings. If I remove it, it compiles without complaining in Arduino IDE.

Please support NANO 33 IOT board.

Hi

I'm using NANO 33 IOT board with SPS30 UART Connection.
NANO 33 IOT board have a SERIALPORT1 except debug port.
If you add code below at "SPS30::setSerialSpeed()" class then very helpful another people.
(for beginner like me)

#if defined(__SAMD21G18A__)
        case SERIALPORT1:
            Serial1.begin(_Serial_baud);
            _serial = &Serial1;
            break;
#endif  

Thanks your good code.
Good luck.

https://store.arduino.cc/usa/nano-33-iot

sps30.h >> SER_STOP_MEASUREMENT

Hello Paul - great library!!

I may have stumbled upon a error in sps30.h, line 291:

bool probe();
bool reset() {return(Instruct(SER_RESET));}
bool start() {return(Instruct(SER_START_MEASUREMENT));}
bool stop() {return(Instruct(SER_START_MEASUREMENT));}
bool clean() {return(Instruct(SER_START_FAN_CLEANING));}

should

bool stop() {return(Instruct(SER_START_MEASUREMENT));}

not be

bool stop() {return(Instruct(SER_STOP_MEASUREMENT));}

? Seems like a copy-error :)

could not probe / connect with SPS30.

Hi,

Does the fan turn on no matter what? It was working, and tried to upload new code and now it doesnt work. I hadn't touched code in a while so something may have changed.. I need to debug this. I get:

Trying to connect
could not probe / connect with SPS30.
Program on hold

Should the fan turn on once plugged in, or is it after the mcu communicates with the sps?
I'm tripple checking the rx tx pins. I'm setting Serial1 and defining RX TX as I'm using an ESP32.
On pin 17 16.

Setting up UART

Hi, I'm having some trouble getting the code running on an ESP32 via UART. I've commented out all the I2C parts and have it compiling. when I turn the debug mode on, I see that the data being sent but no reply. I've got the wires hooked up as in the document, and have turned Serial2 on for the pin 17 and 16 serial2. Could you advise on how I can debug the issue? Thanks!!

Example 6 SPS30

return on line 284 required the addition of a variable to compile for me. Added (true) and everything has been working peachy.

Further check possible when reading values; avoids bad data

I have an SPS30 readout by an ESP8266-NodeMCU, powered by the 5 V pin and using SoftSerial UART with 3.3 V communications.
It has frequent read errors (one per 100 or so), usually caught by the CRC check. But I guess with an 8bit CRC check, once in 256 errors you happen to get the same code by chance, allowing bad data through. Most such events have a few data words missing, and crazy values like billions or negative. So the payload is 0x28, but the actual length value is less than 46 (typically 43). This is easy to detect, just after the redundancy check. When I put this in, it cleared up all the bad data (well, for 24 hours running, reading continuously).

Replacement Connector Found!

This is not an issue - just a note to help others that may have damaged or lost the flimsy cable with the ZHR-5 connector. It is available inexpensively on eBay: https://www.ebay.com/itm/114551266422
Make sure you pick the correct type, which is 1.25mm 5 Pin.
(10 Sets JST SH 1.0 ZH 1.5 PH 2.0 XH 2.5 Housing Connector Female Male Wire)

SPS_DEBUGSERIAL_SODAQ Error

Dear Paul

I'm a newbie to Arduino and your package, so I'm not sure if the following error is due to a programming error on my side or a bug in the package.

I use a ATMega328P on a Chinese Arduino Uno (which worked well for other applications) wired according your sketch to the SPS30.
Now I wanted to upload/compile the example sketch number 1 from your package. I changed the lines to
#define SP30_COMMS I2C_COMMS
#define TX_PIN 0
#define RX_PIN 0
to communicate over I2C to the SPS. I receive the error message below. Since you added recently the feature DEBUGSERIAL I wondered if this is maybe a bug...

In file included from /Users/webseitz/Documents/Arduino/libraries/sps30-master/src/sps30.cpp:66:0:
/Users/webseitz/Documents/Arduino/libraries/sps30-master/src/sps30.cpp: In member function 'void SPS30::DebugPrintf(const char*, ...)':
/Users/webseitz/Documents/Arduino/libraries/sps30-master/src/sps30.h:72:33: error: 'SerialUSB' was not declared in this scope
 #define SPS30_DEBUGSERIAL_SODAQ SerialUSB
                                 ^
/Users/webseitz/Documents/Arduino/libraries/sps30-master/src/sps30.cpp:129:13: note: in expansion of macro 'SPS30_DEBUGSERIAL_SODAQ'
             SPS30_DEBUGSERIAL_SODAQ.print(prfbuf);
             ^~~~~~~~~~~~~~~~~~~~~~~
/Users/webseitz/Documents/Arduino/libraries/sps30-master/src/sps30.h:72:33: note: suggested alternative: 'Serial_RX'
 #define SPS30_DEBUGSERIAL_SODAQ SerialUSB
                                 ^
/Users/webseitz/Documents/Arduino/libraries/sps30-master/src/sps30.cpp:129:13: note: in expansion of macro 'SPS30_DEBUGSERIAL_SODAQ'
             SPS30_DEBUGSERIAL_SODAQ.print(prfbuf);
             ^~~~~~~~~~~~~~~~~~~~~~~

I uncommented line 128 and 129 of sps30.cpp and then the code worked!

Arduino Zero (SAMD21) Issues

I've run into a couple issues while using this library on an Arduino Zero and Adafruit Metro M0 board:

printf.h:
#define _Stream_Obj_ Serial could be changed to #define _Stream_Obj_ SERIAL_PORT_MONITOR to work on most platforms

sps30.cpp:
On this platform the hardware Serial (D0 and D1) are called Serial1. This port is excluded by the ifdefined rules. My proposal is to change #if defined(__AVR_ATmega32U4__) to #if defined(__AVR_ATmega32U4__) || defined(ARDUINO_ARCH_SAMD)

Support for ESP32C3

Overview

The library fails with ESP32C3 over Espressif 5.0.0 and also over Espressif 6.0.0. With other variants, like ESP32, 8266 and also Atmelsam works fine.

Compiling .pio/build/ESP32C3/lib658/S8_UART/utils.cpp.o
.pio/libdeps/ESP32C3/sps30/src/sps30.cpp: In member function 'bool SPS30::setSerialSpeed()':
.pio/libdeps/ESP32C3/sps30/src/sps30.cpp:1097:13: error: 'Serial2' was not declared in this scope
             Serial2.begin(_Serial_baud);
             ^~~~~~~
.pio/libdeps/ESP32C3/sps30/src/sps30.cpp:1097:13: note: suggested alternative: 'Serial1'
             Serial2.begin(_Serial_baud);
             ^~~~~~~
             Serial1

Dependencies:

Resolving ESP32C3 dependencies...
Platform espressif32 @ 6.0.0 (required: espressif32)
framework-arduinoespressif32 @ 3.20006.221224
sps30 @ 1.4.14

Thanks in advance.

SPS30 - Not A Teamplayer - Problems with other devices on I2C

First the important stuff: Paul: I love your library! SENSIRION should hire you for the job you did here.

SYSTEM:
ESP8266 / WeMOS D1 Board
Arduino IDE 1.8.9
esp8266 Library V2.5.2

I2C Devices
SENSIRION SPS30
BME680
D1 OLED-Display Shield

I'm developing a Sensor-Reader/Data-Logger device, set up the SPS30 pretty much the way you did in the examples.

I read the sensor every two seconds, together with the BME680 and update the Display (via the u2g8 Library). And I get garbage like that:

19-06-12_garbage.txt
(Tab separated text file)

Interestingly, if I disable the routines, that write the Display - the SPS30 works fine:

19-06-12_ok.txt

I tried to leave the SPS30 "time to breathe" by tick-tocking every second between reading the SPS30 on even seconds and writing the display on the odd ones - no success.

Tried the combination SPS30/BME680/Display unter the ESP8266-Lib 2.4.2 and it worked. Sadly, we can't go back, b'c some upcomming devices depend on the 2.5.2 Library - welcome to dependency hell.

One more thing: currently the devices are read/written to in that oder:

tick:

  • SPS30
  • BME680

tock:

  • Display

If I change the order, so the BME680 gets read before the SPS30, it screws up the measurement again.

I know: your library comes without warranty or help - if you got any idea what's going on there, it would be greatly appreciated.

CRC error when reading version info

This is a suggested change to your code.

I attached sensor to ESP8266 i2c using D1,D2 but also tested with D3/D4 and D5/D6.
Its power is 5V and pullup is to 3.3V.

The sensor works with exception of reporting faulty version information.

I modified your code in uint8_t SPS30::I2C_ReadToBuffer(uint8_t count, bool chk_zero)
so that data is copied to the receive buffer before the CRC is calculated.
I recommend this modification so one can see what the transmitted version number is.

My sensor reports the following with your demo program "Basic Readings with any i2c" when you implement the above change.

I2C Sending: 0xD1 0x00
I2C CRC error: Expected 0x69, calculated 0xF4
I2C Received: 0x02 0xFF length: 2

Error during reading from I2C: 0x51
Read version info with error.
Firmware level: 2.255
Library level : 1.4

Second byte of version information is likely faulty.

I2C Wake-up does not work

sps30.h line 410
is #define I2C_WAKEUP 0X1002
should be #define I2C_WAKEUP 0X1103
otherwise I2C Wake-up does not work

Error reading sps30.

Hi.
Using the library with canairio proyect, I found that some times the sensor show me some errors:

->[SLIB] attempt enable sensor : SPS30
-->[SLIB] SPS30 Serial number : 3D59CD669A90A7EB
-->[SLIB] SPS30 product name : 00080000
-->[SLIB] SPS30 firmware level : 2.1
-->[SLIB] SPS30 Hardware level : 0
-->[SLIB] SPS30 SHDLC protocol : 0.0
-->[SLIB] SPS30 Library level : 1.4
-->[SLIB] SPS30 Detected SPS30 via I2C.
-->[SLIB] SPS30 Measurement OK
-->[SLIB] sensor registered : SPS30 :D

Here the error:

[E][SLIB] SPS30 error msg : Protocol error
-->[SLIB] AM2320 read : done!
-->[HEAP] LOOP bytes used : 5860b/052Kb
-->[SLIB] Sensors devices count : 2 (SPS30,AM232X,)
-->[SLIB] Sensors units count : 6 (PM1,PM2.5,PM4,PM10,T,H,)
-->[SLIB] Preview sensors values : PM1:18.0 PM2.5:20.0 PM4:20.0 PM10:20.0 T:20.0 H:38.3
-->[SLIB] SPS30 read : done!
-->[SLIB] AM2320 read : done!
-->[HEAP] LOOP bytes used : -1768b/054Kb
-->[SLIB] Sensors devices count : 2 (SPS30,AM232X,)
-->[SLIB] Sensors units count : 6 (PM1,PM2.5,PM4,PM10,T,H,)
-->[SLIB] Preview sensors values : PM1:19.0 PM2.5:20.0 PM4:20.0 PM10:20.0 T:20.0 H:37.1
-->[MQTT] Anaire cloud published : payload size: 197
-->[IFDB] CanAirIO cloud write : payload size: 48

other example with more info:
11:46:13.149 > -->[SLIB] trying to load I2C sensors..
11:46:13.155 > -->[SLIB] I2C SPS30 starting sensor..
11:46:13.155 > I2C Sending: 0xD1 0x00
11:46:13.160 > I2C Received: 0x02 0x01 length: 2
11:46:13.160 >
11:46:13.160 > I2C Sending: 0xD0 0x33
11:46:13.166 > I2C Received: 0x33 0x44 0x35 0x39 0x43 0x44 0x36 0x36 0x39 0x41 0x39 0x30 0x41 0x37 0x45 0x42 0x00 0x00 length: 18
11:46:13.171 >
11:46:13.171 > -->[SLIB] SPS30 Serial number : 3D59CD669A90A7EB
11:46:13.276 > I2C Sending: 0xD0 0x02
11:46:13.276 > I2C Received: 0x30 0x30 0x30 0x38 0x30 0x30 0x30 0x30 length: 8
11:46:13.276 >
11:46:13.276 > -->[SLIB] SPS30 product name : 00080000
11:46:13.276 > I2C Sending: 0xD1 0x00
11:46:13.276 > I2C Received: 0x02 0x01 length: 2
11:46:13.276 >
11:46:13.276 > -->[SLIB] SPS30 firmware level: 2.1
11:46:13.276 > -->[SLIB] SPS30 Hardware level: 0
11:46:13.276 > -->[SLIB] SPS30 SHDLC protocol: 0.0
11:46:13.276 > -->[SLIB] SPS30 Library level : 1.4
11:46:13.276 > I2C Sending: 0xD3 0x04
11:46:15.196 > -->[SLIB] SPS30 Detected SPS30 via I2C.
11:46:15.202 > I2C Sending: 0x00 0x10 0x03 0x00 0xAC
11:46:16.197 > -->[SLIB] SPS30 Measurement OK
11:46:16.203 > -->[SLIB] I2C detected SPS30 sensor :)

And the error:

11:46:24.173 > -->[SLIB] AM2320 read > done!
11:46:24.254 > I2C Sending: 0x02 0x02
11:46:24.259 > I2C Received: 0x00 0x01 length: 2
11:46:24.259 >
11:46:24.259 > I2C Sending: 0x03 0x00
11:46:24.261 > I2C CRC error: Expected 0xE8, calculated 0xD0
11:46:24.267 > I2C Received: 0x41 0x5B 0x50 0xFB 0x41 0x67 0xEB 0x2F length: 8
11:46:24.273 >
11:46:24.273 > Error during reading from I2C: 0x51
11:46:24.277 > [E][SLIB] SPS30 Protocol error
11:46:24.298 > -->[SLIB] PM1:000 PM25:000 PM10:000 CO2:0000 CO2humi:0.000000% CO2temp:0.000000°C H:37.099998% T:18.700001°C
11:46:24.309 > -->[SLIB] new sample time: 15
11:46:39.264 > I2C Sending: 0x02 0x02
11:46:39.265 > I2C Received: 0x00 0x01 length: 2
11:46:39.265 >
11:46:39.265 > I2C Sending: 0x03 0x00
11:46:39.267 > I2C CRC error: Expected 0xFF, calculated 0xF8
11:46:39.273 > I2C Received: 0x41 0x97 0xDB 0x34 0x41 0xA0 0x95 0x0E 0x41 0xA0 0x95 0x07 length: 12
11:46:39.284 >
11:46:39.284 > Error during reading from I2C: 0x51
11:46:39.284 > [E][SLIB] SPS30 Protocol error
11:46:39.290 > -->[SLIB] Any data from sensors? check your wirings!
11:46:39.314 > -->[SLIB] PM1:000 PM25:000 PM10:000 CO2:0000 CO2humi:0.000000% CO2temp:0.000000°C H:37.099998% T:18.700001°C
11:46:41.998 > -->[MQTT] Anaire sensor payload published. (size: 194)

I am not sure if this is an issue or not.
Thanks.

i2c speed recommendation

I recommend changing the speed for i2c to 50,000 for the sps30.
In my setup I have less than 20cm cable length and I have the pullups and esp8266.
When operating at standard clock and polling data every second, my system usually stalls within a 48hr time frame.
When it stalls, all communication with the device fails and it requires power cycle to restart.
This indicates that the controller inside the senor crashed.

When I use 50kHz i2c clock, the system is more stable.

One can achieve this in the "*any_I2c.ino" example program with

TwoWire.setClock(50000);
ret = sps30.GetValues(&val);
TwoWire.setClock(100000);

I would like to suggest to add the above two statements in the i2c example code and to comment them out so that users having same issue can enable it.

One can also change the driver code but there might be other i2c devices on the bus that will change the clock speed when they are initialized or they don't operate properly at 50kHz. One would need to change speed in the getValues section and change it back after data transfer is completed.

I tested the 50kHz clock because there are other Sensirion devices such as CO2 SCD30 where datasheet recommends 50kHz clock.

auto-clean on esp8266 not working

10:53:26.255 -> Serial number : 79D40290B4DFxxxx
10:53:26.255 -> Product name : not available
10:53:26.255 -> Article code : not available
10:53:26.255 -> could not get clean interval.Protocol error
10:53:26.255 -> No Auto Clean interval change requested.
10:53:27.251 -> Measurement started
10:53:27.251 ->
10:53:27.251 -> Hit to continue reading
10:53:29.263 -> Hit to continue reading
10:53:31.248 -> Hit to continue reading
10:53:33.259 -> -------------Mass ----------- ------------- Number -------------- -Average-
10:53:33.259 -> Concentration [μg/m3] Concentration [#/cm3] [μm]
10:53:33.293 -> P1.0 P2.5 P4.0 P10 P0.5 P1.0 P2.5 P4.0 P10 PartSize
10:53:33.293 ->
10:53:33.293 -> 0.74 2.94 4.69 5.04 0.40 3.55 5.73 6.15 6.21 1.63
10:53:36.299 -> 0.79 1.49 2.01 2.12 3.92 5.58 6.26 6.39 6.41 0.89
10:53:39.297 -> 0.87 1.52 2.01 2.11 4.58 6.29 6.93 7.05 7.07 0.92

Using I2c on ESP8266.

ByteToFloat

Hi Paul,

I tried compiling and example 7 this evening, but I run into those errors:

{
	"resource": "/Users/matthijsvandenberg/Documents/PlatformIO/Projects/AirQual Plafond/.pio/libdeps/d1_mini/sps30/src/sps30.h",
	"owner": "cpp",
	"severity": 8,
	"message": "conflicting declaration 'typedef union ByteToFloat ByteToFloat'",
	"startLineNumber": 329,
	"startColumn": 3,
	"endLineNumber": 329,
	"endColumn": 3
}

and

{
	"resource": "/Users/<naam>/Documents/PlatformIO/Projects/AirQual Plafond/lib/scd30/src/paulvha_SCD30.h",
	"owner": "cpp",
	"severity": 8,
	"message": "'ByteToFloat' has a previous declaration as 'typedef union ByteToFloat ByteToFloat'",
	"startLineNumber": 110,
	"startColumn": 3,
	"endLineNumber": 110,
	"endColumn": 3
}

I try this with PlatformIO in VSCode. Any idea's? Google comes up empty. Is this an old version of something? Bit of a noob as you know. :-(

Thnx.

PM1.0 measure over i2c sometimes give 0

Hi,

First, thanks for your library, for your work on it. I'm using this library on CanAirIO firmware and our wrapper library CanAirIO Sensorlib. With UART implementation we don't have this issue but with i2c sometimes the PM1.0 value give 0, the other variables, PM2.5 and PM10 works fine.

When the debug flag is enable, before the issue is reached, we have the next output:

20:37:03.820 > Error: Received NO bytes
20:37:03.820 > I2C Received: length: 0
20:37:03.820 > 
20:37:03.820 > Error during reading from I2C: 0x51
20:37:03.820 > -->[SPS30] read > done! 
20:37:03.820 > -->[SENSORS] PM1:000 PM25:008 PM10:008 CO2:0000 CO2humi:0.0% CO2temp:0.0°C H:39.21% T:25.5°C

It is weird because the error is detected by SPS30 library but something resetting to zero the PM1.0 value. The read method implementation in our library is this

The final output after this issue is something like this:

screenshot20210705_004315

Thanks

PM2.5 - PM10 identical after stabilization time

Hello and thank you for this great library!
I am using it with an ESP32 over UART and have a weird problem. After starting the measurement mode, it only takes some measurements (between 1 and 10) and the values for PM2.5, PM4 and PM10 concentrations are identical. I think it's pretty unlikely that there aren't any larger particles for several days. After a reset the first measurements show different values but they are getting the same pretty fast again.
Have you ever seen a similar behaviour? I am not sure if my sensor is faulty or if I am doing anything wrong.

-------------Mass -----------    ------------- Number --------------   -Average-
     Concentration [μg/m3]             Concentration [#/cm3]             [μm]
P1.0	P2.5	P4.0	P10	P0.5	P1.0	P2.5	P4.0	P10	PartSize

4.41	7.04	8.87	9.25	24.16	32.17	34.83	35.15	35.21	0.75
4.22	5.75	6.77	6.98	26.03	32.34	33.86	34.04	34.07	0.65
4.02	4.16	4.16	4.16	28.70	32.90	33.00	33.00	33.00	0.53
3.89	4.03	4.03	4.03	27.75	31.82	31.91	31.91	31.91	0.51
3.75	3.88	3.88	3.88	26.74	30.66	30.75	30.75	30.75	0.53
3.98	4.12	4.12	4.12	28.39	32.56	32.65	32.65	32.65	0.50
3.98	4.12	4.12	4.12	28.41	32.57	32.66	32.66	32.66	0.50
3.94	4.08	4.08	4.08	28.10	32.22	32.31	32.31	32.32	0.48
3.85	3.99	3.99	3.99	27.47	31.49	31.58	31.58	31.59	0.47
3.74	3.88	3.88	3.88	26.71	30.63	30.72	30.72	30.72	0.48
3.64	3.77	3.77	3.77	26.00	29.82	29.90	29.90	29.90	0.48
3.69	3.82	3.82	3.82	26.33	30.19	30.28	30.28	30.28	0.47
3.66	3.79	3.79	3.79	26.15	29.98	30.07	30.07	30.07	0.47
3.62	3.75	3.75	3.75	25.81	29.60	29.68	29.69	29.69	0.48
3.71	3.84	3.84	3.84	26.45	30.32	30.41	30.41	30.41	0.47
3.92	4.06	4.06	4.06	27.95	32.05	32.14	32.14	32.14	0.47
4.16	4.31	4.31	4.31	29.69	34.04	34.14	34.14	34.14	0.47
4.35	4.50	4.50	4.50	31.02	35.57	35.67	35.67	35.67	0.47
4.27	4.42	4.42	4.42	30.45	34.91	35.01	35.01	35.01	0.47
4.13	4.28	4.28	4.28	29.47	33.79	33.88	33.88	33.88	0.46
4.10	4.25	4.25	4.25	29.28	33.57	33.67	33.67	33.67	0.47
4.08	4.22	4.22	4.22	29.10	33.37	33.46	33.46	33.46	0.47
4.02	4.16	4.16	4.16	28.69	32.89	32.99	32.99	32.99	0.47
3.95	4.09	4.09	4.09	28.18	32.31	32.40	32.40	32.40	0.48
3.87	4.01	4.01	4.01	27.65	31.70	31.79	31.80	31.80	0.48
3.94	4.08	4.08	4.08	28.15	32.28	32.37	32.37	32.37	0.48
4.01	4.15	4.15	4.15	28.62	32.82	32.91	32.91	32.91	0.48
4.16	4.31	4.31	4.31	29.70	34.05	34.15	34.15	34.15	0.48
4.21	4.36	4.36	4.36	30.05	34.45	34.55	34.56	34.56	0.48
4.22	4.37	4.37	4.37	30.10	34.52	34.62	34.62	34.62	0.48
4.07	4.21	4.21	4.21	29.04	33.30	33.39	33.39	33.40	0.48
3.81	3.94	3.94	3.94	27.17	31.15	31.24	31.24	31.24	0.49
3.66	3.79	3.79	3.79	26.10	29.92	30.01	30.01	30.01	0.49
3.74	3.87	3.87	3.87	26.70	30.61	30.70	30.70	30.70	0.49
3.95	4.09	4.09	4.09	28.18	32.31	32.41	32.41	32.41	0.49
4.14	4.28	4.28	4.28	29.53	33.86	33.96	33.96	33.96	0.49
4.21	4.36	4.36	4.36	30.03	34.43	34.53	34.53	34.53	0.49
4.02	4.16	4.16	4.16	28.70	32.90	33.00	33.00	33.00	0.49
3.94	4.09	4.09	4.09	28.16	32.28	32.38	32.38	32.38	0.49
...

Hard reset?

Is it possible to conduct a hard reset on the SPS30?
When uploading new code while a previous program is running and accessing the sensor through I2C, the command ".probe()" usually fails. If the sensor is powered down and reenergized, the program works as expected.

This likely is a firmware issue or perhaps when using I2C one needs to send reset before executing probe()?

Compile error when excluding UART

Hi Paul

When I comment out #define INCLUDE_UART 1 I get a compile error:
[...] /sps30.cpp:772:1: error: control reaches end of non-void function [-Werror=return-type]
772 | }

I'm compiling for a Particle Boron using Particle Workbench (MS Visual Code).

Thanks

Dave

'ERR_DATALENGTH' 'ERR_OK' not declared

Hello Paul, I've been trying to get the SPS30 to read PM values using an Heltec ESP32 LoRa WiFi board, ive tried i2c and UART, yet am experiencing this issue, which is weird since it was not giving me the error of having things undeclared but rather saying that the sps30 probe was not reading. Any assistance would be helpful thank you.

Setting up serialport2 TX and RX

Hi,
I'm having trouble to connect an sps30 to a TTGO wrover esp32.
For serial port 2 I have to use 16,17 pins but the TTGO esp32 doesn't have this pinouts.
I tried to change them in the sketch with 4,5 but without success.
Have u got any hint?

Thnks
Paul
anyway thanks for the lib, nice work

SPS not running Uart

Have purchased a new SPS30. Label 2021 03-03. Operation I2C runs well with both the original library and Pauls. In no way it will run UART. Tried on an Esp32 and mega. With external 5volt power, ground through connected. Cable 4 not connected. No power to SPS30 when changing I2C to UART, cable 4. Right serial ports named. Trying for many days but no results. Someone same problem? Some help?
Product name : 00080000
Firmware level: 2.2
Library level : 1.4

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.