Skip to content

Conversation

@Coloradohusky
Copy link
Contributor

This PR adds support for CO2 sensing with the SCD40/SCD41 sensors. These sensors also support temperature and relative humidity.

Currently, it is using startLowPowerPeriodicMeasurement, which has an update interval of ~30 seconds. However, the datasheet mentions a measure_single_shot for lower power use, but says it is limited to SCD41 sensors only. Nonetheless, I tried it on my SCD40 sensor and it appeared to work fine. measure_single_shot also includes a delay of 5 seconds for each use.

Average Supply Current:

  • High Performance Mode: 11 mA
  • Low Power Mode: 2.8 mA
  • Idle Single Shot Mode: 1.1 mA for 1 min and 0.36 mA for 5 min interval
  • Power-Cycled Single Shot Mode: 0.18 mA for 10 min, 0.09 mA for 20 min, 0.03 mA for 1 hour interval

Other than that, the only differences between SCD40 and SCD41 are a wider CO2 interval and higher accuracy.

See SCD4x Low Power Operation and the Datasheet for more information.

Thanks

@fifieldt
Copy link
Member

Since this one has temperature and humidity in addition to co2, it looks like it spans our EnvironmentMetrics and AirQualityMetrics. Do you have a sense for how easy it would be to put the co2 in AirQualityMetrics and keep the temp/humidity in EnvironmentMetrics?

@Coloradohusky
Copy link
Contributor Author

Coloradohusky commented Sep 26, 2024

I'll work on moving it over to AirQualityMetrics instead of EnvironmentMetrics - although I noticed that IAQ is also in EnvironmentMetrics, should that be moved as well?

@Coloradohusky
Copy link
Contributor Author

Hm yeah, I'm looking closer at AirQualityModule and it's going to be more involved than I'd hoped - AirQualityModule explicitly wants a Adafruit_PM2.5 sensor (aqi = Adafruit_PM25AQI()) so I'm not entirely sure how to handle that with the addition of the CO2 metric

@fifieldt
Copy link
Member

Thanks for the heads up! Will take a look in the next few days.

Previously the module was designed around a single sensor.
This patch brings it into line with the same design as
EnvironmentTelemetry.
@fifieldt
Copy link
Member

@Coloradohusky - I hacked together some things over at
https://github.com/fifieldt/meshtastic-firmware/tree/scd4x

It compiles ... but I haven't got it further than that :)

Do you think you'd be able to hack from there and test with your sensor?

@fifieldt fifieldt marked this pull request as draft October 19, 2024 01:06
@fifieldt
Copy link
Member

@Coloradohusky , have hacked this a bit more. In theory you might also get a screen on your UI with CO2 readings too. Can you test & improve? =D

@Coloradohusky
Copy link
Contributor Author

Was checking it out just now! Will keep testing 😄

@fifieldt fifieldt marked this pull request as ready for review October 19, 2024 02:03
@fifieldt
Copy link
Member

OK, over to you -- I'll hold off making any more commits

@fifieldt fifieldt requested a review from caveman99 October 24, 2024 04:15
@Coloradohusky
Copy link
Contributor Author

Coloradohusky commented Oct 28, 2024

Haven't had much luck yet - it properly detects the sensor, but doesn't grab any measurements. Not sure what's preventing the measurements but will keep testing

@fifieldt fifieldt added the triaged Reviewed by the team, has enough information and ready to work on now. label Oct 31, 2024
@fifieldt fifieldt mentioned this pull request Nov 7, 2024
@hafu
Copy link
Contributor

hafu commented Jul 1, 2025

As mentioned before, I didn't got this branch in a working state and started over. There are also many changes in the firmware ongoing and the PMSA003I got also some changes, which must be applied here.

I suggest to start a new branch with the SCD4x sensor and keep it simple. Get it working to read out the values and send them via telemetry. In my opinion the support for displays can be added in another PR, but it is a nice to have.

Reading the comments above I'd suggest approaching the temperature and humidity of these sensors (CO2 or other multi-sensor modules) as "temperature of the co2 sensor", and add it as co2_sensor_temperature (or something like that?) in the protobuf. It would be good to keep these values separate from environment telemetry, because its otherwise difficult to get a good temperature reading (which is not affected by the co2 sensor operation itself).

I did another approach, at least for the SCD30: The SCD30 comes with an extra temperature/humidity sensor (RH/T something) integrated for calibration. I have to read the datasheet for the SCD4x if it is alike. Therefore I suggest to use the values from the integrated temperature/humidity sensor as environment metrics and calibration, if no other sensor is available.

I also wanted to start on a new branch this week, since I have now a SCD4x.

@oscgonfer
Copy link
Contributor

Hi @hafu,

We are doing a hackathon next week to integrate a whole bunch of air quality sensors into meshtastic (we are coming from a project called smartcitizen with a lot of sensors supported including these). For the hackathon, we have a selection of sensors that overlap with: scd30, scd40, sfa30, sen5x and sen6x series which we are mapping here: fablabbcn#4, and most of them are multisensor nodes that have to be agreed on how the firmware treats the readings.

I think it'd be great if we manage to all sync on this effort, and have a joint approach for integrating these... We can probably discuss the reasoning on discord or a joint call together? I think we can find an agreement on the approach, and potentially even work on a new branch together (maybe on the hackathon repo?

What do you think?

@hafu
Copy link
Contributor

hafu commented Jul 1, 2025

Hi @hafu,

We are doing a hackathon next week to integrate a whole bunch of air quality sensors into meshtastic (we are coming from a project called smartcitizen with a lot of sensors supported including these). For the hackathon, we have a selection of sensors that overlap with: scd30, scd40, sfa30, sen5x and sen6x series which we are mapping here: fablabbcn#4, and most of them are multisensor nodes that have to be agreed on how the firmware treats the readings.

I think it'd be great if we manage to all sync on this effort, and have a joint approach for integrating these... We can probably discuss the reasoning on discord or a joint call together? I think we can find an agreement on the approach, and potentially even work on a new branch together (maybe on the hackathon repo?

What do you think?

Sounds great! This would also be my first major contribution to the project. I did some tinkering with modules, sensors and build my customized meshtastic firmware. Getting CO2 sensors running with meshtastic is on my to do list since the beginning of the year.

I give discord another try, if this is the preferred way. Tomorrow I have some time to discuss. A call is also possible tomorrow.

@hafu
Copy link
Contributor

hafu commented Jul 1, 2025

Haven't had much luck yet - it properly detects the sensor, but doesn't grab any measurements. Not sure what's preventing the measurements but will keep testing

A comment to an old comment: I had some issues with the SCD30 too. I figured out, that the SCD30 only works reliable with 5V. Maybe the 3.3V power rail is a bit to low and prevents the sensor from working properly.

@oscgonfer
Copy link
Contributor

Haven't had much luck yet - it properly detects the sensor, but doesn't grab any measurements. Not sure what's preventing the measurements but will keep testing

A comment to an old comment: I had some issues with the SCD30 too. I figured out, that the SCD30 only works reliable with 5V. Maybe the 3.3V power rail is a bit to low and prevents the sensor from working properly.

I think this should be no issue... we have used SCD30 for very looong data collections (+2 years). (some SCD30 docs here https://docs.smartcitizen.me/knowledge/air/co2/Sensirion_SCD30/)

@oscgonfer
Copy link
Contributor

Hi @hafu,
We are doing a hackathon next week to integrate a whole bunch of air quality sensors into meshtastic (we are coming from a project called smartcitizen with a lot of sensors supported including these). For the hackathon, we have a selection of sensors that overlap with: scd30, scd40, sfa30, sen5x and sen6x series which we are mapping here: fablabbcn#4, and most of them are multisensor nodes that have to be agreed on how the firmware treats the readings.
I think it'd be great if we manage to all sync on this effort, and have a joint approach for integrating these... We can probably discuss the reasoning on discord or a joint call together? I think we can find an agreement on the approach, and potentially even work on a new branch together (maybe on the hackathon repo?
What do you think?

Sounds great! This would also be my first major contribution to the project. I did some tinkering with modules, sensors and build my customized meshtastic firmware. Getting CO2 sensors running with meshtastic is on my to do list since the beginning of the year.

I give discord another try, if this is the preferred way. Tomorrow I have some time to discuss. A call is also possible tomorrow.

I think one very good way to start would be to have a clean branch, updated with master, that has the decouple of AirQualityTelemetry and the PMA003I. I can give it a go, but I have no PMA sensor with me (although I have all the other sensirion ones available).

@fifieldt
Copy link
Member

fifieldt commented Jul 1, 2025

I now have a functional SCD4X and am starting to test and edit this patch a bit.

I can confirm the I2C detection code works at least :)

fifieldt added a commit to fifieldt/meshtastic-firmware that referenced this pull request Jul 1, 2025
This patch adds I2C detection support SCD40/SDC41 CO2 sensors.

It's a start to get meshtastic#4601 over the line :)

Co-Authored-By: @Coloradohusky
@fifieldt
Copy link
Member

fifieldt commented Jul 1, 2025

Trying to clean this up a little for you so you can have a more pleasant hackathon.

fifieldt added a commit that referenced this pull request Jul 1, 2025
* Add detection code for SCD4X

This patch adds I2C detection support SCD40/SDC41 CO2 sensors.

It's a start to get #4601 over the line :)

Co-Authored-By: @Coloradohusky

* Remove SCD4X from Portduino
fifieldt added a commit to fifieldt/meshtastic-firmware that referenced this pull request Jul 1, 2025
Now we have the ability to detect multiple AirQualitySensors,
follow the lead of other sensor types and create supporting methods
and objects for using this information.

Continued cherry-picking to get meshtastic#4601 over the line :)

Co-Authored-By: @Coloradohusky
fifieldt added a commit to fifieldt/meshtastic-firmware that referenced this pull request Jul 1, 2025
Now we have the ability to detect multiple AirQualitySensors,
follow the lead of other sensor types and create supporting methods
and objects for using this information.

Continued cherry-picking to get meshtastic#4601 over the line :)

Co-Authored-By: @Coloradohusky
fifieldt added a commit that referenced this pull request Jul 1, 2025
* Add detection framework for multiple AirQuality sensors

Now we have the ability to detect multiple AirQualitySensors,
follow the lead of other sensor types and create supporting methods
and objects for using this information.

Continued cherry-picking to get #4601 over the line :)

Co-Authored-By: @Coloradohusky

* Update src/main.cpp

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>

---------

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
@oscgonfer oscgonfer mentioned this pull request Jul 2, 2025
3 tasks
@hafu
Copy link
Contributor

hafu commented Jul 5, 2025

I give discord another try, if this is the preferred way. Tomorrow I have some time to discuss. A call is also possible tomorrow.

@oscgonfer Sorry, I got sick, but I got some energy today and tried out your PR and gave some feedback.

@oscgonfer
Copy link
Contributor

@fifieldt superseeded by #7198

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

triaged Reviewed by the team, has enough information and ready to work on now.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

8 participants