0

Adafruit SeeSaw I2C Communication with I2C Handle for STM32
Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.

Adafruit SeeSaw I2C Communication with I2C Handle for STM32

by rogbeta on Tue Jun 01, 2021 8:45 am

Hello

I need some help for the I2C handling in a stm32 environment. we are building a Prototype with an adafruit soil sensor using a stm32 uC. We connect one Adafruit Soilsensor over the I2C to the controller. I2C bus will be managed with a Handle Structure HAL.
Have yu got examples or C libries for your soilsensor? (Seesaw environment)

Thanks you.

Roger

rogbeta
 
Posts: 4
Joined: Thu May 20, 2021 10:46 am

Re: Adafruit SeeSaw I2C Communication with I2C Handle for ST

by mikeysklar on Tue Jun 01, 2021 11:48 am

Tyler Linquata has an some example on github provided that is probably what you are looking for:

https://github.com/tylerlinquata/STM32-soil-sensor

We have Arduino and CircuitPython examples. Depending on your STM32 model you might be able use or adapt our code.

https://learn.adafruit.com/adafruit-ste ... /downloads

mikeysklar
 
Posts: 4920
Joined: Mon Aug 01, 2016 8:10 pm

Re: Adafruit SeeSaw I2C Communication with I2C Handle for ST

by rogbeta on Wed Jun 02, 2021 10:44 am

Hello Mike

Thank you.

Will check and come back again.

Best regards
Roger

rogbeta
 
Posts: 4
Joined: Thu May 20, 2021 10:46 am

Re: Adafruit SeeSaw I2C Communication with I2C Handle for ST

by rogbeta on Wed Jun 02, 2021 2:26 pm

Hello Mike

Just contacted them, but they said, still having the same problem as I explained.

They could not solve it yet.

----
I still have a question regarding format and bitstream.

Are both values (moister and temp) 16bit int?

I still get some ghost numbers, struggling with the format.

(32int_t)
temp received1: 255 (buffer[0])
temp received2: 0 (buffer[1])
temp received3: 27 (buffer[2]l
temp received4: 166 (buffer[3])

With arduino environment it worked well.
Somehow there is a different I2C handling on the stm32.

Does someone have some experience with adafruit products on stm32 uCs?

Regards
Roger

rogbeta
 
Posts: 4
Joined: Thu May 20, 2021 10:46 am

Re: Adafruit SeeSaw I2C Communication with I2C Handle for ST

by mikeysklar on Wed Jun 02, 2021 5:04 pm

Reading the code for getTemp in the Arduino SeeSaw library it looks like it is 32bit float for temperature only (no moisture in there).

Code: Select all | TOGGLE FULL SIZE
/**
 *****************************************************************************************
 *  @brief      Read the temperature of the seesaw board in degrees Celsius.
 *NOTE: not all seesaw firmwares have the temperature sensor enabled.
 *  @return     Temperature in degrees Celsius as a floating point value.
 ****************************************************************************************/
float Adafruit_seesaw::getTemp() {
  uint8_t buf[4];
  this->read(SEESAW_STATUS_BASE, SEESAW_STATUS_TEMP, buf, 4, 1000);
  int32_t ret = ((uint32_t)buf[0] << 24) | ((uint32_t)buf[1] << 16) |
                ((uint32_t)buf[2] << 8) | (uint32_t)buf[3];
  return (1.0 / (1UL << 16)) * ret;
}


https://github.com/adafruit/Adafruit_Se ... seesaw.cpp

The capacitive reading from the soil sensor should be off the captouch pin in the same file, but that will be a 16-bit unsigned integer holding a 10-bit return value (0-1023).

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;

  for (uint8_t retry = 0; retry < 5; retry++) {
    if (this->read(SEESAW_TOUCH_BASE, SEESAW_TOUCH_CHANNEL_OFFSET + p, buf, 2,
                   3000 + retry * 1000)) {
      ret = ((uint16_t)buf[0] << 8) | buf[1];
      break;
    }
  }
  return ret;
}

mikeysklar
 
Posts: 4920
Joined: Mon Aug 01, 2016 8:10 pm

Re: Adafruit SeeSaw I2C Communication with I2C Handle for ST

by rogbeta on Mon Jun 07, 2021 9:15 am

Hello Mike

We checked the format issue, but we still have some weird temperature numbers.

Regarding the TouchRead(), what number do I have to send for the PIN? we tried 0 as it shows in the Arduino example.

"There is also two I2C address jumpers. The default address is 0x36, but you can select between 0x36 and 0x39 inclusive by shorting AD0 (to add 1 to the address) and/or AD1 (to add 2 to the address)"

I do not change the hardware, so I can expect device address 0x36, right?

Best regards
Roger

rogbeta
 
Posts: 4
Joined: Thu May 20, 2021 10:46 am

Re: Adafruit SeeSaw I2C Communication with I2C Handle for ST

by mikeysklar on Mon Jun 07, 2021 5:07 pm

Roger,

Your SeeSaw should be on the default i2c address of 0x36. If you are not 100% sure it would be a good idea to run a simple i2c scanner. Maybe like this demo:

https://deepbluembedded.com/stm32-i2c-s ... e-example/

In terms of touchRead() I think the only important argument to pass is the pin number you are reading from which is pin0 on the SeeSaw.

* @param pin the number of the pin to read.

mikeysklar
 
Posts: 4920
Joined: Mon Aug 01, 2016 8:10 pm

Please be positive and constructive with your questions and comments.