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))
----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))
----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!