Wie Thermoelement-Verstärker MAX31855 in Fhem einbinden

Begonnen von exot, 21 Oktober 2015, 08:47:30

Vorheriges Thema - Nächstes Thema

exot

Hallo, an alle in diesem Trade,
In der Hoffnung hier richtig zu sein, mein Problem.

Nachdem ich nun sehr lange gebraucht habe um mein Thermoelement-Verstärker MAX31855 unter putty in meinem Pi
zum Leben zu erwecken, stellt sich mir die Frage:
Wie bekomme ich das Teil in Fhem implementiert. Unter MAX... ist im Netzt nicht viel zu lesen außer Verkaufsanzeigen.
Da es ja ein spi Device ist habe ich unter dem Begriff gesucht. Aber auch leider nichts konkretes.
In diesem Trade habt Ihr Euch wenigstens mit spi auseinander gesetzt.
Jetzt der berühmte Satz: Ich bin Neuling und benötige Unterstützung, es ist aber halt so.
Wer kann einem alten Mann  :o  hilfreich unter die Arme greifen und hat dazu noch etwas Geduld wenn viele Fragen kommen sollten.
Angesprochen sind natürlich auch "Foreaner" die so ein Teil bereits eingebunden haben.
Ich bin mir sicher, dass es sie gibt.
ODER?? gibt es andere Möglichkeiten ein Thermoelement Typ K in Fhem einzubinden.
Danke schon mal.
Gruß Michael

exot

Hallo,
Immer noch auf der Suche nach einer Lösung bin ich jetzt fast so weit, dass Projekt mit dem MAX zu beenden,
da sich mir eine Lösung nicht erschließt.
Habe jetzt einen neuen Ansatz gefunden.
Und zwar: https://www.abelectronics.co.uk/p/17/ADC-Pi-V2---Raspberry-Pi-Analogue-to-Digital-converter
diesen 8 Kanal Analog Digital Wandler <ADC Pi>.
Wer kann mir darüber etwas hinsichtlich meiner Problematik mitteilen.
Kann ich hier ein Thermoelement anschließen? Wenn ja, was ich hoffe, ist dann eine Verbindung mit Fhem möglich.
Danke Michael

Thorsten Pferdekaemper

Hi,
muss es denn unbedingt so ein Thermoelement sein? Es gibt doch noch einige andere Lösungen, eine Temperatur zur erfassen. Z.B. wären da 1-Wire und Homematic.
Ansonsten: Wenn Du es schon geschafft hast, auf der Konsole eine Temperatur anzuzeigen, dann müsste man das doch auch nach FHEM bringen. Ich würde damit anfangen, einen Dummy anzulegen, dem ein Reading für die Temperatur zu verpassen und das zyklisch über ein at zu füllen.
Gruß,
   Thorsten
FUIP

exot

Halo Thorsten,
Danke das Du mir geantwortet hast.
Thermoelement deshalb, da der Temperaturbereich zwischen 20° und 1000° liegt.
Es ist eine Brennraumtemperatur und wie ich gelesen habe schaffen das eben nur Thermoelemente.
Der Punkt bei dem MAX31855 ist, dass die Übertragung über einen spi Bus und nicht i2c geschieht.
Die momentane Situation ist, dass die Abbildung auf der Konsole prima funktioniert.
Gestern habe ich noch zusätzlich webgpioi installiert. Hiermit kann man aber nur die GPIO's direkt über den Bildschirmschalten.
Mir ist aber aufgefallen, dass GPIO 18 (do) regelmäßig blinkt und zwar immer wenn das Thermoelement einen Wert übermittelt.
Das Thermoelement soll aber nur ein Baustein in einer Kette von weiteren Temperaturen sein.
Diese sollen dann Mittels DS18B20 über 1 Wired Isc Bus laufen. Aber erst wenn ich das Thermoelement gepackt habe.
Wenn ich die Info in Bezug auf den ADC Pi richtig verstanden habe sollte der doch analoge Signale ( Themoelement) in digitale Signale
( GPIO Ports PI) umwandeln. Damit sollte erreicht sein, dass beide Sensortypen in Verbindung mit dem ADC  eine Kommunikation mit dem Pi erreichen.
Ich bin mir aber nicht sicher ob meine Vermutung richtig ist.
Gruß Michael

Thorsten Pferdekaemper

Hi,
wenn Du es doch schon in der Konsole geschafft hast, warum machst Du dann noch mit irgendeinem Web-Kram rum? Ich würde versuchen, was auch immer Du da in der Konsole aufrufst, in FHEM zu integrieren.
1-Wire ist dann ein anderes Thema, dass meiner Meinung nach unabhängig behandelt werden sollte.
Zeig doch mal hier, wie das auf der Konsole aussieht, inklusive welche Kommandos Du dafür aufrufst.
Gruß,
   Thorsten
FUIP

exot

Hallo Thorsten,
Danke!!!!
Ich bin für 2 Sunden dringend außer Haus.
Antwort wenn ich wieder da bin!!
Danke.
Gruß Michael

exot

Hallo Thomas,
Das ist der Log auf der Konsole.
cd /home/pi/Adafruit_Python_MAX31855/examples
sudo python simpletest.py
#Beenden
Strg+c

Die belegten GPIO Ports sind:
CLK = 25
CS = 24
DO =18
Gruß Michael

Thorsten Pferdekaemper

Zitat von: exot am 22 Oktober 2015, 17:42:01
Hallo Thomas,
Welcher Thomas?

sudo python simpletest.py
An Deiner Stelle würde ich aus dem simpletest.py ein Programm machen, was einfach nur die Temperatur einmal ausgibt. D.h. nur die nackte Zahl, ohne sonstiges außenrum. Das kannst Du dann von FHEM aus mit einer einfachen Perl-Funktion aufrufen und regelmäßig in ein Reading von irgendeinem Device (z.B. ein Dummy) schieben. Fertig.
FUIP

exot

Hallo Thomas,
hört sich alles sehr einfach an, nur für mich nicht.
#!/usr/bin/python
# Copyright (c) 2014 Adafruit Industries
# Author: Tony DiCola
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in
# all copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
# THE SOFTWARE.

# Can enable debug output by uncommenting:
#import logging
#logging.basicConfig(level=logging.DEBUG)

import time

import Adafruit_GPIO.SPI as SPI
import Adafruit_MAX31855.MAX31855 as MAX31855


# Define a function to convert celsius to fahrenheit.
def c_to_f(c):
        return c * 9.0 / 5.0 + 32.0


# Uncomment one of the blocks of code below to configure your Pi or BBB to use
# software or hardware SPI.

# Raspberry Pi software SPI configuration.
CLK = 25
CS  = 24
DO  = 18
sensor = MAX31855.MAX31855(CLK, CS, DO)

# Raspberry Pi hardware SPI configuration.
#SPI_PORT   = 0
#SPI_DEVICE = 0
#sensor = MAX31855.MAX31855(spi=SPI.SpiDev(SPI_PORT, SPI_DEVICE))

# BeagleBone Black software SPI configuration.
#CLK = 'P9_12'
#CS  = 'P9_15'
#DO  = 'P9_23'
#sensor = MAX31855.MAX31855(CLK, CS, DO)

# BeagleBone Black hardware SPI configuration.
#SPI_PORT   = 1
#SPI_DEVICE = 0
#sensor = MAX31855.MAX31855(spi=SPI.SpiDev(SPI_PORT, SPI_DEVICE))

# Loop printing measurements every second.
print 'Press Ctrl-C to quit.'
while True:
temp = sensor.readTempC()
internal = sensor.readInternalC()
print 'Thermocouple Temperature: {0:0.3F}*C / {1:0.3F}*F'.format(temp, c_to_f(temp))
print '    Internal Temperature: {0:0.3F}*C / {1:0.3F}*F'.format(internal, c_to_f(internal))
time.sleep(1.0)

Ist das nicht das Programm?
oder dieser Code?
# Copyright (c) 2014 Adafruit Industries
# Author: Tony DiCola
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in
# all copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
# THE SOFTWARE.
import logging
import math

import Adafruit_GPIO as GPIO
import Adafruit_GPIO.SPI as SPI

# Default I2C address for device.
MCP9808_I2CADDR_DEFAULT        = 0x18

# Register addresses.
MCP9808_REG_CONFIG             = 0x01
MCP9808_REG_UPPER_TEMP         = 0x02
MCP9808_REG_LOWER_TEMP         = 0x03
MCP9808_REG_CRIT_TEMP          = 0x04
MCP9808_REG_AMBIENT_TEMP       = 0x05
MCP9808_REG_MANUF_ID           = 0x06
MCP9808_REG_DEVICE_ID          = 0x07

# Configuration register values.
MCP9808_REG_CONFIG_SHUTDOWN    = 0x0100
MCP9808_REG_CONFIG_CRITLOCKED  = 0x0080
MCP9808_REG_CONFIG_WINLOCKED   = 0x0040
MCP9808_REG_CONFIG_INTCLR      = 0x0020
MCP9808_REG_CONFIG_ALERTSTAT   = 0x0010
MCP9808_REG_CONFIG_ALERTCTRL   = 0x0008
MCP9808_REG_CONFIG_ALERTSEL    = 0x0002
MCP9808_REG_CONFIG_ALERTPOL    = 0x0002
MCP9808_REG_CONFIG_ALERTMODE   = 0x0001


class MAX31855(object):
"""Class to represent an Adafruit MAX31855 thermocouple temperature
measurement board.
"""

def __init__(self, clk=None, cs=None, do=None, spi=None, gpio=None):
"""Initialize MAX31855 device with software SPI on the specified CLK,
CS, and DO pins.  Alternatively can specify hardware SPI by sending an
Adafruit_GPIO.SPI.SpiDev device in the spi parameter.
"""
self._logger = logging.getLogger('Adafruit_MAX31855.MAX31855')
self._spi = None
# Handle hardware SPI
if spi is not None:
self._logger.debug('Using hardware SPI')
self._spi = spi
elif clk is not None and cs is not None and do is not None:
self._logger.debug('Using software SPI')
# Default to platform GPIO if not provided.
if gpio is None:
gpio = GPIO.get_platform_gpio()
self._spi = SPI.BitBang(gpio, clk, None, do, cs)
else:
raise ValueError('Must specify either spi for for hardware SPI or clk, cs, and do for softwrare SPI!')
self._spi.set_clock_hz(5000000)
self._spi.set_mode(0)
self._spi.set_bit_order(SPI.MSBFIRST)

def readInternalC(self):
"""Return internal temperature value in degrees celsius."""
v = self._read32()
# Ignore bottom 4 bits of thermocouple data.
v >>= 4
# Grab bottom 11 bits as internal temperature data.
internal = v & 0x7FF
if v & 0x800:
# Negative value, take 2's compliment. Compute this with subtraction
# because python is a little odd about handling signed/unsigned.
internal -= 4096
# Scale by 0.0625 degrees C per bit and return value.
return internal * 0.0625

def readTempC(self):
"""Return the thermocouple temperature value in degrees celsius."""
v = self._read32()
# Check for error reading value.
if v & 0x7:
return float('NaN')
# Check if signed bit is set.
if v & 0x80000000:
# Negative value, take 2's compliment. Compute this with subtraction
# because python is a little odd about handling signed/unsigned.
v >>= 18
v -= 16384
else:
# Positive value, just shift the bits to get the value.
v >>= 18
# Scale by 0.25 degrees C per bit and return value.
return v * 0.25

def _read32(self):
# Read 32 bits from the SPI bus.
raw = self._spi.read(4)
if raw is None or len(raw) != 4:
raise RuntimeError('Did not read expected number of bytes from device!')
value = raw[0] << 24 | raw[1] << 16 | raw[2] << 8 | raw[3]
self._logger.debug('Raw value: 0x{0:08X}'.format(value & 0xFFFFFFFF))
return value

Damit bin ich dann auch am Ende.
Gruß Michael

Thorsten Pferdekaemper

Zitat von: exot am 22 Oktober 2015, 19:39:32
Hallo Thomas,
Ich frage mich immer noch, wen Du meinst...

Lege mal eine Datei namens "temperatur.py" an und packe folgenden Text rein:

#!/usr/bin/python
# Author: Thorsten Pferdekaemper

import Adafruit_MAX31855.MAX31855 as MAX31855

# Raspberry Pi software SPI configuration.
CLK = 25
CS  = 24
DO  = 18
sensor = MAX31855.MAX31855(CLK, CS, DO)

temp = sensor.readTempC()
print '{0:0.3F}'.format(temp)

Diese Datei packst Du dann in dasselbe Verzeichnis wie simpletest.py. Jetzt in das Verzeichnis wechseln und "chmod a+x temperatur.py".
Jetzt müsste ein "./temperatur.py" Dir genau einmal die aktuell gemessene Temperatur ausgeben.
Mach erstmal soweit...
Gruß,
   Thorsten
FUIP

exot


Thorsten Pferdekaemper

#11
Willst Du mich ärgern?
Da Du die dezenten Hinweise ignorierst: THORSTEN, nicht THOMAS!

Ok, Du scheinst prinzipiell Probleme mit den Details zu haben:
Probier mal "./temperatur.py" und NICHT "sudo python temperatur.py".

...und wenn das klappt, dann gib mal im FHEM-Kommandofeld das hier ein:

{ qx('/home/pi/Adafruit_Python_MAX31855/examples/Temperatur.py') }
FUIP

exot

Hallo Thorsten,
Bitte um Entschuldigung,
Sollte nicht wieder vorkommen.
Leider hat es nicht geklappt.
Ich habe es mehrmals versucht.
Wie Du siehst ist die Datei "temperatur.py" aber in dem vorgegebenen Verzeichnis
Was mich wundert ist, usr/bin/python?
Die Datei liegt aber unter home/pi/Adafruit_Python_MAX31855/examples
Danke Michael

Thorsten Pferdekaemper

Hi,
schau mal, ob da irgendwelche Zeichen in der Zeile

#!/usr/bin/python

in der temperatur.py sind. Lösche auch mal alle Leerzeichen dahinter. Das "^M" kommt mir komisch vor.
Dann mach mal "which python".
Gruß,
   Thorsten
FUIP

exot

Hallo Thorsten,
/usr/bin/python -- das ist doch wenn ich jetzt richtig gesucht und gefunden habe der Interpreter.
Den Interpreter (python) gibt es da aber nicht.
#!/usr/bin/python
Das ist die angefragte Zeile.
Gruß Michael