Me, Mux and HS300x

Hi -

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 :innocent:

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:

  • Github code
  • MUX tutorial (from about half way down where the guy uses 4 sensors, not the 4 screen section)
  • My attempt (I have not changed all the serial prints etc. to publishes yet, first goal is to get the sensor to initialise and measure)

When compiling I get the following error.

As mentioned before, I am not a programmer, so please excuse any trivial mistakes.

Many thanks,
Friedl.

@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.

4 Likes

Hi @peekay123 -

Thanks. I have tried so many can’t recall which ones I have not tried, hehe. Let me try this one again, I will let you know the outcome :slight_smile:

The help is greatly appreciated!!

:pray:t3:

@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.

2 Likes

Hi @peekay123 -

My apologies... D23 is pulled high to enable the MUX :slight_smile: Thank you, I will implement the code now and see :slight_smile:

@friedl_1977, are you targeting a Xenon?

Hi -

No, although I have a bunch in my drawer :grin: Using B524

Hi @peekay123 -

I get the same error I did earlier with one of my million attempts, please see below:

Whenever I got the code to compile, I was presente with this error. I checked 5 different boards to eliminate possible reflow issues.

Regards,
Friedl

@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.

Hi @peekay123 -

I assume it is because it is the same code I used for both ToF and Ambient sensors. the are on busses 0,1 and 2 respectively.

I have an I2C scanner app that I use. It supposedly opens each port and scans. It does pick up the temp sensor on port 3, see below.

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.

Regards,
Friedl.

Ok, so if I understand, the scanner DID find the HS300x on port 3? If that is the case, then it means we need to look to the library next.

1 Like

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 :slight_smile:

I am starting to regret implementing the mux :smiling_face:

Regards,
Friedl

@friedl_1977, I’m validating the library against the HS300x datasheet. I’ll let you know what I find, if anything.

1 Like

Hi @peekay123 -

Thank you for all the effort, I am at a loss here. not that it take much when it comes to firmware :sweat_smile:

Regards, Friedl

@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");
    }

Hi -

Ok, let me try this. I will report back :slight_smile:

Regards,
Friedl

1 Like

Hi Peekay -

Please see below:

Regards, Friedl

@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:

 _wire->requestFrom(WireTransmission(HS300X_ADR).quantity(4).timeout(100ms));

Hi -

Ok, on it. I will change it now and let you know.

Thanks, Friedl.

1 Like

Hi Peekay -

unfortunately the result is the same. Error (0)

Regards,