drohm / pi-sht1x

Python library for the Sensirion SHT1x series of temperature and humidity sensors to work on the Raspberry Pi. This includes the SHT10, SHT11, and SHT15 sensors.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

SHT1x failed to properly receive command

XPilot opened this issue · comments

Hello,

I have a SHT11 breakout sensor and I have tried everywhich way to connect to it with little success. The error I am getting:

Traceback (most recent call last):
  File "examples/sensor.py", line 45, in <module>
    main()
  File "examples/sensor.py", line 37, in main
    temp = sensor.read_temperature()
  File "/usr/local/lib/python3.4/dist-packages/pi_sht1x/sht1x.py", line 166, in read_temperature
    self._send_command()
  File "/usr/local/lib/python3.4/dist-packages/pi_sht1x/sht1x.py", line 254, in _send_command
    self._get_ack(command_name)
  File "/usr/local/lib/python3.4/dist-packages/pi_sht1x/sht1x.py", line 397, in _get_ack
    raise SHT1xError(message)
pi_sht1x.sht1x.SHT1xError: SHT1x failed to properly receive command [['Temperature'] - 00000011]

As a short summary:

  1. I wired the DATA pin (purple wire) to a 10k pullup resistor to 3.3v and to the physical pin no. 18 on my pi
  2. I wired clock pin (gray wire) to physical pin 23.

I have attached an image with the pi wiring below.

  • Raspberry wiring
    20160125_234154
  • Breadboard wiring (sorry about the mess)
    20160125_234541

I can see that I receive a voltage on pin 18 (I use wiringPi for it) but on the clock pin it's still set for in.
Can you please provide some info on what I am doing wrong?

 +-----+-----+---------+------+---+--B Plus--+---+------+---------+-----+-----+
 | BCM | wPi |   Name  | Mode | V | Physical | V | Mode | Name    | wPi | BCM |
 +-----+-----+---------+------+---+----++----+---+------+---------+-----+-----+
 |     |     |    3.3v |      |   |  1 || 2  |   |      | 5v      |     |     |
 |   2 |   8 |   SDA.1 |   IN | 1 |  3 || 4  |   |      | 5V      |     |     |
 |   3 |   9 |   SCL.1 |   IN | 1 |  5 || 6  |   |      | 0v      |     |     |
 |   4 |   7 | GPIO. 7 |   IN | 1 |  7 || 8  | 1 | ALT0 | TxD     | 15  | 14  |
 |     |     |      0v |      |   |  9 || 10 | 1 | ALT0 | RxD     | 16  | 15  |
 |  17 |   0 | GPIO. 0 |   IN | 0 | 11 || 12 | 0 | IN   | GPIO. 1 | 1   | 18  |
 |  27 |   2 | GPIO. 2 |   IN | 0 | 13 || 14 |   |      | 0v      |     |     |
 |  22 |   3 | GPIO. 3 |   IN | 0 | 15 || 16 | 0 | IN   | GPIO. 4 | 4   | 23  |
 |     |     |    3.3v |      |   | 17 || 18 | 1 | IN   | GPIO. 5 | 5   | 24  |  <---- voltage present on pin 18
 |  10 |  12 |    MOSI |   IN | 0 | 19 || 20 |   |      | 0v      |     |     |
 |   9 |  13 |    MISO |   IN | 0 | 21 || 22 | 0 | IN   | GPIO. 6 | 6   | 25  |
 |  11 |  14 |    SCLK |   IN | 0 | 23 || 24 | 1 | IN   | CE0     | 10  | 8   |   <---- clock should be out I guess
 |     |     |      0v |      |   | 25 || 26 | 1 | IN   | CE1     | 11  | 7   |
 |   0 |  30 |   SDA.0 |   IN | 1 | 27 || 28 | 1 | IN   | SCL.0   | 31  | 1   |
 |   5 |  21 | GPIO.21 |   IN | 1 | 29 || 30 |   |      | 0v      |     |     |
 |   6 |  22 | GPIO.22 |   IN | 1 | 31 || 32 | 0 | IN   | GPIO.26 | 26  | 12  |
 |  13 |  23 | GPIO.23 |   IN | 0 | 33 || 34 |   |      | 0v      |     |     |
 |  19 |  24 | GPIO.24 |   IN | 0 | 35 || 36 | 0 | IN   | GPIO.27 | 27  | 16  |
 |  26 |  25 | GPIO.25 |   IN | 0 | 37 || 38 | 0 | IN   | GPIO.28 | 28  | 20  |
 |     |     |      0v |      |   | 39 || 40 | 0 | IN   | GPIO.29 | 29  | 21  |
 +-----+-----+---------+------+---+----++----+---+------+---------+-----+-----+
 | BCM | wPi |   Name  | Mode | V | Physical | V | Mode | Name    | wPi | BCM |
 +-----+-----+---------+------+---+--B Plus--+---+------+---------+-----+-----+

Please tell me what am I doing wrong.

Thank you.

Hi @XPilot, I'll take a look tonight.

@XPilot Can you tell me which breakout board you're using for the SHT11?

I'm using this one (no name apparently):

http://www.robofun.ro/breadboard-82x52x10?search=breadboard

Not the breadboard, the SHT11 breakout, who makes it? Do you have a link to where you bought it? I'd like to read the specs on it to make sure your wiring is correct, etc.

Also, check to see if the SHT11 breakout you're using includes the 10K pull-up resistor. The SHT15 that I'm using (https://learn.sparkfun.com/tutorials/sht15-humidity-and-temperature-sensor-hookup-guide) already includes it. Yours might also, but check to make sure.

I just wired up my SHT15 to my pi and didn't have any issues running the examples.py script. Image of the wiring below:

sht15-wiring

Output from running the examples.py script:

drohm@SCIFPI03 ~/dev/pi-sht1x/examples $ sudo python3 examples.py 
[sudo] password for drohm: 
Test: using default values: 3.5V, High resolution, no heater, otp_no_reload off, CRC checking enabled...
/usr/local/lib/python3.2/dist-packages/pi_sht1x/sht1x.py:535: RuntimeWarning: This channel is already in use, continuing anyway.  Use GPIO.setwarnings(False) to disable warnings.
  GPIO.setup(self.data_pin, GPIO.OUT)
Temperature: 23.24*C [73.79*F]
Relative Humidity: 25.31%
Dew Point: 2.09*C

Temperature: 23.22*C [73.76*F]
Relative Humidity: 25.14%
Dew Point: 1.99*C

Temperature: 23.21*C [73.74*F]
Relative Humidity: 25.07%
Dew Point: 1.95*C

Temperature: 23.19*C [73.7*F]
Relative Humidity: 25.07%
Dew Point: 1.93*C

Temperature: 23.17*C [73.67*F]
Relative Humidity: 25.1%
Dew Point: 1.93*C

Test complete.

Test: reading all measurements using GPIO.BCM mode, 3V, High resolution, heater off, otp_no_reload off, and CRC check on.
Temperature: 23.21*C [73.74*F]
Relative Humidity: 25.21%
Dew Point: 2.02*C

Temperature: 24.5*C [76.06*F]
Relative Humidity: 35.55%
Dew Point: 7.41*C

Temperature: 25.81*C [78.42*F]
Relative Humidity: 49.84%
Dew Point: 12.73*C

Temperature: 26.53*C [79.71*F]
Relative Humidity: 59.02%
Dew Point: 15.44*C

Temperature: 26.97*C [80.51*F]
Relative Humidity: 65.0%
Dew Point: 17.0*C

Test complete.

Test: read humidity without providing the temperature as an argument...
Temperature: 26.8*C [80.2*F]
Humidity: 65.28
Temperature: 26.8*C [80.2*F]
Humidity: 52.77
Temperature: 26.8*C [80.2*F]
Humidity: 42.52
Temperature: 26.8*C [80.2*F]
Humidity: 35.57
Temperature: 26.8*C [80.2*F]
Humidity: 31.43
Test complete.

Test: calculate dew point without providing temperature and humidity as arguments...
Temperature: 24.68*C [76.38*F]
Relative Humidity: 28.51%
Dew Point: 4.72*C

Temperature: 24.68*C [76.38*F]
Relative Humidity: 28.51%
Dew Point: 4.72*C

Temperature: 24.68*C [76.38*F]
Relative Humidity: 28.51%
Dew Point: 4.72*C

Temperature: 24.68*C [76.38*F]
Relative Humidity: 28.51%
Dew Point: 4.72*C

Temperature: 24.68*C [76.38*F]
Relative Humidity: 28.51%
Dew Point: 4.72*C

Test complete.

Test: turn otp_no_reload on...
Temperature: 24.23*C [75.57*F]
Relative Humidity: 26.3%
Dew Point: 3.34*C

Temperature: 24.16*C [75.45*F]
Relative Humidity: 28.68%
Dew Point: 4.4*C

Temperature: 24.09*C [75.32*F]
Relative Humidity: 27.31%
Dew Point: 3.72*C

Temperature: 24.03*C [75.21*F]
Relative Humidity: 26.46%
Dew Point: 3.27*C

Temperature: 24.0*C [75.16*F]
Relative Humidity: 25.95%
Dew Point: 3.0*C

Test complete.

Test: use low resolution...
Temperature: 23.94*C [75.05*F]
Relative Humidity: 25.67%
Dew Point: 2.81*C

Temperature: 23.9*C [74.98*F]
Relative Humidity: 25.12%
Dew Point: 2.5*C

Temperature: 23.86*C [74.91*F]
Relative Humidity: 25.12%
Dew Point: 2.47*C

Temperature: 23.82*C [74.84*F]
Relative Humidity: 25.11%
Dew Point: 2.44*C

Temperature: 23.78*C [74.76*F]
Relative Humidity: 25.11%
Dew Point: 2.41*C

Test complete.

Test: change resolution after object creation...
High resolution...
Temperature: 23.79*C [74.78*F]
Relative Humidity: 24.94%
Dew Point: 2.33*C

Temperature: 23.77*C [74.75*F]
Relative Humidity: 24.9%
Dew Point: 2.29*C

Temperature: 23.72*C [74.66*F]
Relative Humidity: 24.9%
Dew Point: 2.25*C

Temperature: 23.71*C [74.64*F]
Relative Humidity: 24.9%
Dew Point: 2.24*C

Temperature: 23.68*C [74.58*F]
Relative Humidity: 24.86%
Dew Point: 2.2*C

Complete.

Low resolution...
Temperature: 23.62*C [74.48*F]
Relative Humidity: 25.1%
Dew Point: 2.28*C

Temperature: 23.62*C [74.48*F]
Relative Humidity: 25.1%
Dew Point: 2.28*C

Temperature: 23.58*C [74.4*F]
Relative Humidity: 25.1%
Dew Point: 2.25*C

Temperature: 23.58*C [74.4*F]
Relative Humidity: 25.1%
Dew Point: 2.25*C

Temperature: 23.54*C [74.33*F]
Relative Humidity: 25.09%
Dew Point: 2.21*C

Test complete.

Test: Read the Status Register (default)...
Status Register: 00000000
Test complete.

Test: Read the Status Register (low resolution, otp_no_reload on)...
Status Register: 00000011
Test complete.

Test: resetting the connection to the sensor...
Temperature: 23.54*C [74.33*F]
Test complete.

Test: performing a soft reset of the sensor...
Status Register: 00000000
Temperature: 23.56*C [74.37*F]
Test complete.

Test: resetting the status register...
Status Register: 00000000
Temperature: 23.56*C [74.37*F]
Test complete.

Test: CRC disabled...
Temperature: 23.57*C [74.39*F]
Relative Humidity: 24.69%
Dew Point: 2.03*C

Temperature: 23.54*C [74.33*F]
Relative Humidity: 24.62%
Dew Point: 1.97*C

Temperature: 23.5*C [74.26*F]
Relative Humidity: 24.61%
Dew Point: 1.93*C

Temperature: 23.48*C [74.22*F]
Relative Humidity: 24.68%
Dew Point: 1.95*C

Temperature: 23.48*C [74.22*F]
Relative Humidity: 24.68%
Dew Point: 1.95*C

Test complete.

Thank you for your answer and I appologise I misread breakout with breadboard. This is the sensor I am using:

http://www.robofun.ro/senzor-temperatura-umiditate-sht11?search=sht

Could you try to find out if that breakout has a pull-up or pull-down resistor built in? I don't have a SHT11 sensor to test this on, but I'll try to get one and see if I run into the same issue. Have you tried removing the pull-up resistor?

Thank you for your help. I got it working 👍

It turns out it was a wiring problem. Thank you for the photos.

Awesome, glad you got it working!

I have the same problem .. can you tell me what was the wiring problem?

In case anyone wanders here with the same problem:
all tutorials say that you have to connect data to GPIO 24 (Pin 18). In my case you actually had to connect data to GPIO 18 (Pin 12). After that change everything is working smoothly

@AndrzejRyl All the tutorials and docs mention the GPIO mode used, which is GPIO.BCM. So when it says pin 18, it means GPIO 18. None of the docs or tutorials mention GPIO 24.

Also, the library allows you to choose between the two different modes (GPIO.BOARD or GPIO.BCM) so you can use whatever you like best.