Hamburger Hamburger

Heating and Ventilation Control

/HvcReadSPI

Keine Erläuterungen gefunden.

"""
Taken and modified from https://pypi.org/project/mcp3208/
to enable chip select for  2 MCP3208
"""
try:
    import  Adafruit_GPIO.SPI as  SPI
except ImportError:
    class SPI(object):
        MSBFIRST = 1
        def  SpiDev(a, b, max_speed_hz): pass
        def  transfer(a): pass
        def  set_mode(a): pass
        def  set_bit_order(a): pass

class MCP3208(object):
    def  __init__(self,chip=0):
        self.spi = SPI.SpiDev(0, chip, max_speed_hz=1000000)
        self.spi.set_mode(0)
        self.spi.set_bit_order(SPI.MSBFIRST)

    def  __del__(self):
        self.spi.close()

    def  read(self, ch):
        if 7 <= ch <= 0:
            raise Exception('MCP3208 channel must be 0-7: ' + str(ch))

        cmd = 128  # 1000 0000
        cmd += 64  # 1100 0000
        cmd += ((ch & 0x07) << 3)
        ret = self.spi.transfer([cmd, 0x0, 0x0])

        # get the 12b out of the return
        val = (ret[0] & 0x01) << 11  # only B11 is here
        val |= ret[1] << 3           # B10:B3
        val |= ret[2] >> 5           # MSB has B2:B0 ... need to move down to LSB

        return (val & 0x0FFF)  # ensure we are only sending 12b

  
class HvcReadSPI:  
    """
    My specific class to connect my analougous sensors.
    """
    def  __init__(self):
        self.ADCPins={}
        self.ADCPins['haus'] =[0,1]
        #self.ADCPins['fire'] =[0,2]
        self.ADCPins['coll'] =[0,3]
        self.ADCPins['flow'] =[0,4]
        self.ADCPins['ret']  =[0,5]
        self.ADCPins['THot'] =[0,6]
        self.ADCPins['TLow'] =[0,7]
        self.ADCPins['ablu'] =[1,2] #1,0
        self.ADCPins['posBp']=[1,1]
        self.ADCPins['zulu'] =[1,0] #1,2
        self.ADCPins['erde'] =[1,3]
        self.ADCPins['folu'] =[1,4]
#        self.ADCPins['posBp']=[1,5]


    def  readADCverbose(self):
        """
        For debugging, this function returns a message with insights into the functionality. 
        """
        ADC={}
        
        adc0 = MCP3208(0)
        adc1 = MCP3208(1)

        message = "HvcReadSPI.readADCverbose \n"
        for  name in self.ADCPins:
            if self.ADCPins[name][0]==0:
                ADC[name] = adc0.read( self.ADCPins[name][1] )
            elif self.ADCPins[name][0]==1:
                ADC[name] = adc1.read( self.ADCPins[name][1] )
            else:
                message = message + "chip not defined! \n"

        message = message + str(ADC) + "\n"
            
        return ADC, message


    def  readADC(self):
        """
        For standard operation, the verbouse message is dropped.
        """
        ADC, message = HvcReadSPI.readADCverbose(self)
        return ADC

"""
for  testing
"""
if __name__ == "__main__":
    mySPI = HvcReadSPI()
    ADC,msg = mySPI.readADCverbose()
    print(msg)
    print("second call")
    ADC = mySPI.readADC()
    print(ADC)

    

python

1/HvcLightControl.py
2/HvcHCSR04ultrasonic.py
3/HvcPV.py
4/HvcMotorDriver.py
5/HvcRollerShutter.py
6/manGenMqttMap.py
7/HvcReadSPI.py
8/HvcMqtt.py
9/HvcTables.py
10/HvcMain.py
11/HvcSetGPIO.py
12/HvcWifiRelay.py
13/HvcOperationMode.py
14/HvcControl.py
15/HvcRaw2phys.py
16/HvcWeather.py
17/HvcOneWire.py
18/makeDoc.py
19/HvcFronius.py
20/EnergyManager.py
21/HvcSendI2C.py

php

1/HV_colorMap.php
2/HV_Admin_Login.php
3/HV_readOperationState.php
4/HV_setParameters.php
5/HV_config.php
6/EM_handleJSON.php
7/index.php
8/readFilenames.php
9/HV_restart.php
10/HV_moveGate.php
11/HV_showLog.php
12/HV_RollerShutter.php
13/EM_editParameter.php
14/HV_serviceLog.php
15/HV_H2Olevel.php
16/HV_TempCal.php
17/HV_Fronius.php
18/EM_plot.php
19/readNamedData.php
20/HV_composeH2Oplot.php
21/HVdoc.php
22/HV_showWeatherForecast.php
23/HV_showHouse.php

Der gesamte Sourcecode darf gemäß GNU General Public License weiterverbreitet werden.