Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Reading of getCapacitance() gets "historical data" #11

Closed
bilbolodz opened this issue Aug 2, 2017 · 12 comments
Closed

Reading of getCapacitance() gets "historical data" #11

bilbolodz opened this issue Aug 2, 2017 · 12 comments

Comments

@bilbolodz
Copy link

First reading of getCapacitance() provide "old data". To get current moisture reading you have to call getCapacitance() twice.

@Apollon77
Copy link
Owner

I did not experienced this. Do you have waited a bit after starting the sensor? Such a behavious is only known for light measurements as I remember

@bilbolodz
Copy link
Author

bilbolodz commented Aug 7, 2017

It's battery powered sensor so after reading I'm putting it into sleep mode. And I'm not using light sensor (main purpose is soil moisture sensor)

@Apollon77
Copy link
Owner

Can you please check if your problem is a duplicate to #8 and solutions there work too?

@bilbolodz
Copy link
Author

I will try it this evening.

@bilbolodz
Copy link
Author

No It's not the same issue. It's not connected with sleeping/not sleeping. Solution "reading sensor version" also not working. My code is:

`
void loop()
{
[..]
while (sensor.isBusy()) wait(50);
float tempC = sensor.getTemperature() / (float)10;

#if defined MY_DEBUG1
Serial.print(F("Temp C: "));
Serial.println(tempC);
#endif

int sensorValueM;

//First reading gets old value so we need to read twice
while (sensor.isBusy()) wait(50);
sensorValueM = sensor.getCapacitance();

while (sensor.isBusy()) wait(50);
sensorValueM = sensor.getCapacitance();

sensor.sleep();

int moistureLevel = min(map(sensorValueM, min_hum_adc, max_hum_adc, 0, 100), 100);

moistureLevel = max(0, moistureLevel);

#if defined MY_DEBUG1
Serial.print(F("Hum i2c: "));
Serial.print(sensorValueM);
Serial.print(F(" Humidity: "));
Serial.print(moistureLevel);
Serial.println(F(" %"));
#endif
[..]
`

@Apollon77
Copy link
Owner

@Miceuz: doyou have an idea?!

@bilbolodz
Copy link
Author

It could be some interaction with Mysensors code

@Miceuz
Copy link
Contributor

Miceuz commented Aug 8, 2017

Yes, this is true. When you are reading the sensor, you are getting data from the last read. If you are doing rare reads, you should do two reads.

This is done to avoid clock stretching issues with a lot of the controllers. Clock stretching is very poorly supported over a wide variety of controllers - Raspberry Pi, ESP8266 to name a few important ones. That's why sensor returns a previous reading and makes another one after each call.

@bilbolodz
Copy link
Author

So "it's feature not a bug"? It's battery powered sleeping sensor so reads are indeed rare.

@Miceuz
Copy link
Contributor

Miceuz commented Aug 8, 2017

Well, it's neither feature, nor a bug. A workaround for buggy world. I should add this to the documentation.

@Apollon77
Copy link
Owner

;-)) Thank you for all your support! I will close this one.

@bilbolodz
Copy link
Author

I should add this to the documentation.
Very good idea

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants