-
Notifications
You must be signed in to change notification settings - Fork 2.1k
Add driver for SPS30 particulate matter sensor #13256
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
drivers/include/sps30.h
Outdated
* @brief SPS30 device parameters | ||
*/ | ||
typedef struct { | ||
i2c_t i2c_dev; /**< I2C dev the sensor is connected to */ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
with the above this could later be changed to union
to allow for I2C and UART support.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
somehow
d9643f6
to
676c43e
Compare
Since the WIP label is still set I allowed myself to squash and rebase directly.. |
@smlng want to give it another look? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
some more comments, and suggestions. No serious blockers though.
finally got it working - after changing cables twice, the device seems to be very sensible 😦 However, driver test and saul test are working as expected. Please fix CI erros and squash afterwards. Then I'll make a final review round. |
3b0aad5
to
874e83b
Compare
@smlng thanks for testing! Can you explain what exactly was sensible and which board you used? Was it that the sensor required stronger pull-ups, didn't work with long wires, or something like that? |
For testing I used a bluepill board, and yes I think the wires were too long and/or didn't make good connection - not sure I first tried a "nice" wiring on a bread board with these u-shaped jumper bridges/wires (?), these didn't work. Finally I used short (10cm) jumper wires, I also used the pull-ups you provided, which worked. |
ac6be65
to
80bd08f
Compare
fixed CI errors and some typos reported by travis and directly squashed to avoid repeated CI builds. Travis also complains about the line containing the datasheet link being to long but there seems to be no nice way to break the url and keep the link working... |
tests/driver_sps30/main.c
Outdated
#define TEST_START_DELAY_US (2 * US_PER_SEC) | ||
#define SENSOR_RESET_DELAY_US (10 * US_PER_SEC) | ||
#define SENSOR_STARTUP_DELAY_US (10 * US_PER_SEC) | ||
#define POLL_FOR_READY_US (1000000U) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
looks like you could go for seconds and use xtimer_sleep
instead of xtimer_usleep
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
also the latter should be 1 * US_PER_SEC
otherwise?
mhm, maybe we need to adjust the vera++ settings @jia200x
|
80bd08f
to
2c2eab3
Compare
tried that, nothing seems to be working. I took the lazy way out using an url shortener. |
lets hope that one is stable enough in the long run 🤞 |
yeah my first thought was also against that but practically there is no difference between the URL shortener quitting service and the manufacturer breaking the links. Actually I encountered the latter more often :P ...and we need to update the link anyway then. Maybe a custom url shortener under riot-os.org would be a nice thing for stuff like that 🤔 |
@@ -148,41 +148,76 @@ enum { | |||
* and the SAUL intra-category ID (six least significant bits). | |||
*/ | |||
enum { | |||
SAUL_ACT_ANY = SAUL_CAT_ACT | SAUL_ACT_ID_ANY, /**< any actuator - wildcard */ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
not sure if we really want to change it this way, maybe its better to relax vera++ settings to allow 120 chars per line before error
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ah damn coding conventions are strict for 100 char tops, and I don't want to start a lengthy discussion (now)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So we leave it as is?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yeah for now, maybe we should discuss the 100 char line limit in our coding conventions and argue for 120. IIRC Python has 120 max, bc 80 is nice to have but often a bit to strict.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
just compiled the doc, still looks good - so let's go for it, regardless of the 100 - 120 chars discussion.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
the only thing I don't like about this change is that now there are two different styles of documentation for enums in this file.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah but I still favor same-line-comments if possible.
yep thought the same |
* | ||
* @return #SPS30_OK on success, negative #sps30_error_code_t on error | ||
*/ | ||
int sps30_start_fan_clean(const sps30_t *dev); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit picky: there is no sps30_stop_fan_clean
😮
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yep because that is not a feature documented by the manufacturer. It could be possible to implement that via the reset command (not tested) but then this is a very unlikely thing to be needed. The clean will be done after a fixed time of 10 seconds anyway. And what kind of firmware would first trigger the clean and then decide it is better to stop it now?^^
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yeah sure, was just bike-shedding 😄
If any I would change this to: sps30_clean_fan
or even a simple sps30_clean
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ahh I leave it as is. I actually chose the name like that because directly maps to how the command is named in the datasheet.
2c2eab3
to
d515ad9
Compare
d515ad9
to
1743f96
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we are good here 😄
Contribution description
This PR provides a sensor driver for the Sensirion SPS30 particulate matter sensor.
I added the WIP label for now because I'm still planning to add SAUL support and improve the test application a bit.[edit:] doneFor now I only implemented I2C support but the sensor could also be used via UART.
Any opinions on whether I should add that too? If yes, how (i.e. runtime vs. compiletime selection) ?
Testing procedure
Check the documentation of
sps30.h
to see if it is sufficient to get it running and run the test application undertests/driver_sps30
.[edit:]
SAUL adaption is now included so the generic saul example can also be used for testing:
USEMODULE="sps30" BOARD=<your_board_name> make -C examples/saul all flash term
[edit 2:]
Keep in mind that the I2C bus must be running in standard mode speed. You might need to change that in your boards
periph_conf.h
Issues/PRs references
Might be a good candidate for discussing about drivers with support for multiple interfaces (i.e. #13208).