8000
Skip to content

Improve ccs811 precision - #1428

Merged
jesserockz merged 4 commits into
esphome:devfrom
TheNetAdmin:TheNetAdmin-patch-1
Jan 22, 2021
Merged

Improve ccs811 precision#1428
jesserockz merged 4 commits into
esphome:devfrom
TheNetAdmin:TheNetAdmin-patch-1

Conversation

@TheNetAdmin
@TheNetAdmin TheNetAdmin commented Dec 22, 2020
Copy link
Copy Markdown
Contributor

Update ccs811 environment setting precision

Description:

Related issue (if applicable):

This pull request improves the ccs811 sensor's environment value precision.

The previous implementation just left shift 1 bit of humidity and temperature value as high byte, and leave low byte as 0x00.

According to ccs811 programmer manual page 18, this approach loses the precision of the 9bit fraction field.

A better implementation is from Adafruit_CCS811. I ported this implementation and created this pull request.

Pull request in esphome-docs with documentation (if applicable): esphome/esphome-docs#

  • The esphome-docs is not affected.

Checklist:

  • The code change is tested and works locally.
  • Tests have been added to verify that the new code works (under tests/ folder).
    • No new test needed
    • I added serial debug output of the humidity and temperature value sent to ccs811, see line 111-112 Deleted

If user exposed functionality or configuration variables are added/changed:

  • Documentation added/updated in esphome-docs.
    • No user exposed functionality is affected

Update ccs811 environment precision
@TheNetAdmin TheNetAdmin changed the title Update ccs811.cpp Improve ccs811 precision Dec 22, 2020
@ssieb
ssieb commented Jan 15, 2021
Copy link
Copy Markdown
Member

According to that document on that page, it says "Currently the CCS811 supports fractional values in increments of 0.5, resultantly only the most significant bit of the fraction field needs to be set." So the current code is correct and it even mentions that in the comment.

@TheNetAdmin
Copy link
Copy Markdown
Contributor Author

According to that document on that page, it says "Currently the CCS811 supports fractional values in increments of 0.5, resultantly only the most significant bit of the fraction field needs to be set." So the current code is correct and it even mentions that in the comment.

Yes, you are correct regarding the Cambridge CMOS Censor's CCS811 Programming Guide (page 18).

But I'm using Adafruit CCS811 which doesn't mention such a limitation (page 19).

Personally, I think it still makes sense to improve the accuracy in general CCS811 sensors.

Comment thread esphome/components/ccs811/ccs811.cpp Outdated
Comment on lines +111 to +112
ESP_LOGD(TAG, " Env Humidity: %u", hum_conv);
ESP_LOGD(TAG, " Env Temperature: %u", temp_conv);
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think this is useful. If you're going to log, then print the actual values, not the coded ones.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agreed, I just deleted these log outputs. I previously used them to debug my code, but it seems not useful to others.

@ssieb
ssieb commented Jan 15, 2021
Copy link
Copy Markdown
Member

It's the same sensor. I really don't think there could be more than one with the same name anyway. However, I guess there's no harm in using the full resolution even if it's going to be ignored by the chip for now.

@ssieb
ssieb commented Jan 15, 2021
Copy link
Copy Markdown
Member

The newer datasheet linked from Adafruit doesn't specifically mention that only one bit is used, but the examples still only go to .5 and have the second byte as 0.

@jesserockz
jesserockz merged commit 8352f52 into esphome:dev Jan 22, 2021
@jesserockz jesserockz added this to the 1.16.0b5 milestone Jan 22, 2021
jesserockz pushed a commit that referenced this pull request Jan 26, 2021
This was referenced Jan 26, 2021
This was referenced Feb 3, 2021
micronen pushed a commit to micronen/esphome that referenced this pull request Feb 5, 2021
@github-actions github-actions Bot locked and limited conversation to collaborators Sep 14, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants

0