Coder Social home page Coder Social logo

pydigitemp's People

Contributors

dragoshenron avatar elementarnaud avatar mcsakoff avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

pydigitemp's Issues

Temperature sensor (XY) error Read/Write error

Hi,

in my simple test program i have:

try:
    starttime = int(time.time())
    while True:
        for sensor in sensors:
            temp = sensor.get_temperature()
            print ("%5d" % getdelay(starttime), sensor.rom, end=":")
            if isinstance(temp, float):
                print ("%0.1f" % temp)
            else:
                errcnt[sensor.rom] += 1
                print (type(temp), "\aErr %s" % errcnt)
            sys.stdout.flush()
        print ("-"*50)
        time.sleep(4)
except termios.error:
    print ("Disconnected...")

The sensors list is list of DS18B20() objects...

I use it to test different UART <-> 1-wire circuits and i sometime get "Read/Write error", the problem is, that it is not an exception, but it appears as stdin (or perhaps stderr) output. Here is example two readings of two sensors, one without error and one with error:

--------------------------------------------------
 2543 282E12D50400005A:24.9
 2544 283DA9E104000021:23.0
--------------------------------------------------
 2548 282E12D50400005A:24.9
Temperature sensor (283DA9E104000021) error Read/Write error
 2552 283DA9E104000021:<class 'NoneType'> Err {'282E12D50400005A': 0, '283DA9E104000021': 1}
--------------------------------------------------

It seems, that the get_temperature() doesn't raise this exception, but only reports text and this is problem to catch. I try to find, where this printing happens, but i lost in code. Please, can you implement raising this error instead printing, to one can catch it in try .. except block?

Windows compatibility

On Windows, calling fileno() on a Serial object raises an UnsupportedOperation exception.

import serial
uart = serial.Serial('COM4')
uart.fileno()

image

I will be submitting a pull request to address this issue and let Windows users work with pydigitemp.

Issue with DS18S20 device

When reading via pyDigiTemp I get inconsistent results, compared to DigiTemp.

PyDigiTemp;

root@sbcctrl:~/digitemp# python
Python 2.7.13 (default, Nov 24 2017, 17:33:09) 
[GCC 6.3.0 20170516] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> from digitemp.master import UART_Adapter
>>> from digitemp.device import DS1820
>>> bus = UART_Adapter('/dev/ttyUSB5')
>>> sensor = DS1820(bus)
>>> print sensor.info()
Bus: /dev/ttyUSB5
Device: DS18S20 - High-precision Digital Termometer
ROM Code: 1048293103080071
Power Mode: external
Connection Mode: single-drop
Alarms: high = +75 C, low = +70 C
None
>>> print sensor.get_temperature()
17.38
>>> print sensor.get_temperature()
15.5
>>> print sensor.get_temperature()
16.13
>>> print sensor.get_temperature()
14.06
>>> print sensor.get_temperature()
16.19
>>> 
root@sbcctrl:~/digitemp#

DigiTemp;

root@sbcctrl:~/digitemp# digitemp_DS9097 -i -s /dev/ttyUSB5 -a
DigiTemp v3.7.1 Copyright 1996-2015 by Brian C. Lane
GNU General Public License v2.0 - http://www.digitemp.com
Turning off all DS2409 Couplers
.
Searching the 1-Wire LAN
1048293103080071 : DS1820/DS18S20/DS1920 Temperature Sensor
ROM #0 : 1048293103080071
Wrote .digitemprc
Jul 26 08:31:38 Sensor 0 C: 26.50 F: 79.70
root@sbcctrl:~/digitemp#

Example snippet not working

In the example labeled "Get temperature when there is only one 1-wire device on the bus", there is a typo and TemperatureSensor() call does not match the signature for this class and therefore fails.

Example

from digitemp.master import UART_Adapter
from digitemp.device import TemperatureSensor

sensor = TemperatureSensor(UART_Adapter('/dev/ttyS0') # <- missing ')'
sensor.info()
print(sensor.get_temperature())

Signature

def TemperatureSensor(bus, rom): # rom must be passed

Maybe you were thinking of OneWireTemperatureSensor() ?

Thank you for sharing your library btw!

Inproper device disconnect handle

Hi,

while further playing with it i go to another exceptions troubles. I have simple test program:

import time

from digitemp.master import UART_Adapter
from digitemp.device import DS18B20
from digitemp.exceptions import DeviceError, AdapterError

device = "/dev/tty1wUSB"
sensID = "282E12D50400005A"

print ("Connecting to '%s'..." % device)

# infinite device loop
while True:
    try:
        bus    = UART_Adapter(device)
        print ("Connected to '%s'..." % device)
        sensor = DS18B20(bus, rom=sensID)

        # infinite reading loop
        while True:
            try:
                temp = sensor.get_temperature()
                #temp = round(temp * 4) / 4
                print ("{}:{}".format(sensID, temp))
            except AdapterError:
                print ("U")

            time.sleep(10)
    except KeyboardInterrupt:
        print ("Koniec...")
        break

bus.close()

Purpose of the testing is to catch the device disconnect and eventually reconnect it again (and continue with measuring) when device is connected again. With this code i did simple tests:

  • run without device connected
  • disconnect after initial connecting

Although in both cases is the error the same, your code throws different exceptions in both cases:

  • in attempt to run on disconnected device i get FileNotFoundError followed by the serial.serialutil.SerialException
  • in attempt to read disconnected device (after bus was initialized) i get termios.error

This requires to import two additional modules (serial and termios) to catch these situations and catch both exceptions.

There is defined DeviceError exception in your code, then IMO both these situations have to be catched by module and have to raise DeviceError (eg. with text from original exception) exception, to make code more cleaner. Or is this exception intended for something other?

UART > 1-wire schematics

While I experimented with this i collect some different solutions on the internet and i created SVG schematics of them. I am not able to attach it here (github complains about unsupported file type for SVG and for ZIP too). You can download archive here http://digitemp.slavino.sk/uart-1wire.zip (i will delete it after issue will be closed).

These i tested:

  • ds18b20-uart.svg
  • ds18b20-uart-par.svg
  • ds18b20-uart-dioda.svg
  • ds18b20-uart-diodapar.svg

The parasitic mode works for short lines - i was success in 1 m and less and not success in 10 m (both with 3k3 resistor, perhaps lowering resistor value can help). Nonparasitic mode i didn't test on 10 m - i have no long 3-wire cable ;-) I tried all with the CP2102 USB/UART adapter in two flavors -- one with USB-A and second with micro USB connector. The first one gives better results, then usage depends on adapter too. In short, not all schematics works in all cases, depending on adapter and cable length.

These i didn't test yet, the MOSFET is directly from Maxim application note and NPN from forgotten site:

  • ds18b20-uart-mosfet.svg
  • ds18b20-uart-npn.svg

These schematics are not developed by me, i only draw them, then i am not sure about license.

pydigitemp does not play well with DS18B20 (not DS18S20)

I can successfully use digitemp (not pydigitemp) to talk to my DS18B20 temperature sensor attached to my Linux/Ubuntu machine. However, pydigitemp seems not to play nice with the DS18B20.

I used the following python code to test pydigitemp:


from digitemp.master import UART_Adapter
from digitemp.device import AddressableDevice
from digitemp.device import DS1820

print(AddressableDevice(UART_Adapter('/dev/ttyUSB3')).get_connected_ROMs())
bus = UART_Adapter('/dev/ttyUSB3') # DS9097 connected to COM1
sensor = DS1820(bus)
sensor.info()


Running this test, I get the following output:


python pydigitemp_testy.py

['28B62E1707000035']
Traceback (most recent call last):
File "pydigitemp_testy.py", line 12, in
sensor = DS1820(bus)
File "/home/brennmat/pydigitemp/digitemp/device/termometer.py", line 39, in init
raise DeviceError('The device is not a %s' % self._device_name(self.FAMILY_CODE))
digitemp.exceptions.DeviceError: The device is not a DS18S20 - High-precision Digital Termometer


It looks like pydigitemp does not recognize the DS18B20, although it is very similar to the DS18S20. Also the DS18B20 is listed as supported hardware under https://github.com/neenar/pydigitemp. In fact, I could make pydigitemp work by uncommenting lines 38 and 39 in the file digitemp/device/termometer.py, which gave the following output from the test code:


python pydigitemp_testy.py

['28B62E1707000035']
Bus: /dev/ttyUSB3
Device: DS18S20 - High-precision Digital Termometer
ROM Code: 28B62E1707000035
Power Mode: external
Connection Mode: single-drop
Alarms: high = +75 C, low = +70 C


It seems to me that the change required to make pydigitemp play nice with the DS18B20 would be rather small, but I don't know where to look and how to do this. Any help or code update would be greatly appreciated!

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.