Skip to content

Remote error when running as script #4

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

Closed
robiwano opened this issue May 4, 2019 · 6 comments
Closed

Remote error when running as script #4

robiwano opened this issue May 4, 2019 · 6 comments

Comments

@robiwano
Copy link

robiwano commented May 4, 2019

I've installed all prerequisites, and I get the following when running my script read_sensor.py:

pi@raspberrypi:~/hum_temp_server $ ./read_sensor.py
Traceback (most recent call last):
  File "./read_sensor.py", line 13, in <module>
    print("\nTemperature: %0.1f C" % sensor.temperature)
  File "/usr/local/lib/python3.5/dist-packages/adafruit_htu21d.py", line 121, in temperature
    self.measurement(TEMPERATURE)
  File "/usr/local/lib/python3.5/dist-packages/adafruit_htu21d.py", line 140, in measurement
    self._command(what)
  File "/usr/local/lib/python3.5/dist-packages/adafruit_htu21d.py", line 93, in _command
    i2c.write(struct.pack('B', command))
  File "/usr/local/lib/python3.5/dist-packages/adafruit_bus_device/i2c_device.py", line 115, in write
    self.i2c.writeto(self.device_address, buf, **kwargs)
  File "/usr/local/lib/python3.5/dist-packages/busio.py", line 65, in writeto
    return self._i2c.writeto(address, buffer, stop=stop)
  File "/usr/local/lib/python3.5/dist-packages/adafruit_blinka/microcontroller/generic_linux/i2c.py", line 38, in writeto
    self._i2c_bus.write_bytes(address, buffer[start:end])
  File "/usr/local/lib/python3.5/dist-packages/Adafruit_PureIO/smbus.py", line 244, in write_bytes
    self._device.write(buf)
OSError: [Errno 121] Remote I/O error

However, entering all the commands in a python3 shell works just fine... (?). Content of read_sensor.py is:

#!/usr/bin/python3
import time
import board
import busio
from adafruit_htu21d import HTU21D

# Create library object using our Bus I2C port
i2c = busio.I2C(board.SCL, board.SDA)
sensor = HTU21D(i2c)

while True:
    print("\nTemperature: %0.1f C" % sensor.temperature)
    print("Humidity: %0.1f %%" % sensor.relative_humidity)
    time.sleep(2)

@ladyada
Copy link
Member

ladyada commented May 4, 2019

sounds like maybe you can add some time.sleep delays around, since its running too fast? see where that helps and let us know!

@robiwano
Copy link
Author

robiwano commented May 5, 2019

Adding a 100 ms sleep after getting sensor fixed it:

#!/usr/bin/python3
import time
import board
import busio
from adafruit_htu21d import HTU21D

# Create library object using our Bus I2C port
i2c = busio.I2C(board.SCL, board.SDA)
sensor = HTU21D(i2c)
time.sleep(0.1)

while True:
    print("\nTemperature: %0.1f C" % sensor.temperature)
    print("Humidity: %0.1f %%" % sensor.relative_humidity)
    time.sleep(2)

@robiwano
Copy link
Author

robiwano commented May 5, 2019

Actually, even a time.sleep(0.001) makes it work.

@ladyada
Copy link
Member

ladyada commented May 5, 2019

ooh ok, want to submit a PR to fix by adding a delay at the end of the HTU21D init? :)

@evaherrada
Copy link
Collaborator

Done

@tannewt
Copy link
Member

tannewt commented May 9, 2019

Fixed by #5. Thanks @dherrada

@tannewt tannewt closed this as completed May 9, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants