Reef-Pi CO2 Monitoring

atlantean

Active Member
View Badges
Joined
Dec 31, 2020
Messages
244
Reaction score
258
Location
Oregon
Rating - 0%
0   0   0
Finished writing the code to integrate ambient CO2 monitoring using the SCD41 sensor through the I2C port on my Robotank. I leveraged this guidance and then just modified it to reflect the SCD41 sensor: https://www.reef2reef.com/threads/sht20-temperature-humidity-with-reef-pi.817553/

I'm still working on some interference issues that popped up, but I think its related to a setting I changed when I was problem-solving the i2c connectivity and forgot to change back.

Screenshot 2023-03-27 at 12.52.25 PM.png

Thought I'd post the script in case its helpful for anyone else:

import os
import time
import board
import busio
import adafruit_scd4x

i2c_address = 0x62
i2c_bus = busio.I2C(board.SCL, board.SDA)
rootDir = "/dev/shm"
WorkDrir = "/ReeFHardwareComs/SCD41"
path = rootDir + WorkDrir
access_rights = 0o755

F_Hum_Name = "SCD41_Hum"
F_Temp_name = "SCD41_Temp"
F_CO2_name = "SCD41_CO2"

if not os.path.isdir(path):
try:
os.makedirs(path, access_rights)
except OSError:
print("Creation of the directory %s failed" % path)
else:
print("Successfully created the directory %s " % path)

scd4x = adafruit_scd4x.SCD4X(i2c_bus, i2c_address)
print("Serial number:", [hex(i) for i in scd4x.serial_number])

scd4x.start_periodic_measurement()
print("Waiting for first measurement....")

while True:
if scd4x.data_ready:
co2 = scd4x.CO2
temperature_c = scd4x.temperature
temperature_f = temperature_c * 9 / 5 + 32
humidity = scd4x.relative_humidity

print("CO2: %d ppm" % co2)
print("Temperature: %0.1f °F" % temperature_f)
print("Humidity: %0.1f %%" % humidity)
print()

F_CO2 = open(path + "/" + F_CO2_name, "w")
strSHT = repr(co2)
F_CO2.write(strSHT)
F_CO2.close()
os.chmod(path + "/" + F_CO2_name, access_rights)

F_Temp = open(path + "/" + F_Temp_name, "w")
strSHT = repr(temperature_f)
F_Temp.write(strSHT)
F_Temp.close()
os.chmod(path + "/" + F_Temp_name, access_rights)

F_Hum = open(path + "/" + F_Hum_Name, "w")
strSHT = repr(humidity)
F_Hum.write(strSHT)
F_Hum.close()
os.chmod(path + "/" + F_Hum_Name, access_rights)

time.sleep(1)
 

Sral

Valuable Member
View Badges
Joined
May 2, 2022
Messages
1,005
Reaction score
971
Location
Germany
Rating - 0%
0   0   0

A worm with high fashion and practical utility: Have you ever kept feather dusters in your reef aquarium?

  • I currently have feather dusters in my tank.

    Votes: 68 37.8%
  • Not currently, but I have had feather dusters in my tank in the past.

    Votes: 59 32.8%
  • I have not had feather dusters, but I hope to in the future.

    Votes: 25 13.9%
  • I have no plans to have feather dusters in my tank.

    Votes: 28 15.6%
  • Other.

    Votes: 0 0.0%
Back
Top