Sensiron SCD30 Configuration on Raspberry Pi (adafruit_scd30

CircuitPython on hardware including Adafruit's boards, and CircuitPython libraries using Blinka on host computers.

Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.
Locked
User avatar
Veer
 
Posts: 2
Joined: Thu Jun 30, 2022 3:59 pm

Sensiron SCD30 Configuration on Raspberry Pi (adafruit_scd30

Post by Veer »

Hi there,

I have found myself severely stuck with this problem and would appreciate any help:

My aim: I am trying to configure/callibrate the Sensiron SCD30 sensors in using CircuitPython's adafruit_scd30 library so that I can use the sensor to log data. My hope is to run a configuration/calibration script that calibrates and sets all the parameters for the sensor and stores them in the sensor's supposed non-volatile memory such that I can just call the sensor in a different script to just log data without having to restate all these values.

The problem: I am able to configure the Sensor in one script, but the moment I try and use the sensor in a different script all the sensor parameters return back to default values. Code 1 shows how I configure the sensor (in this code all I do is change the measurement interval to 5 seconds as opposed to the default 2 seconds, which seems to work well. (Ignore the loads of libraries)

Code 1:

Code: Select all

#Importing required libraries
import datetime as dt
import pandas as pd
import os
import pause
from time import sleep
import board
import busio
import adafruit_scd30

# SCD-30 has tempremental I2C with clock stretching, datasheet recommends
# starting at 50KHz
i2c = busio.I2C(board.SCL, board.SDA, frequency=50000)
scd = adafruit_scd30.SCD30(i2c)

print("----Preconfigured Settings----")
print("Ambient pressure setting:" + str(scd.ambient_pressure))
print("Altitude setting: " + str(scd.altitude))
print("Measurement interval setting: " + str(scd.measurement_interval) + " seconds")
print("Self calibration setting: " + str(scd.self_calibration_enabled))
print("Forced recalibration reference setting: " + str(scd.forced_recalibration_reference))

print("\n----Running Configuration----")
scd.measurement_interval = 5
print("Measurement interval set to: " + str(scd.measurement_interval))


print("\n----Configured Settings----")
print("Ambient pressure setting:" + str(scd.ambient_pressure))
print("Altitude setting: " + str(scd.altitude))
print("Measurement interval setting: " + str(scd.measurement_interval) + " seconds")
print("Self calibration setting: " + str(scd.self_calibration_enabled))
print("Forced recalibration reference setting: " + str(scd.forced_recalibration_reference))
Code 1 Output:
----Preconfigured Settings----
Ambient pressure setting:0
Altitude setting: 0
Measurement interval setting: 2 seconds
Self calibration setting: True
Forced recalibration reference setting: 5

----Running Configuration----
Measurement interval set to: 5

----Configured Settings----
Ambient pressure setting:0
Altitude setting: 0
Measurement interval setting: 5 seconds
Self calibration setting: True
Forced recalibration reference setting: 5

BUT.....when I then use the sensor in a different code these values reset as shown by Code 2, which shows that the measurement interval has returned back to 2 seconds even though Code 1 was just run previously. The same thing happens with all other parameters e.g. temperature_offset etc.

Code 2:

Code: Select all

#Importing required libraries
import datetime as dt
import pandas as pd
import os
import pause
from time import sleep
import board
import busio
import adafruit_scd30

# SCD-30 has tempremental I2C with clock stretching, datasheet recommends
# starting at 50KHz
i2c = busio.I2C(board.SCL, board.SDA, frequency=50000)
scd = adafruit_scd30.SCD30(i2c)

print("----Sensor Settings----")
print("Ambient pressure setting:" + str(scd.ambient_pressure))
print("Altitude setting: " + str(scd.altitude))
print("Measurement interval setting: " + str(scd.measurement_interval) + " seconds")
print("Self calibration setting: " + str(scd.self_calibration_enabled))
print("Forced recalibration reference setting: " + str(scd.forced_recalibration_reference))
Code 2 Output:
----Sensor Settings----
Ambient pressure setting:0
Altitude setting: 0
Measurement interval setting: 2 seconds
Self calibration setting: True
Forced recalibration reference setting: 5

I don't know why this is happening, but I have a hunch it has something to do with instantiating scd again in the new code. Any way to fix this would be very much appreciated!!

Thanks!

User avatar
adafruit_support_carter
 
Posts: 29056
Joined: Tue Nov 29, 2016 2:45 pm

Re: Sensiron SCD30 Configuration on Raspberry Pi (adafruit_s

Post by adafruit_support_carter »

Yep, your hunch is correct. It's the re-instantiating. Here's the initialization code that is run with each instance:
https://github.com/adafruit/Adafruit_Ci ... y#L88-L105

The measurement_interval is set to 2.

Why can't the logging script set these to the desired values? There aren't a lot of things to set.

User avatar
mikeysklar
 
Posts: 13824
Joined: Mon Aug 01, 2016 8:10 pm

Re: Sensiron SCD30 Configuration on Raspberry Pi (adafruit_s

Post by mikeysklar »

The initialization code will set the measurement_interrval back to 2 seconds (as you concluded with). You will need to keep your desired measurement_interval defined in your code after initialization.

https://github.com/adafruit/Adafruit_Ci ... /issues/17

User avatar
Veer
 
Posts: 2
Joined: Thu Jun 30, 2022 3:59 pm

Re: Sensiron SCD30 Configuration on Raspberry Pi (adafruit_s

Post by Veer »

Thanks for such a swift response mikeysklar and adafruit_support_carter!

So the project I'm doing essentially requires me to calibrate the sensors then mount them in a room and log the CO2 levels. It is easy to select settings such as temperature_offset and measurment_interval at the start of the data logging script, because those are "known" values. However, I want to pre-calibrate the forced_calibration_setting in a controlled environment (before mounting) where I can use known CO2 levels to calibrate the sensors. Hence, the desire for the configuration script.

Having said this, I read the code in the link adafruit_support_carter included and, from my basic understanding, it seems that parameter values for self_calibration_enabled and forced_recalibration_reference are not reset when scd is instantiated. Is this true? Does this mean I can write a configuration script to calibrate these parameters and not need to reset them when I run the data logging script?

And am I correct in saying that if the power is switched off these values are meant to be held on the sensor's non-volatile memory? Because when I configure them and then switch the power off and on, and call to check these values, the self_calibration_enabled setting stays as it was (True or False) before it was switched off, but the forced_calibration_setting always resets to 400. Why is that?

User avatar
mikeysklar
 
Posts: 13824
Joined: Mon Aug 01, 2016 8:10 pm

Re: Sensiron SCD30 Configuration on Raspberry Pi (adafruit_s

Post by mikeysklar »

The forced calibration settings will hold through resets and work with you scenario of:

calibrate with known ppm --> power off --> place and power up

You need to use the "forced_recalibration_reference.setter" to get something other than the default minimum of 400.

https://github.com/adafruit/Adafruit_Ci ... 30.py#L223

User avatar
adafruit_support_carter
 
Posts: 29056
Joined: Tue Nov 29, 2016 2:45 pm

Re: Sensiron SCD30 Configuration on Raspberry Pi (adafruit_s

Post by adafruit_support_carter »

There's some additional information here that might be useful as well:
https://learn.adafruit.com/adafruit-scd ... alibration

Locked
Please be positive and constructive with your questions and comments.

Return to “Adafruit CircuitPython”