timofurrer / w1thermsensor

A Python package and CLI tool to work with w1 temperature sensors like DS1822, DS18S20 & DS18B20 on the Raspberry Pi, Beagle Bone and other devices.
MIT License
493 stars 113 forks source link

Unable to get Python 3 W1ThermSensor work with RPi 1-Wire Pi Plus adapter card #50

Closed mikespolk closed 5 years ago

mikespolk commented 5 years ago

I have been trying to get DS18B20 1-Wire temperature sensors to work with Raspberry Pi 2, with the 1-Wire Pi Plus adapter card installed, as in article https://www.abelectronics.co.uk/p/60/1-wire-pi-plus. To proceed, I have followed the guidelines in this article https://www.abelectronics.co.uk/kb/article/1/i2c--smbus-and-raspbian-linux. To get a Python 3 compatible library to read the sensors, I also installed the W1ThermSensor, as in article https://pypi.org/project/w1thermsensor. Essentially, here I ran the following command: sudo apt-get install python3-w1thermsensor.

However, when I ran the following Python demo script:

_import time from w1thermsensor import W1ThermSensor sensor = W1ThermSensor() tempr = sensor.gettemperature()

with the Thonny Python IDE, I end up with the following error message:

Python 3.5.3 (/usr/bin/python3)

%Run testi-2018-12a.py PROBLEM WITH THONNY'S BACK-END:

Traceback (most recent call last): File "/usr/lib/python3/dist-packages/thonny/backend.py", line 1164, in _execute_prepared_user_code exec(statements, global_vars) File "/home/pi/Honka/testi-2018-12a.py", line 3, in sensor = W1ThermSensor() File "/usr/lib/python3/dist-packages/w1thermsensor/core.py", line 118, in init raise NoSensorFoundError("Unknown", "") w1thermsensor.errors.NoSensorFoundError: No Unknown temperature sensor with id '' found

During handling of the above exception, another exception occurred:

Traceback (most recent call last): File "/usr/lib/python3/dist-packages/thonny/backend.py", line 1141, in execute_source return self._prepare_hooks_and_execute(bytecode, None, global_vars) File "/usr/lib/python3/dist-packages/thonny/backend.py", line 1156, in _prepare_hooks_and_execute return self._execute_prepared_user_code(statements, expression, global_vars) File "/usr/lib/python3/dist-packages/thonny/backend.py", line 1173, in _execute_prepared_user_code return {"user_exception": self._vm._prepare_user_exception()} File "/usr/lib/python3/dist-packages/thonny/backend.py", line 1029, in _prepare_user_exception "stack": self._export_stack(last_frame), File "/usr/lib/python3/dist-packages/thonny/backend.py", line 932, in _export_stack locals=self.export_variables(system_frame.f_locals), File "/usr/lib/python3/dist-packages/thonny/backend.py", line 886, in export_variables result[name] = self.export_value(variables[name], 100) File "/usr/lib/python3/dist-packages/thonny/backend.py", line 876, in export_value rep = repr(value) File "/usr/lib/python3/dist-packages/w1thermsensor/core.py", line 150, in repr self.class.name, self.type, self.id) AttributeError: 'W1ThermSensor' object has no attribute 'type'

So it seems that the W1ThermSensor library is unable to enumerate any of the (two) DS18B20 sensors that are connected.

Troubleshooting steps that I did:

  1. When using the (Python2 only) owfs library, as in article https://www.abelectronics.co.uk/kb/article/3/owfs-with-i2c-support-on-raspberry-pi, and ran the python example code listed in it, both of the DS18B20 sensors enumerate OK. So it seems that the sensor and adapter card connections are working as intended.

  2. When executed this command: i2cdetect -y 1, as in article https://raspberryblog.de/?p=2293, the "18" is shown as adviced.

  3. This command: lsmod | grep i2c, the listing is as follows: i2c_bcm2835 16384 0 i2c_dev 16384 0 (so, instead of listing this: "i2c_bcm2708", as in some articles, like here: https://www.abelectronics.co.uk/forums/thread/113/1-wire-plus-is-not-being-seen-with-i2cdetect)

  4. I also reinstalled the RPi from scratch, as in article https://www.imore.com/how-get-started-using-raspberry-pi, plus installed the guizero, i2c-tools, and python3-w1thermsensor, etc. needed modules (no any owfs installs however), but with same results.


I wouldn't want to switch to owfs library, because AFAIK is is only available for Python2. For example, the guizero library only works in Python3, so that's why I try to target the Python3.

What to do to get the W1ThermSensor work here?

timofurrer commented 5 years ago

What version of w1thermsensor are you using?

Can you please try with the current version or the latest version from pypi?

mikespolk commented 5 years ago

I think they already are the newest ones(?), as did the RPi scratch reinstall yesterday, and as listed from the Add/Remove Software: (x) Python w1 therm sensor module (Python 3) python3-w1thermsensor-1.0.5 Python w1 therm sensor module (Python 2) python-w1thermsensor-1.0.5

bsimmo commented 5 years ago

Do you get a reading not using the python software? i.e. hower the HAT says to get readings?

On Mon, 31 Dec 2018, 09:03 mikespolk <notifications@github.com wrote:

I think they already are the newest ones(?), as did the RPi scratch reinstall yesterday, and as listed from the Add/Remove Software: (x) Python w1 therm sensor module (Python 3) python3-w1thermsensor-1.0.5 Python w1 therm sensor module (Python 2) python-w1thermsensor-1.0.5

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/timofurrer/w1thermsensor/issues/50#issuecomment-450649113, or mute the thread https://github.com/notifications/unsubscribe-auth/ALALt5CavOCEhY4ft1cay-3coTDlvT3Gks5u-hkggaJpZM4ZlRVc .

bsimmo commented 5 years ago

Forgot to say, I ask as I am assuming it is this hat https://pinout.xyz/pinout/1_wire_pi_plus

You talk to a chip via i2c on the HAT, not with 1-wire directly, which this module does. See the link and the link on there to GitHub, their webpages etc.

On Mon, 31 Dec 2018, 09:28 Ben Simmons <bensimmo@gmail.com wrote:

Do you get a reading not using the python software? i.e. hower the HAT says to get readings?

On Mon, 31 Dec 2018, 09:03 mikespolk <notifications@github.com wrote:

I think they already are the newest ones(?), as did the RPi scratch reinstall yesterday, and as listed from the Add/Remove Software: (x) Python w1 therm sensor module (Python 3) python3-w1thermsensor-1.0.5 Python w1 therm sensor module (Python 2) python-w1thermsensor-1.0.5

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/timofurrer/w1thermsensor/issues/50#issuecomment-450649113, or mute the thread https://github.com/notifications/unsubscribe-auth/ALALt5CavOCEhY4ft1cay-3coTDlvT3Gks5u-hkggaJpZM4ZlRVc .

mikespolk commented 5 years ago

Yes, my 1-Wire adapter is just that formfactor that bsimmo sent the link for. Also, to clarify, what already have been tried:

  1. Just to make sure. to not interfere with any possible GPIO wirings I am going to use, I have disconnected any other connections from the GPIO pins.

  2. With the (Python2 level) OWFS library as I mentioned above, the sensors enumerate OK, but not with the w1thermsensor library.

  3. Did try many combinations in /boot/config.txt, /etc/modules, /etc/modprobe.d/raspi-blacklist.conf files, for the dtparam=i2c, dtparam=i2c1, i2c-bcm2708, i2c-bcm2835, i2c-dev, w1_gpio and w1_therm lines, to view if I have luck (=didn't have)

How to proceed next?

bsimmo commented 5 years ago

I guess mute (but I think that may just be the current issue) on the email or on GitHub stop following/etc. Have a look on GitHub, it'll be where you asked to follow.

On Mon, 31 Dec 2018, 14:03 fireheadman <notifications@github.com wrote:

How do I get off this list? I keep unsubscribing then get another email.

On Mon, Dec 31, 2018 at 8:30 AM mikespolk notifications@github.com wrote:

Yes, my 1-Wire adapter is just that formfactor that bsimmo sent the link for. Also, to clarify, what already have been tried:

1.

Just to make sure. to not interfere with any possible GPIO wirings I am going to use, I have disconnected any other connections from the GPIO pins. 2.

With the (Python2 level) OWFS library as I mentioned above, the sensors enumerate OK, but not with the w1thermsensor library. 3.

Did try many combinations in /boot/config.txt, /etc/modules, /etc/modprobe.d/raspi-blacklist.conf files, for the dtparam=i2c, dtparam=i2c1, i2c-bcm2708, i2c-bcm2835, i2c-dev, w1_gpio and w1_therm lines, to view if I have luck (=didn't have)

How to proceed next?

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub < https://github.com/timofurrer/w1thermsensor/issues/50#issuecomment-450658638 , or mute the thread < https://github.com/notifications/unsubscribe-auth/AS7YGz0-qCJ1wDo1OK0sJxBU6vIEHlHrks5u-i2agaJpZM4ZlRVc

.

— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/timofurrer/w1thermsensor/issues/50#issuecomment-450680889, or mute the thread https://github.com/notifications/unsubscribe-auth/ALALt41WWvQizIBk5xHiNtE7jMAzs-zUks5u-l9pgaJpZM4ZlRVc .

timofurrer commented 5 years ago

I think they already are the newest ones(?), as did the RPi scratch reinstall yesterday, and as listed from the Add/Remove Software:

@mikespolk the newest version is 1.1.2. I'd suggest that you install that one from pip and make sure you've removed the packages from raspbian installed via apt.

@mikespolk can we discuss and debug this issue in gitter? (link is in the README) I (or @bsimmo) can assist you to narrow down your problem.

mikespolk commented 5 years ago

OK, let's move to Gitter, and then finally update status here, when ready. Meanwhile, short answer: removed 1.0.5 with sudo apt-get --purge remove python3-w1thermsensor and then installed 1.1.2 with pip3 install w1thermsensor (hope, did that correctly, as aimed) However, no sensors enumerated, yet.

bsimmo commented 5 years ago

But your sensor HAT is i2c, 1-wire is 1-wire.

You need to talk to the HAT with i2c.

This module doesn't do that.

On Tue, 1 Jan 2019, 09:04 mikespolk <notifications@github.com wrote:

OK, let's move to Gitter, and then finally update status here, when ready. Meanwhile, short answer: removed 1.0.5 with sudo apt-get --purge remove python3-w1thermsensor and then installed 1.1.2 with pip3 install w1thermsensor (hope, did that correctly, as aimed) However, no sensors enumerated, yet.

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/timofurrer/w1thermsensor/issues/50#issuecomment-450730803, or mute the thread https://github.com/notifications/unsubscribe-auth/ALALtwXygDyrX2jodrJR7Rhb5EjxG5mIks5u-2rQgaJpZM4ZlRVc .

timofurrer commented 5 years ago

@bsimmo thanks for the answer, I think that's exactly the problem. I'm confused though as why the sensor appears in /sys/bus/w1/deviceswith the00` family code.

Which is not supported by the w1 kernel module according to https://www.kernel.org/doc/Documentation/w1/slaves/w1_therm

bsimmo commented 5 years ago

I think 00- could be 'ghost' sensors, i.e. not really there and/you have bad wiring. I'd have to search on it. Also no idea either.

On Tue, 1 Jan 2019, 14:39 Timo Furrer <notifications@github.com wrote:

@bsimmo https://github.com/bsimmo thanks for the answer, I think that's exactly the problem. I'm confused though as why the sensor appears in /sys/bus/w1/deviceswith the00` family code.

Which is not supported by the w1 kernel module according to https://www.kernel.org/doc/Documentation/w1/slaves/w1_therm

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/timofurrer/w1thermsensor/issues/50#issuecomment-450752222, or mute the thread https://github.com/notifications/unsubscribe-auth/ALALtyAJVMsQYvFu0_Gz5CH3jVcQiEjKks5u-7lUgaJpZM4ZlRVc .

mikespolk commented 5 years ago

Just to mention, yesterday again I doublechecked the wirings by installing the owfs library to my from-scratch-installed RPi, according these articles: https://www.abelectronics.co.uk/kb/article/3/owfs-with-i2c-support-on-raspberry-pi and https://www.abelectronics.co.uk/kb/article/1/i2c--smbus-and-raspbian-linux, and my DS18B20 and DS18S20 sensors enumerated OK.

bsimmo commented 5 years ago

So reading through that they are putting a 'driver' in to make fake 1-wire files. You'll need to modify this python module to pick up the specific serial code it creates. This module is not a driver, it just looks for valid serial numbers. You'll still need to be running that owfs 'driver' also.

On Tue, 1 Jan 2019, 23:37 mikespolk <notifications@github.com wrote:

Just to mention, yesterday again I doublechecked the wirings by installing the owfs library to my from-scratch-installed RPi, according these articles: https://www.abelectronics.co.uk/kb/article/3/owfs-with-i2c-support-on-raspberry-pi and https://www.abelectronics.co.uk/kb/article/1/i2c--smbus-and-raspbian-linux, and my DS18B20 and DS18S20 sensors enumerated OK.

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/timofurrer/w1thermsensor/issues/50#issuecomment-450786092, or mute the thread https://github.com/notifications/unsubscribe-auth/ALALt1woEqJkiTLsvABYYCpxKoVCljp5ks5u_Dd1gaJpZM4ZlRVc .

bsimmo commented 5 years ago

for the info, I've been working on the emails, for some reason the initial post didn't send the actual post with it, so I just went off the title and assumed there was no description with it. i'm on holiday and couldn't remember my GitHub login, I have now :-)

I understand the thread a bit better, same problem though.

bsimmo commented 5 years ago

so had a read through. I would suggest abondoning using this module for now.

look at the OWFS website and examples for reading the data from it the files or server/http port. it's used a lot and there are many examples from a quick search (I have never used it but have seen posts on it on the RPi forums)

but it look like it mounts the sensor in /mnt/1wire and reads from there as a file system, if you look there do you see them? if yes then just redirect any python3 program to read from there rather than /sys/bus/w1/devices/

then you'll not need to use the python server module. you will still need to have owfs running as that is taking the i2c reading from the chip on the hat and doing the conversion.

an alternative method is to see how to talk directly to the chip on the hat via i2c to get it's readings, but that sounds more complicated ;-)

Edit If you can see them in /mnt/1wire (just ls the folder as you would the 1-wire one). You could download the whole w1thermsensor folder from this module (to your working folder with your code) Edit core.py with the alteration on BASE_DIRECTORY = ""/mnt/1wire"

Then see if that works.

mikespolk commented 5 years ago

Yes, have to try that. Essentially, in that configuration, the owfs must be defined to autostart at boot, and then let it generate the temperature readings to /mnt/1wire folder, asynchronously in the background. Then my Py3 app would read the file contents when needed.

For that, I think that these articles would serve best: https://raspberrypi.stackexchange.com/questions/62292/usage-of-python-ow-one-wire-file-system-python-package-for-reading-1-wire-ds18b2 https://wiki.m.nu/index.php/OWFS_with_i2c_support_on_Raspberry_Pi_(English_version) because the autostart definition is there, too.

What I have to do first is to again create a fresh boot Raspbian image from scratch, to prevent existing w1thermsensor and its definitions or any other trial+error configurations from causing any secondary problems. Will take its time, and I will provide update then.

mikespolk commented 5 years ago

Yes, I got owfs background processes working, by following the above articles, essentially this: https://wiki.m.nu/index.php/OWFS_with_i2c_support_on_Raspberry_Pi_(English_version) As result:

Thank you timofurrer and bsimmo for Support and troubleshooting! I would however be very glad, if the w1thermsensor module would support the i2c bus, too, someday. That is because in home automation, where the cabling may be lengthy, 1-Wire adapter car protects RPi internal bus from electrical interference, and would let it run more stable from day to day.

bsimmo commented 5 years ago

In linux everything is a text file, the 1-wire is a text file as such too. Just done at slower level in the OS (the bits you load at the start up) If it looks the same owfs mnt folder then exerting DS18B20s code should work but pointed the the different directory. Try what I mentioned above.

I personally don't think this module should support i2c reading. At the moment this module just passed a text file. The OS is doing what OWFS is doing but for one wire at an OS module level. Leave it to OWFS to do the low level stuff, it designed for it and used in industry. Keep the expertise in one place. Or get OS to do it at the OS level.

On Thu, 3 Jan 2019, 12:07 mikespolk <notifications@github.com wrote:

Yes, I got owfs background processes working, by following the above articles, essentially this: https://wiki.m.nu/index.php/OWFS_with_i2c_support_on_Raspberry_Pi_(English_version)

  • 1-Wire sensors are connected via the HAT type 1-Wire Pi Plus adapter card
  • owfs autostarts at boot
  • In /mnt/1wire folder, there starts appearing 10 and 28 subfolders, for DS18S20 and DS18B20 sensor types, respectively
  • The up-to-date temperatures are readable in the temperature text files. So I can have my Py3 application, running in the foreground, to read temperatures from text files. The temperature readings seem to update automatically every 10 seconds or so.

Thank you timofurrer and bsimmo for Support and troubleshooting! I would however be very glad, if the w1thermsensor module would support the i2c bus, too, someday. That is because in home automation, where the cabling may be lengthy, 1-Wire adapter car protects RPi internal bus from electrical interference, and would let it run more stable from day to day.

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/timofurrer/w1thermsensor/issues/50#issuecomment-451209704, or mute the thread https://github.com/notifications/unsubscribe-auth/ALALtzNzbVmQxIquX5st7PvT7tjHbiX8ks5u_jjsgaJpZM4ZlRVc .

timofurrer commented 5 years ago

Thanks @bsimmo for the support!

I personally don't think this module should support i2c reading

What's great about this module is it's simplicity - in maintenance and usage. Therefore I want add i2c support any time soon - except someone has a really good point way it should be implemented.

Try what I mentioned above.

@mikespolk I'd be interested about that, too. Can you post the output of ls -lR /mnt/1wire here?

If that's working I'll add an option to configure this path.

mikespolk commented 5 years ago

Attached is listing you asked for, from a booted, idle RPi, having those owfs autostart stuff installed. mnt-1wire-folder-listing.txt

mikespolk commented 5 years ago

After all of the previous discussions, and because I would love to see things trivial where possible, I am quite confused with one thing: Why wouldn't there just be a module that, as its only task, executes a 1-wire read sequence thru the i2c bus, and then synchronously returns the results to the calling Py application? Instead of acting as a background server and using a drop-in directory structure to pass results? Or, is this question irrelevant in some way?

bsimmo commented 5 years ago

There may be one, I've never used an i2c module for 1-wire. If you know the i2c specs from the chipset datasheets you could probably make one. Grab the chip name and search on it.

On Fri, 4 Jan 2019, 11:11 mikespolk <notifications@github.com wrote:

After all of the previous discussions, and because I would love to see things trivial where possible, I am quite confused with one thing: Why wouldn't there just be a module that, as its only task, executes a 1-wire read sequence thru the i2c bus, and then synchronously returns the results to the calling Py application? Instead of acting as a background server and using a drop-in directory structure to pass results? Or, is this question irrelevant in some way?

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/timofurrer/w1thermsensor/issues/50#issuecomment-451488391, or mute the thread https://github.com/notifications/unsubscribe-auth/ALALtxkHgZx2HQM8GzlDQsv3Jpkt5RAjks5u_30ygaJpZM4ZlRVc .

MaherKhaz commented 1 year ago

l have the same problem. when l run w1thermsensor ls, there is no sensors found. The ds18b20 is emitting a red light. what does it mean please? It is plugged to pin 8 or ceo.