0

Stemma moisture sensor read issues, Arduino/Clue
Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.

Stemma moisture sensor read issues, Arduino/Clue

by liquidsquid793 on Thu Mar 11, 2021 9:20 pm

Hi All,

I posted this in the Clue forum, but maybe I will get a little more traction here. I am working on an irrigation system for my office plants using 4x Stemma moisture sensors. I am using Arduino for the development environment, so I have (I think) the latest libraries for the seesaw. Currently I am only testing a single sensor board to get this patched into my main application.

I run the example code for testing the sensor, and it fails (stuck) reading the touchRead(0). Otherwise I get the revision and temperature just fine. I try values other than '0' for the pin, and I immediately get a '0' value, no stuck waiting for result.

Looking into the source for touchRead(), there is a loop that will run forever until the result from the read is not 65535. Unfortunately I never get a result that allows this loop to exit. It is always 65535. I put a means to allow the loop to exit on a timeout and my program can continue with a bad number but I would really like to sort this out.

So the version reported from the soil sensors is:

seesaw started! version: FBA278F


Temperature is realistic, hovering around 23C in the office with a little noise.

Can anyone else run the example Arduino code on their board and let me know if it works or not? What is the version?
Right now it looks like there is a software bug somewhere on the seesaw side.

I don't yet want to jump into Python being I have code from other older C projects I wish to re-use.

liquidsquid793
 
Posts: 25
Joined: Sat Feb 27, 2021 4:16 pm

Re: Stemma moisture sensor read issues, Arduino/Clue

by liquidsquid793 on Thu Mar 11, 2021 9:50 pm

Dang, right after posting this I found the "cure" simply by changing timing to the call on read() from 1000uS to 2000uS. There probably is some best performing timing someplace, but a 2mS delay is fine for my application.

So it seems that this timing number needs to be different on the Clue than on other platforms. Hope this helps others.

Code: Select all | TOGGLE FULL SIZE
/*!
 ******************************************************************************
 *  @brief      read the analog value on an capacitive touch-enabled pin.
 *
 *  @param      pin the number of the pin to read.
 *
 *  @return     the analog value. This is an integer between 0 and 1023
 ****************************************************************************/
uint16_t Adafruit_seesaw::touchRead(uint8_t pin) {
  uint8_t buf[2];
  uint8_t p = pin;
  uint16_t ret = 65535;
  uint16_t timeout = 500; //0.5 second timeout.
  do {
    delay(1); //1mS, but function passes a 1 second delay.
    this->read(SEESAW_TOUCH_BASE, SEESAW_TOUCH_CHANNEL_OFFSET + p, buf, 2,
               2000); //delay is in microseconds.
    ret = ((uint16_t)buf[0] << 8) | buf[1];
  } while (ret == 65535 && timeout--);
  return ret;
}

liquidsquid793
 
Posts: 25
Joined: Sat Feb 27, 2021 4:16 pm

Re: Stemma moisture sensor read issues, Arduino/Clue

by Bobbassoonguy on Sat Apr 10, 2021 11:30 am

I had the same issue as you, the capacitive sensor was returning only the temperature value as the capacitance reading. I saw your post and got so excited about fixing the library, but with your edits I still had the same issues. Any other ideas?

Bobbassoonguy
 
Posts: 1
Joined: Wed Oct 30, 2019 5:03 pm

Please be positive and constructive with your questions and comments.