Jump to content

mehrere ds18b20 Sensoren mit dem 1wire bricklet auslesen? (python)


Recommended Posts

Hallo,

wie muss denn der python code aussehen, wenn mehrere ds18b20 Sensoren mit dem 1wire bricklet ausgelesen werden sollen?

Ich bin leider etwas ratlos :-\

 

#!/usr/bin/env python
# -*- coding: utf-8 -*-

HOST = "localhost"
PORT = 4223
UID = "GGW" # Change XYZ to the UID of your One Wire Bricklet GGW

import time

from tinkerforge.ip_connection import IPConnection
from tinkerforge.bricklet_one_wire import BrickletOneWire

if __name__ == "__main__":
    ipcon = IPConnection() # Create IP connection
    ow = BrickletOneWire(UID, ipcon) # Create device object

    ipcon.connect(HOST, PORT) # Connect to brickd
    # Don't use device before ipcon is connected

    ow.write_command(0, 78) # WRITE SCRATCHPAD
    ow.write(0) # ALARM H (unused)
    ow.write(0) # ALARM L (unused)
    ow.write(127) # CONFIGURATION: 12 bit mode

    # Read temperature 10 times
    for i in range(5):
        ow.write_command(0, 68) # CONVERT T (start temperature conversion)
        time.sleep(1) # Wait for conversion to finish
        ow.write_command(0, 190) # READ SCRATCHPAD

        t_low = ow.read().data
        t_high = ow.read().data
        print('Temperature: {0} °C'.format((t_low | (t_high << ) / 16.0))
        print('Temperature1: {0} °C'.format((t_low | (t_high << ) / 16.0))#??

    raw_input("Press key to exit\n") # Use input() in Python 3
    ipcon.disconnect()

Vielen Dank für die Hilfe

Link to comment
Share on other sites

Das ist gar nicht so schwierig. Du holst dir zuerst per "search_bus" die IDs der ganzen Sensoren:

ids = ow.search_bus().identifier

 

Dann kannst du auf die einzelnen Sensoren zugreifen in dem du bei jedem "write_command" die id anstatt 0 überträgst, z.B.:

ow.write_command(ids[0], 78) 

 

 

Link to comment
Share on other sites

:)

das mit den ids hat funktioniert,

 

und wie soll der print befehl für den folgenden sensor geschrieben werden?

Verstehe nicht, was in der {0} zu stehen hat inder zeile print.

#!/usr/bin/env python
# -*- coding: utf-8 -*-

HOST = "localhost"
PORT = 4223
UID = "GGW" # Change XYZ to the UID of your One Wire Bricklet GGW

import time

from tinkerforge.ip_connection import IPConnection
from tinkerforge.bricklet_one_wire import BrickletOneWire

if __name__ == "__main__":
    ipcon = IPConnection() # Create IP connection
    ow = BrickletOneWire(UID, ipcon) # Create device object

    ipcon.connect(HOST, PORT) # Connect to brickd
    # Don't use device before ipcon is connected

    ids = ow.search_bus().identifier      
    print ids
    ow.write_command(15348569994255425064L, 78) # WRITE SCRATCHPAD
    ow.write_command(14772109243647972136L, 78)


    
    ow.write(0) # ALARM H (unused)
    ow.write(0) # ALARM L (unused)
    ow.write(127) # CONFIGURATION: 12 bit mode

    # Read temperature 2 times
    for i in range(2):
        ow.write_command(15348569994255425064L, 68) 
        ow.write_command(14772109243647972136L, 68)        
        
        time.sleep(1) # Wait for conversion to finish
        ow.write_command(15348569994255425064L, 190) # READ SCRATCHPAD
        ow.write_command(14772109243647972136L, 190)       

        t_low = ow.read().data
        t_high = ow.read().data
        print('Temperature: {0} °C'.format((t_low | (t_high << ) / 16.0))
        print('Temperature1: {0} °C'.format((t_low | (t_high << ) / 16.0))





    #raw_input("Press key to exit\n") # Use input() in Python 3
    ipcon.disconnect()





 

als Ergebnis bekomme ich:

(15348569994255425064L, 14772109243647972136L)
Temperature: 17.3125 °C
Temperature1: 17.3125 °C
Temperature: 17.3125 °C
Temperature1: 17.3125 °C

 

Vielen Dank ::)

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

 Share

×
×
  • Create New...