Odd behavior with clue and SCD30

For CircuitPython issues, ask in the Adafruit CircuitPython forum.

Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.
Locked
User avatar
mspearfungi
 
Posts: 48
Joined: Mon Jul 07, 2014 9:51 am

Odd behavior with clue and SCD30

Post by mspearfungi »

Introduction
===========
I can't find any description of an error that happens on power on but disappears on reset. Here is an example and there is probably a simple explanation I'm missing.

The Problem
===========
When programing the Clue, as it is plugged into my PC with USB, the code works perfectly every time. When on battery power the code does not run and and error message is displayed on the Clue (included below). But here is the weird part: If the Reset button on the Clue is pressed the code works perfectly.

Circuit description
================
Very simple. The Clue is the center of the device. In use it is powered by an Adafruit Power Boost 500 C with a 2000 mAh lithium battery.
The SCD30 is Stemma connected to the Clue. There is a power switch between the power board and the Clue.

Egregious Code
===============
# Almost Working Version of Mushroom Farmer's friend environmental sensor
import adafruit_scd30
import time
import board
import digitalio
import busio
from adafruit_clue import clue

# Create object for CO2
scd = adafruit_scd30.SCD30(board.I2C())

# check scd30
print(scd.CO2)

clue_display = clue.simple_text_display(text_scale=4, colors=(clue.WHITE,))
# Set up non variant titles
clue_display[1].color = clue.GREEN
clue_display[2].color = clue.RED
clue_display[3].color = clue.BLUE

print("Check point B")

while True:
clue_display[1].text = "CO2 %d ppm" % scd.CO2
ftemp = (scd.temperature * 1.8) +32
clue_display[2].text = "Temp %0.0f F" % ftemp
clue_display[3].text = "RH %0.0f %%" % scd.relative_humidity
clue_display.show()
time.sleep(2)


Error Message when code fails
===========================
Board ID:clue_nrf52840_express
code.py output:
Check point A
Traceback (most recent call last):
File “code.py”, line 8, in <module>

File “adafruit_clue.py”, line 930, in <module>
File “adafruit_clue.py”, line 221, in __init__
File “adafruit_lsm6ds/__init__py”, line 194, in __init__.py
ValueError: No I2C device a address: 6a

Code done running.



Alternate Approach
==================
Note that looking in the Forums shows a comment about starting up the "temperamental" SCD30. When I try that I get another error amounting to P19 already in use.

User avatar
mspearfungi
 
Posts: 48
Joined: Mon Jul 07, 2014 9:51 am

Re: Odd behavior with clue and SCD30

Post by mspearfungi »

Please not that in the previous post the indentation did not survive the copy paste maneuver.

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

Re: Odd behavior with clue and SCD30

Post by adafruit_support_carter »

It could be a race condition on initial power. The CLUE is coming up faster than the SCD30, so tries to talk to it before it's ready. But with the reset, this no longer happens, since everything has then been powered for some time.

Try adding a delay before initializing the SCD30:

Code: Select all

# Create object for CO2
time.sleep(1)
scd = adafruit_scd30.SCD30(board.I2C())

User avatar
mspearfungi
 
Posts: 48
Joined: Mon Jul 07, 2014 9:51 am

Re: Odd behavior with clue and SCD30

Post by mspearfungi »

Thanks for your reply. I liked it and implemented it.

But, no joy. I ran the delay before creating the scd object up to 10 seconds.

Same error message. Same situation that resolves itself on Reset.

Weird.

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

Re: Odd behavior with clue and SCD30

Post by adafruit_support_carter »

OK, maybe something with power? Why are you using a PowerBoost instead of just directly connecting the battery to the CLUE?

User avatar
mspearfungi
 
Posts: 48
Joined: Mon Jul 07, 2014 9:51 am

Re: Odd behavior with clue and SCD30

Post by mspearfungi »

Another interesting suggestion. I tried the following and although it still does not work there may be a clue.

Test 1: Plugged a charged battery directly into the Clue, bypassing the PowerBoost.
Result: No improvement.

Test 2: Plugged a wall wart directly into the clue by USB.
Result: No improvement.

Clue:
I noticed that when I plugged in the Clue board, and it crashes the error message happens right away. When I reset it there is a long delay where I put in the sleep command. The sleep command is before the scd call and it is not getting that far.

Conclusion: The error is occurring before the scd = adafruit_scd.... call.

Test 3: I put a print statement after every line prior to the scd call and re-ran the program.
Result: The last successfully run line was before the line: from adafruit_clue import clue

Conclusion: The error is coming from the Clue library not the SCD.

Now what?

Test 4: I put the clue import statement at the start of the program, before the scd import.
Result: No joy. The program crashes at the clue import command.

Follow-up 1: I made sure the Clue board is running CircuitPython 7.0.0 from 2021-09-20
Follow-up 2: I checked the Clue library and discovered there is a new version as of today. I downloaded it and replaced the adafruit_clue.mpy on the board with the new adafruit_clue.mpy
Result: The board is now crashing after during the execution of the first line of the program which is; from adafruit_clue import clue

Now this is the first indication I have seen that it just might not all be my fault for writing bad code.

Follow-up 3: Nuke the board and reload the operating system and the newest library code. Reload my code complete with all the print statements.
Result: Same problem.

Any ideas?

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

Re: Odd behavior with clue and SCD30

Post by adafruit_support_carter »

Try this as a test code, save as code.py in CIRCUITPY folder:

Code: Select all

from adafruit_clue import clue

print("hello world")
With that, you get error messages instead of seeing "hello world" printed?

User avatar
mspearfungi
 
Posts: 48
Joined: Mon Jul 07, 2014 9:51 am

Re: Odd behavior with clue and SCD30

Post by mspearfungi »

Thanks for your continued help for this frustrating issue.

When the Clue board is plugged into the computer with USB:
Result: No error

When plugged into wall wart error message follows:

Traceback (most recent call last):
File "code.py", line 1, in <module>

File "adafruit_clue.py", line 930, in <module>
File "adafruit_clue.py", line 221, in __init__
File "adafruit_lsm6ds/__init__.py", line 194, in __init__.py", line 194, in __init__
Value error: No I2C device as address 6a

I hope this means more to you than it does to me.

User avatar
mspearfungi
 
Posts: 48
Joined: Mon Jul 07, 2014 9:51 am

Re: Odd behavior with clue and SCD30

Post by mspearfungi »

Note new finding!

When I unplug the SCD30 from the Stemma connector the error disappears.

Must be significant of something.

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

Re: Odd behavior with clue and SCD30

Post by adafruit_support_carter »

Probably still some kind of initial power race condition. Try this version:

Code: Select all

import time
time.sleep(5)
from adafruit_clue import clue

print("hello world")

User avatar
mspearfungi
 
Posts: 48
Joined: Mon Jul 07, 2014 9:51 am

Re: Odd behavior with clue and SCD30

Post by mspearfungi »

Works now. What a relief.

Thanks so much. If you need a positive review for your supervisor count me in.

I buy LOTs of products from Adafruit. Not for price. You are supportive of inexpert makers.
That makes it possible to create laboratory and farm instruments for markets too small to be served by the usual science supply houses.

Thanks again.

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

Re: Odd behavior with clue and SCD30

Post by adafruit_support_carter »

Cool, glad that worked. Nothing special about using 5 seconds. That was just a super conservative initial guess. You can try lowering that value until you find the minimum you can get away with. (if you want to try and minimize initial lag)

Do you have any links to more info on the lab or farm equipment you are working on? We always like to see how things are being used.

User avatar
mspearfungi
 
Posts: 48
Joined: Mon Jul 07, 2014 9:51 am

Re: Odd behavior with clue and SCD30

Post by mspearfungi »

For mushroom farmers, commercial or hobby scale, environmental control is critical to getting a crop and avoiding yield loses from disease. The new true CO2 sensors have not hit the agricultural instrument market yet and the "calculated CO2" sensors are not workable.

With the Clue, a simple 3d printed case, and the SCD30, I am making pocketable environmental sensor gifts that my co-workers find immediately useful. It's my version of a home handicraft since I can't sew and my woodworking projects look like they were made by beavers.

Thanks so much for your help. In the end the delay time.sleep(5) was not needed. I just imported the SCD30 first and print(scd30.CO2) a reading first. Then start up the clue.

This is the second major revision as the SCD40 and SCD41 sensors have lower precision.

Next version will include an Adalogger.

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

Return to “CLUE Board”