Closed bilbolodz closed 7 years ago
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
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)
Can you please check if your problem is a duplicate to https://github.com/Apollon77/I2CSoilMoistureSensor/issues/8 and solutions there work too?
I will try it this evening.
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;
Serial.print(F("Temp C: ")); Serial.println(tempC);
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);
Serial.print(F("Hum i2c: ")); Serial.print(sensorValueM); Serial.print(F(" Humidity: ")); Serial.print(moistureLevel); Serial.println(F(" %"));
[..] `
@Miceuz: doyou have an idea?!
It could be some interaction with Mysensors code
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.
So "it's feature not a bug"? It's battery powered sleeping sensor so reads are indeed rare.
Well, it's neither feature, nor a bug. A workaround for buggy world. I should add this to the documentation.
;-)) Thank you for all your support! I will close this one.
I should add this to the documentation. Very good idea
First reading of getCapacitance() provide "old data". To get current moisture reading you have to call getCapacitance() twice.