2

I use a temperature and humidity sensor sht20. According to this link: http://www.sensirion.com/en/products/humidity-temperature/humidity-temperature-sensor-sht2x/ It is compatible with sht21, which has a linux kernel module driver in drivers/hwmon/sht21.c

For my raspberry Pi B+, I recompiled the kernel of 3.18.1+ to enable HWMON and SHT21 module. I successfully update the kernel image and modules to my Pi. And I refer to this link: http://www.raspberrypi.org/forums/viewtopic.php?f=44&t=7086

Do below (as root):

root@raspberrypi:/home/pi# i2cdetect -y 1
     0  1  2  3  4  5  6  7  8  9  a  b  c  d  e  f
00:          -- -- -- -- -- -- -- -- -- -- -- -- -- 
10: -- -- -- -- -- -- -- -- -- -- -- UU -- -- -- -- 
20: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 
30: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 
40: 40 -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 
50: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 
60: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 
70: -- -- -- -- -- -- -- --  

And then,

echo sht21 0x40 > /sys/class/i2c-adapter/i2c-1/new_device

Do again,

root@raspberrypi:/home/pi# i2cdetect -y 1
     0  1  2  3  4  5  6  7  8  9  a  b  c  d  e  f
00:          -- -- -- -- -- -- -- -- -- -- -- -- -- 
10: -- -- -- -- -- -- -- -- -- -- -- UU -- -- -- -- 
20: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 
30: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 
40: UU -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 
50: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 
60: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 
70: -- -- -- -- -- -- -- --      

I installed latest version lm_sensors by make && make install from the source code. Then I typed

root@raspberrypi:/home/pi# sensors
bcm2835_thermal-virtual-0
Adapter: Virtual device
temp1:        +36.9掳C  

sht21-i2c-1-40
Adapter: bcm2708_i2c.1
ERROR: Can't get value of subfeature temp1_input: I/O error
temp1:            N/A  

root@raspberrypi:/home/pi# sensors-detect 
...
Sorry, no sensors were detected.
...

Why?

Thanks!

3
  • 2
    What happens if you use a kernel without that driver and run i2cdetect? It should still show up, and checking that might demonstrate that it is the driver that is the problem.
    – goldilocks
    Jan 20, 2015 at 18:57
  • 1
    You do know that UU indicates "Probing was skipped, because this address is currently in use by a driver." (man i2cdetect)? But just because someone wrote a driver for it doesn't mean it works (and it appears that it does not). Do you have a datasheet and documentation for the device? If you are decent with C, you could try going through that and using the smbus API to create a userspace driver. Probably not that much code...I have a C++ example of this for a temp/pressure sensor here.
    – goldilocks
    Jan 21, 2015 at 15:12
  • 1
    Thank you for your info! (1) I find an example code in user space which can get sensor data from SHT20, emsystech.de/raspi-sht21 And it may use GPIO to act as i2c. (2) I am writing code using open/ioctl/write/read to operate /dev/i2c-1, this way may be hardware independent and easily porting to other Linux device. (3) I just want to use this chance to learn more about Linux kernel. That is why I asked over and over on difference between user space and kernel space, and try to make this kernel way work. @goldilocks
    – Tom Xue
    Jan 21, 2015 at 15:52

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Browse other questions tagged or ask your own question.