I have managed to successfully get my Fuel gauge, 2 ToF sensors as well as an ambient sensor to work correctly on via I2C and a MUX. I have been stuck for two days now trying to get the HS300x temperature sensor to work. If anyone has nothing better to do, I would appreciate some assistance… again
I have done the best I could so far, followed the same process as I did with the LTR303ALS and VL53L4 sensors. Got some code from Github, followed a tutorial on how to open ports on a MUX and tried marrying to two. So far so good… except for this HS300x sensor. Below is all te resources I am using:
@friedl_1977, I believe the library you wanted/should be using is this one, which has the begin() class function. The one you are using is a cut-down version of it. Note that this new library automatically constructs the HS300x object so you don’t need to.
@friedl_1977, here is an updated version of your code using the new library. I don’t know what purpose of the code at lines 26 and 27 is. I had to change the D23 pin value to D2 to get it to compile but you will need to change that if some pin is used to interface with the HX300x.
Also, the void printValues(HS300xClass HS300x, int bus) function can use the globally declared HS300x object instead of a copy or reference as you have it. So use void printValues(int bus) instead.
@friedl_1977, first thing is to make sure that “bus 3” actually is selected correctly. Do you have any other sensors on the same bus? If not, you could run an I2C scanner to see if it find any device on the bus 3 and for good measure, test it on a bus with known-working devices.
0x36 and 0xb is the fuel gauge which is connected directly to I2C on the uC as I will be shutting down the MUX when not in use to preserve battery life.
Correct, it did find the HS300x on Port 3. The same scanner also found the other sensors on their respective ports, so I can only assume it is working as intended
@friedl_1977, let’s add a little debugging. Replace the “begin()” code with this. It will provide the value of the error code being returned by the library, which you can post.
char msg[40];
int ret = HS300x.begin();
if (!ret) {
snprintf(msg, sizeof(msg), "No HS300x found (%i)", ret);
Particle.publish("Could not find a valid HS300x sensor on bus 3");
while (1);
}
else {
Particle.publish("Device OK");
}
@friedl_1977, it seems the library is not getting a response from the HS300x after it wakes it up and returns a value of zero or HS300X_ERROR_SENSOR_BUSY. You could try changing line 60 in the HS300x.cpp file to: