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
drivers/dht: initial import #2990
Conversation
There are some cleanup activities left.. Will tend to this PR again tomorrow. Anyway: |
5608489
to
c109b18
Compare
/* read 1, set bit */ | ||
les_bits |= 0x0000000000000001; | ||
/* wait for low */ | ||
while (gpio_read(dev)) ; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this line is a leftover of the previous approach with using sleep.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
right!
Can't test anymore, my sensor died. |
@LudwigOrtmann
Did it die because of this PR? 😜 |
@gebart Due to the cause chain: definitely ;) |
RIP |
Tested patches with an intact DHT22, worked as expected. |
|
||
void dht_parse_22(dht_data_t *data, float *outhum, float *outtemp) | ||
{ | ||
*outhum = data->humidity / 10; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I didn't find this in the datasheet immediately but I guess this has to do with the higher resoultion of the dht22?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yes, also it's what the datasheets say the conversion is
@LudwigOrtmann the driver looks good to me besides some minor comments. I don't have the hardware to test it. I never "researched" on it but I thought about a common 1-wire interface for the future. After implementing this rudimentary protocol, do you think it makes sense so create a common 1-wire API? |
@PeterKietzmann I don't think the DHT22 is really 1-wire (I'm assuming you were referring to the 1-wire brand name by Maxim Integrated). From the data sheet the DHT22 seems similar but the length of each bit depends on if it is a zero or a one, which it does not in the (Maxim) 1-wire protocol. |
I superficially looked into this as well and can confirm that the DHT family is not speaking "1-wire". While it has some similarities, I wouldn't base a unified communication module on it. |
Thanks for your answers. Well, if it is proprietary, I agree there is no reason for an interface... |
Does anyone have the hardware to test this driver? |
* @param[out] hum pointer to variable humidity is stored to | ||
* @param[out] temp pointer to variable temperature is stored to | ||
*/ | ||
void dht_parse(dht_t *dev, dht_data_t *data, float *hum, float *temp); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same as in #2980: I would prefer to have three functions here:
void dht_read_raw(); // return raw values
void dht_read(dev, int32_t *tmp, int16_t? *hum); // return milidegree C and mg/m^3
void dht_read(dev, float *tmp, float *hum); // return degree and g/m^3
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
void dht_read_raw(); // return raw values
As a side-effect?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hm, probably not .. anyways - I think the parse function allows for higher flexibility regarding reading and transforming of the values. I can add convenience functions that call both in one go if you insist.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yes, I do. In the end, in 99% of the cases, users are not interested in the raw value, but in the actual physical ones. So forcing them to call parse
after any reading reduces IMHO the usability of the driver...
Could you elaborate on how an explicit parse
function increases the flexibility?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You can read values at one and convert them at a later point in time. I imagine this might be useful in a time constrained situation.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not going to implement an optimized integer reading version any time soon, knock yourself out in a follow-up PR.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looking at the timings for the sensor and the time it takes for the conversion I say the conversion time is insignificantly small... But if you will not fix it anyway, fine with me.
@haukepetersen @PeterKietzmann can I squash? |
@LudwigOrtmann the code looks good to me. Can anyone test the driver? Maybe @mehlis has a device? Let's wait with squashing until tested. |
Why do we need with squashing for a test? |
Honestly I don't really know :-) ! Fine, please squash. ACK when tests went positive |
I don't understand the question. |
ACK when suqashed and Travis happy. |
Unified driver for DHT11 and DHT22.
And go |
drivers/dht: initial import
Unified driver for DHT11 and DHT22.
Test application included.