STHS34PF80 (Non qwiic) I2C Trouble

Having some trouble getting the STHS34PF80 sensor working and looking for advice. Closest I could find was someone in Sept of last year with my same troubles, but in that issue was a misunderstanding of pin setup. Note that I don’t have a qwiic cable, so I’m directly going to the pins and Im using an Arduino Nano 33 (though I also tried it on an Arduino MKR 1000 with the same results).

I’ve wired up GND, 3.3, SCL and SDA (triple checked I’m on the right pins for SCL and SDA on each board), get the on board LED to turn on but I cannot read data using the example sketch, Example1_BasicReadings.ino. Always the call to STHS34PF80_I2C::begin returns false. I’'ve also read that there are issues using this board in SPI mode so I’m assuming this is not an option for me. (there was an open issue on the github project for the library noting this ).

One thing I’d note is that the example sketch didn’t compile for me. It seems like the I2C library I have is different than the example uses. It seems/appears the call to Wire::begin in the example library returns a boolean value but the prototype for the function in my local library does not return anything. Im not too familiar w/ the I2C library as well so Im not sure if there is a way to check to see if initialization is successful, but I’m just assuming it succeeds and moving forward. I’ll say though if I iterate the I2C bus I can see some devices there; on the Nano 33 I can see 3 (or it appears there are 3) and on the MKR 10000 I see 1.

I only have 4 things wired up as I noted earlier, INT and CS are not connected to anything but I don’t think they need to be, I believe those are for SPI mode. I can’t tell for certain though if the documentation for not running with qwiic cables is actually complete, but I’ll say nothing mentions connecting those pins anywhere using I2C and direct wiring (non qwiic).

Any help or pointers would be greatly appreciated.
rms.

Standard checklist:
Going to pins D18 (SDA) & D19 (SCL)

Your using a module with pull up resistors:

Your accessing the correct address:
I2C Address (7-bit): 0x5A (Default)

You have tried lowering the clock speed:
Wire.begin();
Wire.setClock(50000); // Half standard frequency
Wire.setWireTimeout(3000 , true); // Enable Timeout for lockups

You have tried the basic examples from the library:

Share a photo of your setup/wiring
Are you using this library? Arduino - SparkFun Optical Tracking Odometry Sensor - PAA5160E1 (Qwiic) Hookup Guide

Thanks very much for the input here. But to clarify, what Im saying is it appears the I2c Library I am using locally is not what was used to build that library, the STHS34PF80 library, and that suggestion makes me even more sure of this. Initially I thought this because the examples included in that Sparkfun library don’t compile for me. As I noted earlier here –

It seems/appears the call to Wire::begin in the example library returns a boolean value but the prototype for the function in my local library does not return anything.

Im more sure of this because there is no function, Wire::setWireTimeout, in the library I have available to me locally.

The changes applied don’t change the result I get. Does this (seemingly) difference in Wire/I2C libraries have something to do with it I wonder? I have not done any Arudino (or any microcontroller) development in a very long time and am not too sure of troubleshooting these Nano’s (though also I see the same problem on MKR 1000).

When I iterate through addreses on I2C bus, I see something at the following addresses:

  • 0x60
  • 0x6A
  • 0x7E

I am iterating over them as such –

  Serial.begin(115200);
  while (!Serial) {
    delay(100);
  }

  Wire.begin();
  Wire.setClock(50000); // Half standard frequency
  // Wire.setWireTimeout(3000 , true); // Enable Timeout for lockups


  Serial.println("started I2C");

  delay(1000);

  // Establish communication with device
  if (mySensor.begin() == false) {
    Serial.println("Error setting up STHS34PF80_I2C");
    Serial.print("Scanning I2C bus");
    for (int i = 1; i < 127; i++) {
      Wire.beginTransmission((byte)i);
      byte error = Wire.endTransmission();
      if (error == 0) {
        Serial.print("0x");
        if (i < 16)
          Serial.print("0");
        Serial.print(i, HEX);
      } else if (error == 4) {
        Serial.print("?");
      } else {
        Serial.print(".");
      }
    }
    while (1);
  }

The output I get:

16:54:15.296 -> Error setting up STHS34PF80_I2C
16:54:15.296 -> Scanning I2C bus...............................................................................................0x60.........0x6A...................0x7E

Im attaching the way I’ve wired up the device if helpful.



I apologize, I pasted the wrong link above - Installation and Setup - Hookup Guide - SparkFun Human Presence and Motion Sensor - STHS34PF80

What other devices are on the bus? (3 are appearing)

It does look like you are using an older Wire Library.
ArduinoCore-avr/libraries/Wire at master · arduino/ArduinoCore-avr · GitHub

Timeout was implemented in 2020.
library.properties shows V1.0

Looking at my wire libraries, I seem to have V1.0

locate Wire.h
/home/user/.arduino15/packages/arduino/hardware/avr/1.8.6/libraries/Wire/src/Wire.h
/usr/share/arduino/hardware/arduino/avr/libraries/Wire/src/Wire.h

I have both Arduino IDE V2.3.4 and V1.8.19 installed.

You are getting x3 I2C devices when you only have the one STHS34PF80 connected?
Perhaps the STHS34PF80 is faulty and borking it’s address.
Possibly your local wire library is using 8 or 10 bit addressing or something?
I’m guessing you have tried using those addresses to talk to the STHS34PF80?

How long are those wires going from the nano to the STHS34PF80?

Thanks again for the input here.

Details on my setup –

MacOS: Sonoma 14.3 (23D56)
Arduino: Version: 2.3.4
Wire: 1.8.14 (though I did find something strange here)
❯ find ./ -print | grep Wire\.h .//packages/arduino/hardware/avr/1.8.6/libraries/Wire/src/Wire.h .//packages/arduino/hardware/mbed_nano/4.2.1/libraries/Wire/Wire.h .//packages/arduino/hardware/samd/1.8.14/libraries/Wire/Wire.h
Seems like there are multiple versions on my computer. Can I remove some of these? What is the name of the Library that I would search for in the Arduino IDE?

What other devices are on the bus? (3 are appearing)

You are getting x3 I2C devices when you only have the one STHS34PF80 connected?

Im unsure of what this is, I’l say there is nothing else connected to the whole controller. This is the only thing connected (SCL+SDA+GND+3.3). I had just assumed that the other 2 were some internal stuff, maybe even those I2C pins showed up during that inspection. Though I’ll also note that I only see 1 address on the I2C bus when I use MKR1000 with this same STHS34PF80 sensor. This is what led me to think it’s probably some internal Nano stuff.

Perhaps the STHS34PF80 is faulty and borking it’s address.
Possibly your local wire library is using 8 or 10 bit addressing or something?
I’m guessing you have tried using those addresses to talk to the STHS34PF80?

Definitely it could be the device, I soldered the header pins on the wrong side twice and had to desolder them and reattach. Regarding the talking to those addresses, Im unsure how to do that. Would you happen to be able to share some psuedo code or a snipper that would illustrate what you are suggesting? Beyond the beginTransmission / endTransmission functions I’ve used.

How long are those wires going from the nano to the STHS34PF80?

They are very short, maybe 6inches from sensor to nano.

Thanks to both you guys again, the help is here is very much appreciated.

The NANO33 IOT has onboard sensors on I2C:

  • The LSM6DSRTR 3D Gyroscope has address 0x6A
  • The ECC608 crypto has address 0x60
  • Then there is the WM102 (maybe also interfering so maybe the 0x7E)

Try to do an I2C scan WITHOUT the STH34PF80. See what you get.

I am actually missing the 0x5A which is the default for the STH34PF80 according to the Sparkfun information mentioned earlier

1 Like

This was good idea. I did this on both Nano and MKR1000, same I2C addresses appear to be there when STH34PF80 has no connection to board. This leads me to believe the STH34PF80 may be bad / not working.

Too bad… but it happens. Looks like it as the 0x5A should show up. Try to get a replacement.

Looking at the STHS34PF80 library
SparkFun_STHS34PF80_Arduino_Library/src/SparkFun_STHS34PF80_Arduino_Library.cpp at main · sparkfun/SparkFun_STHS34PF80_Arduino_Library · GitHub

bool STHS34PF80_I2C::begin(uint8_t devAddr, TwoWire& wirePort)
{
_i2cBus.init(wirePort, false);
sensor.read_reg = STHS34PF80_I2C::read;
sensor.write_reg = STHS34PF80_I2C::write;
sensor.mdelay = STHS34PF80_I2C::delayMS;
sensor.handle = this;
deviceAddress = devAddr;

// call super class begin -- it returns 0 on no error
return STHS34PF80::begin() == 0;

}

So the first value (an unsigned byte - uint8_t) is the address.

void setup()
{
Serial.begin(115200);
Serial.println(“STHS34PF80 Example 1: Basic Readings”);

// Begin I2C
Wire.begin()

// Establish communication with device 
if(mySensor.begin(0x5A) == false)
{
  Serial.println("Error setting up device - please check wiring.");
  while(1);
}

delay(1000);

}

Though it does look like your STHS34PF80 is faulty from your previous post.
So putting the address in probably wont make a difference.

Was it purchased from us? If so head over to Returns (contact vendor if purchased elsewhere) and we’ll get ya squared away

It was indeed. Thanks for the pointer, Russell. I’ll do that. Appreciate everyone’s help/input, thank you.

1 Like