Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Renesas HS300x Sensor Support #63016

Merged
merged 2 commits into from Nov 17, 2023

Conversation

iandmorris
Copy link
Contributor

Added driver and sample application for the Renesas HS3001 and HS3003 temperature/humidity sensors.

Tested using a Nucleo-F401RE, Click shield for Nucleo-64 and Temp&Hum Click 18 (HS3003) and Temp& Hum Click 17 (HS3001). The only difference between the HS3001 and HS3003 is the accuracy of the relative humidity measurements.

drivers/sensor/hs300x/hs300x.c Outdated Show resolved Hide resolved
drivers/sensor/hs300x/hs300x.c Show resolved Hide resolved
return -ENOTSUP;
}

rc = hs300x_start_measurement(dev);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure it's worth a dedicated function?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

samples/sensor/hs300x/README.rst Outdated Show resolved Hide resolved
@iandmorris
Copy link
Contributor Author

I messed up when rebasing this branch with the main branch (very new to the Zephyr Git workflow) and can't seem to recover. I'm going to close this pull request, go away and learn/practice the work flow and then create a new PR that also addresses the comments made. The time you spent reviewing was not a waste, I'll be sure to incorporate the comments.

@kartben
Copy link
Collaborator

kartben commented Sep 28, 2023

I messed up when rebasing this branch with the main branch (very new to the Zephyr Git workflow) and can't seem to recover. I'm going to close this pull request, go away and learn/practice the work flow and then create a new PR that also addresses the comments made. The time you spent reviewing was not a waste, I'll be sure to incorporate the comments.

git rebase origin/main --interactive and then just delete that commit that's not yours?

@iandmorris
Copy link
Contributor Author

I messed up when rebasing this branch with the main branch (very new to the Zephyr Git workflow) and can't seem to recover. I'm going to close this pull request, go away and learn/practice the work flow and then create a new PR that also addresses the comments made. The time you spent reviewing was not a waste, I'll be sure to incorporate the comments.

git rebase origin/main --interactive and then just delete that commit that's not yours?

Thanks for the suggestion, however I have compounded the problem while trying to fix it (new to using git rebase). Quicker if i just create a new branch and PR (once I have added the features requested in the comments).

@kartben
Copy link
Collaborator

kartben commented Sep 29, 2023

I see. FWIW you should also be able to do a hard reset to any of your previous commits, which SHAs still show up on this PR or which you could also find via git reflog. Just thought it might be worthwhile for you to explore a bit more as there is almost always a solution that doesn't involve reopening a PR :)

@iandmorris
Copy link
Contributor Author

I see. FWIW you should also be able to do a hard reset to any of your previous commits, which SHAs still show up on this PR or which you could also find via git reflog. Just thought it might be worthwhile for you to explore a bit more as there is almost always a solution that doesn't involve reopening a PR :)

Thanks for the tip about git reflog (and for your encouragement). I think I have resolved the issues I created...

{
const struct hs300x_config *cfg = dev->config;

if (!device_is_ready(cfg->bus.bus)) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
if (!device_is_ready(cfg->bus.bus)) {
if (!i2c_is_ready_dt(cfg->bus)) {

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

Comment on lines 12 to 19
struct hs300x_config {
struct i2c_dt_spec bus;
};

struct hs300x_data {
int16_t t_sample;
uint16_t rh_sample;
};
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not enough here to justify having a separate private include file. Please move into hs300x.c

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

Comment on lines 775 to 802
test_i2c_hs300x: hs300x@44 {
compatible = "renesas,hs300x";
reg = <0x44>;
};
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Address should be incremented by one from the last one. Note this is just a build test that will not execute on hardware so the address doesn't need to match the sensor datasheet

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thanks, hadn't realized the address should be incremented.

@@ -0,0 +1,65 @@
.. _hs300x_sample:

HS300X Sample
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We want to stop introducing new driver-specific sensor samples, and instead use more generic ones for each sensor type. See samples/sensor/accel_polling and samples/sensor/magn_polling for example

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

makes sense. do you want me to create a generic sample for temperature and humidity sensors, based on one of these samples? something like samples/sensor/temp_hum_polling perhaps?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That would be great, thank you

Copy link
Collaborator

@kartben kartben Oct 25, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe simply repurpose/rename the dht sample?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok, I will look at creating a generic temperature/humidity sample based on the existing dhtsample.

@zephyrbot zephyrbot added the area: Samples Samples label Oct 24, 2023
@iandmorris iandmorris force-pushed the renesas_hs300x_sensor branch 2 times, most recently from 25f1fc3 to 5634408 Compare October 24, 2023 22:03
Copy link
Member

@MaureenHelm MaureenHelm left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Needs a rebase

@@ -0,0 +1,65 @@
.. _hs300x_sample:

HS300X Sample
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That would be great, thank you

MaureenHelm
MaureenHelm previously approved these changes Oct 30, 2023
@MaureenHelm
Copy link
Member

@kartben please revisit

break;
}

printk("%16s: temp is %d.%d oC humidity is %d.%d %%RH\n", dev->name,
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
printk("%16s: temp is %d.%d oC humidity is %d.%d %%RH\n", dev->name,
printk("%16s: temp is %d.%d °C humidity is %d.%d %%RH\n", dev->name,

Also, maybe the format should be %d.%02d, having so many digits feels odd.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I changed oC to °C, however when I tried the %d.%02d modification I found it did not do what I thought it would... After some reading it seems that (unless I have missed something) the width format specifier defines the minimum number of characters to be printed but it does not truncate the value if it is larger. Therefore there was no change in the output (in most cases) and so I left formatting as it was...

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah! of course... my bad. So also need to divide val2 by 10000, right?

printk("T: %d.%02d\n", temp.val1, temp.val2 / 10000);

Comment on lines 39 to 49
hs300x@44: temp is 25.31129 oC humidity is 30.391259 %RH
hs300x@44: temp is 25.51272 oC humidity is 30.446194 %RH
hs300x@44: temp is 25.51272 oC humidity is 30.372947 %RH
hs300x@44: temp is 25.51272 oC humidity is 30.391259 %RH
hs300x@44: temp is 25.31129 oC humidity is 30.372947 %RH
hs300x@44: temp is 25.31129 oC humidity is 30.354635 %RH
hs300x@44: temp is 25.51272 oC humidity is 30.372947 %RH
hs300x@44: temp is 25.51272 oC humidity is 30.372947 %RH
hs300x@44: temp is 25.51272 oC humidity is 30.391259 %RH
hs300x@44: temp is 25.51272 oC humidity is 30.446194 %RH
hs300x@44: temp is 25.51272 oC humidity is 30.531648 %RH
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

update to use "°" and possibly the newer format as per my other comment.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done, but see comment above.

harness_config:
type: one_line
regex:
- "[0-9A-Za-z_,+-.]*@[0-9A-Fa-f]*: temp is (.*) oC humidity is (.*) %RH"
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ditto

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

drivers/sensor/hs300x/hs300x.c Show resolved Hide resolved
Copy link
Collaborator

@kartben kartben left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry for the delay! The new generic sample is great, thanks for this!
A few remaining comments that are hopefully not too nitpicky :)

MaureenHelm
MaureenHelm previously approved these changes Nov 10, 2023
kartben
kartben previously approved these changes Nov 13, 2023
Copy link
Collaborator

@kartben kartben left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks! My latest comment is not asking you for yet another update, to be clear :)

@MaureenHelm we should probably now just remove the existing /dht sample, right?

samples/sensor/dht_polling/src/main.c Show resolved Hide resolved
MaureenHelm
MaureenHelm previously approved these changes Nov 13, 2023
Copy link
Member

@MaureenHelm MaureenHelm left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we should probably now just remove the existing /dht sample, right?

Yes, but it would be nice to port boards/nrf52dk_nrf52832.overlay in the process

@kartben
Copy link
Collaborator

kartben commented Nov 13, 2023

we should probably now just remove the existing /dht sample, right?

Yes, but it would be nice to port boards/nrf52dk_nrf52832.overlay in the process

Ya although tbh I am not a big fan of overlay files that imply manual wiring and breadboarding, especially if the README does not really provide guidance for beginners re: wiring for beginners (as this is virtually the only audience for which such overlay could really be useful IMO). OTH the overlay still kind of make sense in this particular example of the DHT22/11, I guess, as it showcases the use of the dht22 binding property.

In any case, the deletion of the legacy dht sample is for another PR to address which I'll likely look into at some point :)

@carlescufi
Copy link
Member

@iandmorris please rebase to solve the conflict.

Adds support for Renesas HS3001 and HS3003 temperature/humidity sensors
connected via an I2C bus.

Signed-off-by: Ian Morris <ian.d.morris@outlook.com>
This simple application periodically prints the temperature and humidity
measured by one or more digital humidity/temperature sensors.

Signed-off-by: Ian Morris <ian.d.morris@outlook.com>
@MaureenHelm MaureenHelm merged commit dfc747d into zephyrproject-rtos:main Nov 17, 2023
19 checks passed
@iandmorris iandmorris deleted the renesas_hs300x_sensor branch November 17, 2023 16:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area: Devicetree Binding PR modifies or adds a Device Tree binding area: Logging area: Samples Samples area: Sensors Sensors
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants