Skip to content
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

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

Closed
mikespolk opened this issue Dec 31, 2018 · 23 comments

Comments

@mikespolk
Copy link

mikespolk commented Dec 31, 2018

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.get_temperature()

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
Copy link
Owner

What version of w1thermsensor are you using?

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

@mikespolk
Copy link
Author

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
Copy link

bsimmo commented Dec 31, 2018 via email

@bsimmo
Copy link

bsimmo commented Dec 31, 2018 via email

@mikespolk
Copy link
Author

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
Copy link

bsimmo commented Dec 31, 2018 via email

@timofurrer
Copy link
Owner

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
Copy link
Author

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
Copy link

bsimmo commented Jan 1, 2019 via email

@timofurrer
Copy link
Owner

@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
Copy link

bsimmo commented Jan 2, 2019 via email

@mikespolk
Copy link
Author

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
Copy link

bsimmo commented Jan 2, 2019 via email

@bsimmo
Copy link

bsimmo commented Jan 2, 2019

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
Copy link

bsimmo commented Jan 2, 2019

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
Copy link
Author

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
Copy link
Author

mikespolk commented Jan 3, 2019

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:

  • 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.

@bsimmo
Copy link

bsimmo commented Jan 3, 2019 via email

@timofurrer
Copy link
Owner

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
Copy link
Author

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

@mikespolk
Copy link
Author

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
Copy link

bsimmo commented Jan 4, 2019 via email

@MaherKhaz
Copy link

MaherKhaz commented Jan 14, 2023

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.

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