Due to high demand, expect some shipping delays at this time - orders may not ship for up to 2-3 business days.
0

Odd behavior with clue and SCD30
Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.

Odd behavior with clue and SCD30

by mspearfungi on Wed Dec 08, 2021 12:36 pm

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.

mspearfungi
 
Posts: 42
Joined: Mon Jul 07, 2014 9:51 am

Re: Odd behavior with clue and SCD30

by mspearfungi on Wed Dec 08, 2021 12:38 pm

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

mspearfungi
 
Posts: 42
Joined: Mon Jul 07, 2014 9:51 am

Re: Odd behavior with clue and SCD30

by adafruit_support_carter on Wed Dec 08, 2021 1:21 pm

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 | TOGGLE FULL SIZE
# Create object for CO2
time.sleep(1)
scd = adafruit_scd30.SCD30(board.I2C())

adafruit_support_carter
 
Posts: 23519
Joined: Tue Nov 29, 2016 2:45 pm

Re: Odd behavior with clue and SCD30

by mspearfungi on Wed Dec 08, 2021 3:35 pm

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.

mspearfungi
 
Posts: 42
Joined: Mon Jul 07, 2014 9:51 am

Re: Odd behavior with clue and SCD30

by adafruit_support_carter on Wed Dec 08, 2021 3:42 pm

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

adafruit_support_carter
 
Posts: 23519
Joined: Tue Nov 29, 2016 2:45 pm

Re: Odd behavior with clue and SCD30

by mspearfungi on Wed Dec 08, 2021 6:02 pm

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?

mspearfungi
 
Posts: 42
Joined: Mon Jul 07, 2014 9:51 am

Re: Odd behavior with clue and SCD30

by adafruit_support_carter on Fri Dec 10, 2021 2:29 pm

Try this as a test code, save as code.py in CIRCUITPY folder:
Code: Select all | TOGGLE FULL SIZE
from adafruit_clue import clue

print("hello world")


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

adafruit_support_carter
 
Posts: 23519
Joined: Tue Nov 29, 2016 2:45 pm

Re: Odd behavior with clue and SCD30

by mspearfungi on Fri Dec 10, 2021 2:49 pm

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.

mspearfungi
 
Posts: 42
Joined: Mon Jul 07, 2014 9:51 am

Re: Odd behavior with clue and SCD30

by mspearfungi on Fri Dec 10, 2021 2:51 pm

Note new finding!

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

Must be significant of something.

mspearfungi
 
Posts: 42
Joined: Mon Jul 07, 2014 9:51 am

Re: Odd behavior with clue and SCD30

by adafruit_support_carter on Sun Dec 12, 2021 3:04 pm

Probably still some kind of initial power race condition. Try this version:
Code: Select all | TOGGLE FULL SIZE
import time
time.sleep(5)
from adafruit_clue import clue

print("hello world")

adafruit_support_carter
 
Posts: 23519
Joined: Tue Nov 29, 2016 2:45 pm

Re: Odd behavior with clue and SCD30

by mspearfungi on Sun Dec 12, 2021 5:34 pm

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.

mspearfungi
 
Posts: 42
Joined: Mon Jul 07, 2014 9:51 am

Re: Odd behavior with clue and SCD30

by adafruit_support_carter on Sun Dec 12, 2021 7:41 pm

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.

adafruit_support_carter
 
Posts: 23519
Joined: Tue Nov 29, 2016 2:45 pm

Re: Odd behavior with clue and SCD30

by mspearfungi on Wed Dec 15, 2021 6:02 pm

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.

mspearfungi
 
Posts: 42
Joined: Mon Jul 07, 2014 9:51 am

Please be positive and constructive with your questions and comments.