guild icon
Toit
#SCD30 set the intervals
Thread channel in help
Shadi
Shadi 06/08/2023 02:25 PM
Hi every one, Is it possible to set the measuring interval for scd30? currently it seems that is in the highest measuring interval that causes a lot of energy usage . Thanks in davance
floitsch
floitsch 06/08/2023 02:28 PM
I would need to look at the specs for the scd30.
floitsch
floitsch 06/08/2023 02:28 PM
Looking at the code it seems like it's requesting a measurement every time one calls read.(edited)
floitsch
floitsch 06/08/2023 02:29 PM
The constructor of the driver states that the sensor is initialized in "continuous measurement mode".
floitsch
floitsch 06/08/2023 02:29 PM
But that this can be switched off.
Shadi
Shadi 06/08/2023 02:30 PM
yes, true. but in Toit as i checked scd30 toit's driver i found it i snot possible
Shadi
Shadi 06/08/2023 02:30 PM
esp_err_t scd30_get_measurement_interval(i2c_dev_t *dev, uint16_t *interval_seconds)
Get measurement interval.

Gets the interval used bythe SCD30 sensor to measure in continuous measurement mode. Saved in non-volatile memory.
floitsch
floitsch 06/08/2023 02:32 PM
I see.
floitsch
floitsch 06/08/2023 02:33 PM
There is a command (0x4600) that can set the measurement interval in seconds.
floitsch
floitsch 06/08/2023 02:33 PM
it's set to 2 by default (the fastest).
Shadi
Shadi 06/08/2023 02:34 PM
can I change it and use my modified librray?
floitsch
floitsch 06/08/2023 02:34 PM
Looking into whether there is an easy way to try a higher rate without modifying the package.
πŸ‘1
floitsch
floitsch 06/08/2023 02:35 PM
(mainly for testing).
floitsch
floitsch 06/08/2023 02:39 PM
Try to add the following after you created the driver.
So, let's assume you have sensor := scd30.Scd30 device.
Then you might be able to change the measuring interval as follows
seconds := #[0x00, 0x10] command := #[0x46, 0x00] + seconds + #[sensor.compute_crc8_ seconds] sensor.device_.write command
floitsch
floitsch 06/08/2023 02:39 PM
That's reaching into the sensor's private functions, but for testing that should be fine.
floitsch
floitsch 06/08/2023 02:40 PM
If that works I can try to add the missing function(s).
floitsch
floitsch 06/08/2023 02:41 PM
(In the example code here the seconds is initialized to 0x10 which is 16. So not a huge difference, but you can increase that to 0xFF (255), or even up to a total of 1800 in which case you also need to change the most-significant byte).
Shadi
Shadi 06/08/2023 02:44 PM
basic question. I did not understand where should I add these lines? in my toit program or scd30 toit driver
floitsch
floitsch 06/08/2023 02:44 PM
In your toit program.
floitsch
floitsch 06/08/2023 02:44 PM
There should be a place where you create the Scd30 object.
floitsch
floitsch 06/08/2023 02:44 PM
It should look something like sensor := scd30.Scd30 device.
floitsch
floitsch 06/08/2023 02:45 PM
In the example of the package it would be here: https://github.com/jacobqvist/scd30/blob/main/examples/room.toit#L28
Contribute to jacobqvist/scd30 development by creating an account on GitHub.
Shadi
Shadi 06/08/2023 02:46 PM
this is my program. I will add this now
floitsch
floitsch 06/08/2023 02:46 PM
In the example the variable is called scd30 , so just replace my sensor with scd30.
Shadi
Shadi 06/08/2023 02:47 PM
bus := i2c.Bus
--sda=gpio.Pin 21
--scl=gpio.Pin 22

device := bus.device Scd30.I2C_ADDRESS
scd30 := Scd30 device
sleep --ms=5000

while true:
reading := scd30.read
if reading.co2 > 2000:
print "Open your window: $(reading.co2.to_int)ppm"
else:
print "CO2 level is healthy: $(reading.co2.to_int)ppm"
print "Temperature: $(%.1f reading.temperature)ΒΊC"
print "Humidity: $(%.1f reading.humidity)%"
temperature := reading.co2.to_int
client.publish topic_1 "$temperature".to_byte_array
sleep --ms=5_500
// temperature := 25
client.publish topic_2 "$temperature".to_byte_array
print "i am at deep sleep %"
sleep --ms=5_500
esp32.deep_sleep (Duration --s=120)
print "I am awake"
floitschfloitsch
(In the example code here the seconds is initialized to 0x10 which is 16. So not a huge difference, but you can increase that to 0xFF (255), or even up to a total of 1800 in whic...
Shadi
Shadi 06/08/2023 02:47 PM
here you mean, instead of seconds := #[0x00, 0x10] I have to write seconds := #[0x00, 0xFF]
floitsch
floitsch 06/08/2023 02:48 PM
correct.
floitsch
floitsch 06/08/2023 02:48 PM
that would change the interval to 255 seconds.
Shadi
Shadi 06/08/2023 02:50 PM
I will back with new results in short time
πŸ‘1
floitsch
floitsch 06/08/2023 02:52 PM
Since I see your code here:
Try to call device.close and bus.close just before the esp32.deep_sleep. (You mentioned that the i2c was draining battery. Calling close might solve this.)
floitsch
floitsch 06/08/2023 02:58 PM
Another tip:
instead of having the sleep --ms=5_500 you could look at a pin and only go to deep-sleep if that pin is not grounded.
Something like:
run_jaguar_pin := gpio.Pin 32 --input --pull_up if run_jaguar_pin == 0: // The pin is pulled to ground. // Don't call deep sleep. exit 0

You can then install your program with
jag container install -D jag.disabled -D jag.timeout=2m scd30 scd30_program.toit
This makes it such that Jaguar isn't even trying to connect to WiFi if your program is running.
However, if you program terminates (and doesn't go to deep-sleep) Jaguar starts and you can update the program.

You then only need to pull pin 32 to ground (either with a button or with a wire) to start Jaguar.
Shadi
Shadi 06/08/2023 03:00 PM
I get this "Received a Toit system message. Executing the command below will
make it human readable:
----
jag decode WyNVBVVYU1UPdjIuMC4wLWFscGhhLjc5U1UAWyRVI1UQry2V/nwcXOmPwlKUFjqXWFsjVQRVRVNVCUVYQ0VQVElPTlNVHERldmljZSBpcyBub3QgZ2V0dGluZyByZWFkeS5bI1UCVVNbI1UKWyNsAAAAA1VGVQBJKs9bI2wAAAADVUZVAUkrGVsjbAAAAANVRlUCSQJKWyNsAAAAA1VGVQNJB4FbI2wAAAADVUZVBEkJLVsjbAAAAANVRlUFSQlEWyNsAAAAA1VGVQZJCPJbI2wAAAADVUZVB0kye1sjbAAAAANVRlUISTKQWyNsAAAAA1VGVQlJB54="
floitsch
floitsch 06/08/2023 03:01 PM
When did you get this error?
floitsch
floitsch 06/08/2023 03:02 PM
I'm also surprised that Jaguar can't decode the message.
If you run a program with jag run it should store the snapshot with debug information in your cache directory.
Shadi
Shadi 06/08/2023 03:02 PM
nad my SCD30 is not working any more
floitschfloitsch
When did you get this error?
Shadi
Shadi 06/08/2023 03:03 PM
when I add these line to increase the interval
floitsch
floitsch 06/08/2023 03:04 PM
You then execute it with jag run ?
Shadi
Shadi 06/08/2023 03:04 PM
no
floitsch
floitsch 06/08/2023 03:04 PM
jag container install ?
Shadi
Shadi 06/08/2023 03:04 PM
jag container install ..
floitsch
floitsch 06/08/2023 03:04 PM
and there is no stack trace?
floitsch
floitsch 06/08/2023 03:04 PM
and running jag decode WyN... does not work?(edited)
floitschfloitsch
and running jag decode WyN... does not work?(edited)
Shadi
Shadi 06/08/2023 03:05 PM
I did not try this
floitsch
floitsch 06/08/2023 03:05 PM
Normally jag monitor should do it for you.
Shadi
Shadi 06/08/2023 03:06 PM
i copied from jag monitor
floitsch
floitsch 06/08/2023 03:06 PM
I don't understand why you wouldn't get a stack trace.
floitsch
floitsch 06/08/2023 03:06 PM
I would still run the command.
floitsch
floitsch 06/08/2023 03:06 PM
It gives a bit more information on why it can't decode it.
Shadi
Shadi 06/08/2023 03:08 PM
I did this, there was a problem in my code. Now I solved
Shadi
Shadi 06/08/2023 03:17 PM
Thanks a lot. now there is no energy leakage from SCD30.
πŸ₯³1
Shadi
Shadi 06/08/2023 03:17 PM
I am really appreciated for your support
floitsch
floitsch 06/08/2023 03:18 PM
I would need to read a bit more the datasheet, but note that increasing the measurement interval means that reading the measurement might be quite out of date.
floitsch
floitsch 06/08/2023 03:19 PM
It could be better to stop continuous measurement before you go to deep-sleep and to start the sensor up when you need new measurements.
floitschfloitsch
It could be better to stop continuous measurement before you go to deep-sleep and to start the sensor up when you need new measurements.
Shadi
Shadi 06/08/2023 03:20 PM
yes, I agree. because I get this error some times: EXCEPTION error.
Device is not getting ready.
0: Scd30.wait_forready <pkg:scd30>/driver.toit:58:20
1: Scd30.read <pkg:scd30>/driver.toit:108:5
2: main adafruit_1.toit:74:22
floitsch
floitsch 06/08/2023 03:22 PM
I think that's because the device uses clock stretching which only works up to a certain point on the esp32.
floitsch
floitsch 06/08/2023 03:22 PM
Not 100% sure, but it would explain it.
floitsch
floitsch 06/08/2023 03:23 PM
That said. It it might just be that the wait_for_ready_ isn't waiting long enough.
floitsch
floitsch 06/08/2023 03:24 PM
It's currently waiting 2 seconds in total.
Shadi
Shadi 06/08/2023 03:25 PM
But before I have added those lines, I never face with error. But now, every time the toit container wakes up from deep sleep mode I face this error
floitsch
floitsch 06/08/2023 03:25 PM
nevermind.
floitsch
floitsch 06/08/2023 03:25 PM
I understand now.
floitsch
floitsch 06/08/2023 03:25 PM
When you set the sensor to continuous measurements the sensor is automatically updating a measurement every x seconds.
floitsch
floitsch 06/08/2023 03:26 PM
It stores the read value in its own memory.
floitsch
floitsch 06/08/2023 03:26 PM
When it has a value it responds to 'is-data-ready?' with 1.
floitsch
floitsch 06/08/2023 03:26 PM
If the measurement isn't there yet, it returns with 0.
floitsch
floitsch 06/08/2023 03:26 PM
Once you read a value, the is-data-ready switches back to 0.
floitsch
floitsch 06/08/2023 03:27 PM
That is, using the Toit driver here, you can only read the latest measurement once, as the driver checks that a measurement is ready.
floitsch
floitsch 06/08/2023 03:27 PM
By switching to a higher measurement interval you instructed the sensor to sample only every 255 seconds (or ever less often).
floitsch
floitsch 06/08/2023 03:28 PM
Once you have read the measurement the sensor marks the data as read and will respond 'is-data-ready?' with "0".
floitsch
floitsch 06/08/2023 03:28 PM
So if you ask the sensor for a measurement more often than every 255 seconds you will now get this error message.
floitsch
floitsch 06/08/2023 03:30 PM
If you only want to save power, wouldn't stopping continuous mode be more what you want?
floitsch
floitsch 06/08/2023 03:31 PM
Tell the sensor to stop sampling while you don't need it.
Shadi
Shadi 06/08/2023 03:31 PM
ok. I fully understand what you said. but i think it might be sth else. because when I also put 0x00, 0x10 and every 120 seconds repeat it, I also get that error
floitsch
floitsch 06/08/2023 03:31 PM
Then, when you want to measure you start continuous mode again.
Shadi
Shadi 06/08/2023 03:31 PM
excatly
ShadiOPShadi
ok. I fully understand what you said. but i think it might be sth else. because when I also put 0x00, 0x10 and every 120 seconds repeat it, I also get that error
floitsch
floitsch 06/08/2023 03:31 PM
ok. That's weird.
Shadi
Shadi 06/08/2023 03:32 PM
How can i tell the sensor to stop continuous measurement
floitsch
floitsch 06/08/2023 03:32 PM
scd30.continuous_mode = false(edited)
floitsch
floitsch 06/08/2023 03:33 PM
Be aware that turning on the continuous mode takes a few seconds.
floitsch
floitsch 06/08/2023 03:33 PM
So you might need to add a sleep --ms=5_000 or so before you can read the new measurement.
Shadi
Shadi 06/08/2023 03:33 PM
Class 'Scd30' does not have any method 'continous_mode'
floitsch
floitsch 06/08/2023 03:34 PM
sorry. typo. I updated my response.
Shadi
Shadi 06/08/2023 03:34 PM
I am writing like this: device := bus.device Scd30.I2C_ADDRESS
scd30 := Scd30 device
scd30.continuous_mode = false
floitsch
floitsch 06/08/2023 03:34 PM
correct.
floitsch
floitsch 06/08/2023 03:35 PM
So actually, what you probably want is:
set it to true when you start up.
Shadi
Shadi 06/08/2023 03:35 PM
I will update you in 2 mins
floitsch
floitsch 06/08/2023 03:35 PM
then set it to false before you go to deep-sleep.
Shadi
Shadi 06/08/2023 03:36 PM
ok
floitsch
floitsch 06/08/2023 03:39 PM
I looked through the datasheet. Couldn't see any data on how long it takes for the first measurement.
floitsch
floitsch 06/08/2023 03:39 PM
However, since it can measure every 2 seconds, I would hope that it doesn't take longer than that.
floitsch
floitsch 06/08/2023 03:40 PM
In that case you shouldn't need any sleep.
floitsch
floitsch 06/08/2023 03:40 PM
Btw. Here is the datasheet.
floitsch
floitsch 06/08/2023 03:40 PM
It needs a minute before it gives a good measurement?
Shadi
Shadi 06/08/2023 03:41 PM
I am not sure. I just saw it in a paper
floitsch
floitsch 06/08/2023 03:41 PM
In that case you should consider the following approach:
- set the sensor to continuous mode (2s would be fine).
- go to deep-sleep for a minute (or two).
- read a new measurement.
- disable continuous mode
- go to deep-sleep for much longer (like an hour or so).
floitsch
floitsch 06/08/2023 03:42 PM
You can use import system.storage to store a bit of information in RTC memory which survives deep sleep.
So you could store there whether you want to enable continuous mode, or whether you want to read a measurement.
floitschfloitsch
So actually, what you probably want is: set it to true when you start up.
Shadi
Shadi 06/08/2023 03:43 PM
when I follow this steps I get agian the same error :Class 'Null' does not have any method 'write'.
0: Device.write <sdk>/i2c.toit:168:10
1: Device.write <sdk>/i2c.toit:161:5
2: Scd30.continuous_mode= <pkg:scd30>/driver.toit:94:15
3: main adafruit_1.toit:92:27
floitsch
floitsch 06/08/2023 03:43 PM
did you do this before you called device.close ?
Shadi
Shadi 06/08/2023 03:43 PM
oh, no
floitsch
floitsch 06/08/2023 03:44 PM
Also note: the interval is written into the sensor. So you might want to reset it to 2 seconds if changing the continuous mode is what you want.(edited)
floitschfloitsch
did you do this before you called device.close ?
Shadi
Shadi 06/08/2023 03:45 PM
Now, I put it before device.close but still error : Class 'Null' does not have any method 'write'.
0: Device.write <sdk>/i2c.toit:168:10
1: Device.write <sdk>/i2c.toit:161:5
2: Scd30.continuous_mode= <pkg:scd30>/driver.toit:94:15
3: main
floitsch
floitsch 06/08/2023 03:45 PM
can you show me your program again?
floitsch
floitsch 06/08/2023 03:46 PM
(use triple back-ticks to preserve indentation)
Shadi
Shadi 06/08/2023 03:46 PM
ADAFRUIT_IO_FEEDNAME_1 ::= "Humidity New" ADAFRUIT_IO_FEEDNAME_2 ::= "Co2" HOST ::= "io.adafruit.com" co2_level := 0.0 main: network := net.open print "I am trying to connect" transport := mqtt.TcpTransport.tls network --host=HOST --root_certificates=[ certificate_roots.DIGICERT_GLOBAL_ROOT_CA ] /** // Alternatively, you can also connect without TLS, by using the // following transport: transport := mqtt.TcpTransport network --host=HOST // In that case you can remove the `certificate_roots` import. */ client := mqtt.Client --transport=transport options := mqtt.SessionOptions --client_id = "toit-example-client" --username = ADAFRUIT_IO_USERNAME --password = ADAFRUIT_IO_KEY client.start --options=options print "Connected to broker" topic_1 := "$ADAFRUIT_IO_USERNAME/feeds/$ADAFRUIT_IO_FEEDNAME_2" topic_2 := "$ADAFRUIT_IO_USERNAME/feeds/$ADAFRUIT_IO_FEEDNAME_1" bus := i2c.Bus --sda=gpio.Pin 21 --scl=gpio.Pin 22 device := bus.device Scd30.I2C_ADDRESS scd30 := Scd30 device scd30.continuous_mode = true sleep --ms=5000 //seconds := #[0x00, 0x10] //command := #[0x46, 0x00] + seconds + #[scd30.compute_crc8_ seconds] //scd30.device_.write command while true: reading := scd30.read if reading.co2 > 2000: print "Open your window: $(reading.co2.to_int)ppm" else: print "CO2 level is healthy: $(reading.co2.to_int)ppm" print "Temperature: $(%.1f reading.temperature)ΒΊC" print "Humidity: $(%.1f reading.humidity)%" temperature := reading.co2.to_int client.publish topic_1 "$temperature".to_byte_array sleep --ms=5_500 // temperature := 25 client.publish topic_2 "$temperature".to_byte_array print "i am going to deep sleep %" sleep --ms=5_500 scd30.continuous_mode = false device.close bus.close esp32.deep_sleep (Duration --s=90) print "I am awake" client.close(edited)
floitsch
floitsch 06/08/2023 03:46 PM
Please put triple back-ticks around your code.
floitsch
floitsch 06/08/2023 03:48 PM
back-ticks not ticks.(edited)
floitsch
floitsch 06/08/2023 03:49 PM
(but I can read enough).
floitsch
floitsch 06/08/2023 03:49 PM
I can't see how this program can have the error you showed.
floitsch
floitsch 06/08/2023 03:49 PM
the device is clearly open and there is no reason the call to i2c write would fail.
floitsch
floitsch 06/08/2023 03:50 PM
Can you send me the full stack-trace. (including the line of main)
floitsch
floitsch 06/08/2023 03:51 PM
Also: I would move the sleep --ms=5_500 to just before the esp32.deep_sleep call. This way you already turn off the device/bus 5 seconds earlier.(edited)
floitschfloitsch
Can you send me the full stack-trace. (including the line of main)
Shadi
Shadi 06/08/2023 03:53 PM
jag decode WyNVBVVYU1UPdjIuMC4wLWFscGhhLjc5U1UAWyRVI1UQCnNMZGzvVV+0mPI//HU6flsjVQRVRVNVDUxPT0tVUF9GQUlMRURbI2wAAAADVUFVA1sjVQNJBnpVX1pbI1UCVVNbI1ULWyNsAAAAA1VGVQBsAAD0ZVsjbAAAAANVRlUBbAAA9FFbI2wAAAADVUZVAmwAAIFMWyNsAAAAA1VGVQNJBXdbI2wAAAADVUZVBEkLmVsjbAAAAANVRlUFSQ1FWyNsAAAAA1VGVQZJDVxbI2wAAAADVUZVB0kNClsjbAAAAANVRlUIbAAArL9bI2wAAAADVUZVCWwAAKzUWyNsAAAAA1VGVQpJC7Y=
Class 'Null' does not have any method 'write'.
0: Device.write <sdk>/i2c.toit:168:10
1: Device.write <sdk>/i2c.toit:161:5
2: Scd30.continuous_mode= <pkg:scd30>/driver.toit:94:15
3: main adafruit_1.toit:92:27
floitsch
floitsch 06/08/2023 03:53 PM
That's still the same line number (92) as before.
floitsch
floitsch 06/08/2023 03:53 PM
Are you sure it is executing the modified program?
Shadi
Shadi 06/08/2023 03:53 PM
yes
Shadi
Shadi 06/08/2023 03:54 PM
line 92 is bus.close
Shadi
Shadi 06/08/2023 03:54 PM
maybe there is a conflict between bus.close and stop continuously measurment
floitsch
floitsch 06/08/2023 03:54 PM
No.
floitsch
floitsch 06/08/2023 03:54 PM
The stacktrace clearly states that it's going through Scd30.continuous_mode=.
floitsch
floitsch 06/08/2023 03:55 PM
I would try to reinstall the container again.
Shadi
Shadi 06/08/2023 03:55 PM
ok
Shadi
Shadi 06/08/2023 03:56 PM
DEBUG: Connected to broker
DEBUG: Connection established
Connected to broker
----
Received a Toit system message. Executing the command below will
make it human readable:
----
jag decode WyNVBVVYU1UPdjIuMC4wLWFscGhhLjc5U1UAWyRVI1UQqc9PDXgdWXmZcw297YaQf1sjVQRVRVNVCUVYQ0VQVElPTlNVEEkyQ19XUklURV9GQUlMRURbI1UCVVNbI1UOWyNsAAAAA1VGVQBsAAD0OlsjbAAAAANVRlUBbAAA9TVbI2wAAAADVUZVAmwAAPRlWyNsAAAAA1VGVQNsAAD0UVsjbAAAAANVRlUEbAAAgXlbI2wAAAADVUZVBWwAAIE8WyNsAAAAA1VGVQZJBMVbI2wAAAADVUZVB0kLmVsjbAAAAANVRlUISQ1FWyNsAAAAA1VGVQlJDVxbI2wAAAADVUZVCkkNClsjbAAAAANVRlULbAAArL9bI2wAAAADVUZVDGwAAKzUWyNsAAAAA1VGVQ1JC7Y=
Shadi
Shadi 06/08/2023 03:57 PM
EXCEPTION error.
I2C_WRITEFAILED
0: Device.write.<block> <sdk>/i2c.toit:161:18
1: Bus.write
<sdk>/i2c.toit:90:18
2: Device.write <sdk>/i2c.toit:168:10
3: Device.write <sdk>/i2c.toit:161:5
4: Scd30.setpressure <pkg:scd30>/driver.toit:101:13
5: Scd30.continuous_mode= <pkg:scd30>/driver.toit:92:7
6: main adafruit_1.toit:68:25
Shadi
Shadi 06/08/2023 03:57 PM
after reinstall the container
floitsch
floitsch 06/08/2023 03:57 PM
ok. That's a different error.
floitsch
floitsch 06/08/2023 03:57 PM
Move the continuous_mode = true line to after the sleep.
Shadi
Shadi 06/08/2023 03:58 PM
ok
Shadi
Shadi 06/08/2023 04:01 PM
ok, it has been solved and also no further energy wastage by continues measurements ,
floitsch
floitsch 06/08/2023 04:01 PM
great.
floitsch
floitsch 06/08/2023 04:01 PM
I'm spending a few minutes on improving your code.
floitsch
floitsch 06/08/2023 04:01 PM
Will send it to you when I'm done.
Shadi
Shadi 06/08/2023 04:01 PM
I am deeply grateful
floitsch
floitsch 06/08/2023 04:05 PM
In the meantime:
I would decomment the following lines and reset the interval to 2 seconds:
seconds := #[0x00, 0x02] command := #[0x46, 0x00] + seconds + #[scd30.compute_crc8_ seconds] scd30.device_.write command

You only need to run it once. The sensor will save it in its own memory.
Shadi
Shadi 06/08/2023 04:07 PM
ok, thanks. but I do not why I face this error again: jag decode WyNVBVVYU1UPdjIuMC4wLWFscGhhLjc5U1UAWyRVI1UQlFb87NpBUi2mjKYrpKY7k1sjVQRVRVNVCUVYQ0VQVElPTlNVHERldmljZSBpcyBub3QgZ2V0dGluZyByZWFkeS5bI1UCVVNbI1UKWyNsAAAAA1VGVQBsAACBFFsjbAAAAANVRlUBbAAAgYRbI2wAAAADVUZVAkkE0VsjbAAAAANVRlUDSQuZWyNsAAAAA1VGVQRJDUVbI2wAAAADVUZVBUkNXFsjbAAAAANVRlUGSQ0KWyNsAAAAA1VGVQdsAACsv1sjbAAAAANVRlUIbAAArNRbI2wAAAADVUZVCUkLtg== EXCEPTION error.
Device is not getting ready.
0: Scd30.wait_forready <pkg:scd30>/driver.toit:58:20
1: Scd30.read <pkg:scd30>/driver.toit:108:5
2: main adafruit_1.toit:77:22
floitsch
floitsch 06/08/2023 04:07 PM
after setting the interval to 2s?
floitsch
floitsch 06/08/2023 04:07 PM
or in general?
Shadi
Shadi 06/08/2023 04:08 PM
no, i did not check with interval 2 s yet. a moment please
Shadi
Shadi 06/08/2023 04:11 PM
yes. it happens again: jag decode WyNVBVVYU1UPdjIuMC4wLWFscGhhLjc5U1UAWyRVI1UQpcS+BbwIW4uSqlz4bHR+S1sjVQRVRVNVCUVYQ0VQVElPTlNVEEkyQ19XUklURV9GQUlMRURbI1UCVVNbI1UMWyNsAAAAA1VGVQBsAAD0WVsjbAAAAANVRlUBbAAA9VRbI2wAAAADVUZVAmwAAPSEWyNsAAAAA1VGVQNsAAD0cFsjbAAAAANVRlUESQTdWyNsAAAAA1VGVQVJC7hbI2wAAAADVUZVBkkNZFsjbAAAAANVRlUHSQ17WyNsAAAAA1VGVQhJDSlbI2wAAAADVUZVCWwAAKzeWyNsAAAAA1VGVQpsAACs81sjbAAAAANVRlULSQvV
EXCEPTION error.
I2C_WRITEFAILED
0: Device.write.<block> <sdk>/i2c.toit:161:18
1: Bus.write
<sdk>/i2c.toit:90:18
2: Device.write <sdk>/i2c.toit:168:10
3: Device.write <sdk>/i2c.toit:161:5
4: main adafruit_1.toit:70:17
Shadi
Shadi 06/08/2023 04:11 PM
but different error
Shadi
Shadi 06/08/2023 04:11 PM
` device := bus.device Scd30.I2C_ADDRESS scd30 := Scd30 device seconds := #[0x00, 0x02] command := #[0x46, 0x00] + seconds + #[scd30.compute_crc8_ seconds] scd30.device_.write command sleep --ms=5000 scd30.continuous_mode = true(edited)
floitsch
floitsch 06/08/2023 04:12 PM
Is line 70 the one with scd30.device_.write command ?
floitsch
floitsch 06/08/2023 04:12 PM
I see.(edited)
floitsch
floitsch 06/08/2023 04:12 PM
Move the sleep --ms=5000 directly after the scd30 := Scd30 device.(edited)
Shadi
Shadi 06/08/2023 04:14 PM
ok
floitsch
floitsch 06/08/2023 04:15 PM
GitHub Gist: instantly share code, notes, and snippets.
floitsch
floitsch 06/08/2023 04:15 PM
Untested, but I hope it will work.
floitsch
floitsch 06/08/2023 04:15 PM
You don't need to use everything I put in there, but this is relatively close to what I would have done.
Shadi
Shadi 06/08/2023 04:16 PM
I will test it now
floitsch
floitsch 06/08/2023 04:17 PM
There are a few things that would influence the program:
- does the sensor really need some time before it provides good measurement?
- how often do you want to measure?
- do you want to send data immediately, or do you want to save some in flash before you send it to the mqtt server.

All of these influence the design and the power consumption.
floitsch
floitsch 06/08/2023 04:18 PM
Did you succeed in changing the interval back to 2s ?
floitschfloitsch
There are a few things that would influence the program: - does the sensor really need some time before it provides good measurement? - how often do you want to measure? - do you w...
Shadi
Shadi 06/08/2023 04:18 PM
great. thanks a lot. I will consider them
floitschfloitsch
Did you succeed in changing the interval back to 2s ?
Shadi
Shadi 06/08/2023 04:18 PM
yes. and till now it is working without problem :πŸ™‚:
floitsch
floitsch 06/08/2023 04:19 PM
great.
floitsch
floitsch 06/08/2023 04:19 PM
You can remove that code now.
floitsch
floitsch 06/08/2023 04:19 PM
(If you haven't done so yet).
Shadi
Shadi 06/08/2023 04:19 PM
interesting. so now it is set
floitsch
floitsch 06/08/2023 04:20 PM
yes.
floitsch
floitsch 06/08/2023 04:20 PM
the sensor remembers the interval.
Shadi
Shadi 06/08/2023 04:22 PM
Thanks a lot, the program works seamlessly without any problem
Shadi
Shadi 06/08/2023 04:22 PM
I am incredibly grateful for your support
πŸ‘1
floitsch
floitsch 06/08/2023 04:22 PM
Great.
If you haven't done so yet: try to understand everything.
floitsch
floitsch 06/08/2023 04:23 PM
there are things in there that should be tweaked.
floitsch
floitsch 06/08/2023 04:23 PM
And some things might be overkill for you.
floitsch
floitsch 06/08/2023 04:23 PM
so don't feel obligated to take everything.
Shadi
Shadi 06/08/2023 04:23 PM
ok, sure.
166 messages in total