vitormhenrique / OctoPrint-Enclosure

OctoPrint Enclosure Plugin

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Multiple DS18B20 working with OctoPrint-Enclosure - anyone got this working?

LightningShark25 opened this issue · comments

Hi has anyone managed to get multiple DS18B20 working with Octopi/Octoprint?
I got one sensor working correctly by adding the dtoverlay to the boot/config.txt

I want to use a second sensor connected to a different GPIO pin

The following page https://pinout.xyz/pinout/1_wire suggests this is possible atleast with raspberry PI.

dtoverlay w1-gpio gpiopin=4 pullup=0 # header pin 7
dtoverlay w1-gpio gpiopin=17 pullup=0 # header pin 11

This didn't work for me, neither sensor shows up after a reboot. Probably some syntax or something silly
Anyone else succeeded?

yes I did this yesterday, walk in the park
I used gpio pin 4 for both DS18B20
Did you populate the serial of the DS18B20 ?

need to add this below:
sudo nano /boot/config.txt
dtoverlay=w1-gpio,gpiopin=4

pi@octopi:~ $ dmesg | grep w1-gpio
pi@octopi:~ $ sudo modprobe w1-gpio [I think this turns on the pullup R]
pi@octopi:~ $ sudo modprobe w1-therm [I think this turns on the pullup R]
pi@octopi:~ $ cd /sys/bus/w1/devices
pi@octopi:/sys/bus/w1/devices
ls
28-ba7a82116461 w1_bus_master1 [if you do not get the serial, then there are no coms to the DS18B20]
Enter the above serial into enclosure plugin

Please be aware with Python 3 DS18b20 don't work.

This is what you will get

2021-10-29 12:09:15,377 - octoprint.plugins.enclosure - WARNING - An exception of type IndexError occurred on log_error. Arguments:
('list index out of range',)
Traceback (most recent call last):
File "/home/pi/oprint/lib/python3.7/site-packages/octoprint_enclosure/init.py", line 986, in get_sensor_data
temp = self.read_18b20_temp(sensor['ds18b20_serial'])
File "/home/pi/oprint/lib/python3.7/site-packages/octoprint_enclosure/init.py", line 1203, in read_18b20_temp
lines = self.read_raw_18b20_temp(serial_number)
File "/home/pi/oprint/lib/python3.7/site-packages/octoprint_enclosure/init.py", line 1218, in read_raw_18b20_temp
device_folder = glob.glob(base_dir + str(serial_number) + '*')[0]
IndexError: list index out of range
2021-10-29 12:09:15,379 - octoprint.plugins.enclosure - WARNING - An exception of type TypeError occurred on log_error. Arguments:
('cannot unpack non-iterable NoneType object',)
Traceback (most recent call last):
File "/home/pi/oprint/lib/python3.7/site-packages/octoprint_enclosure/init.py", line 811, in check_enclosure_temp
temp, hum = self.get_sensor_data(sensor)
TypeError: cannot unpack non-iterable NoneType object

why does it not work on python3

@pintail120 so you used the same GPIO pin 4 for both sensors?
I did all the other config you used - the difference was I was trying two different GPIO pins.
I'll try putting them on the same GPIO pin4 - thanks!

When it fails I get something similar in my octoprint log to @nfored but I'm not on the upgraded python 3.
I suspect those messages appear when the sensors are not available??

Yes same data pin for both.
The DS18B20 has a unique serial number, it uses its data pin like a bus, therefore only the correct DS18B20 will respond when addressed.
I have read somewhere that the DS18B20 will only work on gpio4, not sure how true that is but it was on one of the links I read.

This is my version of python:
pi@octopi:~ $
pi@octopi:~ $
pi@octopi:~ $ python
Python 2.7.16 (default, Oct 10 2019, 22:02:15)
[GCC 8.3.0] on linux2
Type "help", "copyright", "credits" or "license" for more information.

PS please do not use my serial I indicated above, you need to find both the serial numbers of your ds18b20 and enter them into enclosure plugin.

I think only pin 4 is technically a 1 wire pin, much like only a single set of pins can do i2c.

If you check the link I included in the original post you will see that onewire on other pins is possible.
I just didn't get it working properly
Either way if it works properly on GPIO 4 then its an easy fix. Will report back when I get a chance..

using pin 4 is the way to go, with multiple on the same pin, only getting the serial number for each, have you tested it?

Can confirm 2 sensors on PIN 4 working no issues. Not quite what I was trying to do - but no fuss.
Thanks guys