Skip to content

Commit 5af0f25

Browse files
committed
remove reset from init
1 parent b507ba0 commit 5af0f25

File tree

2 files changed

+38
-9
lines changed

2 files changed

+38
-9
lines changed

adafruit_scd30.py

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -61,8 +61,6 @@ def __init__(self, i2c_bus, ambient_pressure=0, address=SCD30_DEFAULT_ADDR):
6161
self._buffer = bytearray(18)
6262
self._crc_buffer = bytearray(2)
6363

64-
self.reset()
65-
6664
# set continuous measurement interval in seconds
6765
self.measurement_interval = 2
6866
# activate automatic self-calibration
@@ -79,13 +77,6 @@ def reset(self):
7977
"""Perform a soft reset on the sensor, restoring default values"""
8078
self._send_command(_CMD_SOFT_RESET)
8179
sleep(0.1) # not mentioned by datasheet, but required to avoid IO error
82-
# pylint:disable=protected-access
83-
# are we using Blinka?
84-
if hasattr(self.i2c_device.i2c, "_i2c"):
85-
# with an MCP2221?
86-
if hasattr(self.i2c_device.i2c._i2c, "_mcp2221"):
87-
# then lets reset that too
88-
self.i2c_device.i2c._i2c._mcp2221._reset()
8980

9081
@property
9182
def measurement_interval(self):

examples/scd30_reset.py

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
# SPDX-FileCopyrightText: 2021 by Carter Nelson, written for Adafruit Industries
2+
#
3+
# SPDX-License-Identifier: Unlicense
4+
import time
5+
import board
6+
import busio
7+
import adafruit_scd30
8+
9+
i2c = busio.I2C(board.SCL, board.SDA)
10+
scd = adafruit_scd30.SCD30(i2c)
11+
12+
# The SCD30 reset generates a hiccup on the SCL and SDA lines
13+
# which can end up not being handled well by different hosts.
14+
scd.reset()
15+
16+
# The MCP2221 is known to not like the SCD30 reset hiccup.
17+
# See below for more information:
18+
# https://github.com/adafruit/Adafruit_CircuitPython_SCD30/issues/2
19+
# Can get around it by resetting via this hack.
20+
if hasattr(i2c, "_i2c"):
21+
# we're using Blinka, check for MCP2221
22+
if hasattr(i2c._i2c, "_mcp2221"):
23+
# reset it
24+
i2c._i2c._mcp2221._reset()
25+
26+
while True:
27+
# since the measurement interval is long (2+ seconds) we check for new data before reading
28+
# the values, to ensure current readings.
29+
if scd.data_available:
30+
print("Data Available!")
31+
print("CO2:", scd.CO2, "PPM")
32+
print("Temperature:", scd.temperature, "degrees C")
33+
print("Humidity:", scd.relative_humidity, "%%rH")
34+
print("")
35+
print("Waiting for new data...")
36+
print("")
37+
38+
time.sleep(0.5)

0 commit comments

Comments
 (0)