コード例 #1
0
	def getI2CTemp():
		try:
			sensora, sensorb = bus.transaction(i2c.write_bytes(temphomeaddress, 0x00),
			i2c.read(temphomeaddress,2))[0]
			
			temp = (sensora << 8 | sensorb) /256
			return temp
		except:
			print ("get i2ctemp failed")	
			return 0.00	
コード例 #2
0
    def getI2CTemp():
        try:
            sensora, sensorb = bus.transaction(
                i2c.write_bytes(temphomeaddress, 0x00),
                i2c.read(temphomeaddress, 2))[0]

            temp = (sensora << 8 | sensorb) / 256
            return temp
        except:
            print("get i2ctemp failed")
            return 0.00
コード例 #3
0
    def getadcreading(address, channel):
        bus.transaction(i2c.write_bytes(address, channel))
        time.sleep(0.05)
        h, l, r = bus.transaction(i2c.read(address, 3))[0]
        time.sleep(0.05)
        h, l, r = bus.transaction(i2c.read(address, 3))[0]

        t = (h << 8 | l)
        if (t >= 32768):
            t = 655361 - t
        v = t * 2.048 / 32768.0

        return v
	def getadcreading(address, channel):
		bus.transaction(i2c.write_bytes(address, channel))
		time.sleep(0.05)
		h, l, r = bus.transaction(i2c.read(address,3))[0]
		time.sleep(0.05)
		h, l, r = bus.transaction(i2c.read(address,3))[0]
		
		t = (h << 8 | l)
		if (t >= 32768):
			t = 655361 -t
		v = t * 2.048/32768.0	
		
		return v
コード例 #5
0
def test_mcp23008_multibyte_writes():
    with i2c.I2CBus() as bus:
        # Ensure sequential addressing mode is on
        write_register(bus, IOCON, 0x00)
        
        # Write two bytes, the IODIR register and, thanks to
        # sequential addressing mode, the next register, IOPOL
        bus.transaction(
            i2c.write_bytes(address, IODIR, 0xFF, 0xAA))
        
        iodir_state = read_register(bus, IODIR)
        iopol_state = read_register(bus, IOPOL)
        
        assert iodir_state == 0xFF
        assert iopol_state == 0xAA
コード例 #6
0
def test_mcp23008_multibyte_reads():
    with i2c.I2CBus() as bus:
        # Ensure sequential addressing mode is on
        write_register(bus, IOCON, 0x00)
        
        write_register(bus, IODIR, 0xFF)
        write_register(bus, IOPOL, 0xAA)
        
        # Read two bytes, the IODIR register and, thanks to sequential
        # addressing mode, the next register, IOPOL
        iodir_state, iopol_state = bus.transaction(
            i2c.write_bytes(address, IODIR),
            i2c.read(address, 2))[0]
    
        assert iodir_state == 0xFF
        assert iopol_state == 0xAA
コード例 #7
0
    def getadcreading(address, channel):
        try:
            bus.transaction(i2c.write_bytes(address, channel))
            time.sleep(0.05)
            h, l, r = bus.transaction(i2c.read(address, 3))[0]
            time.sleep(0.05)
            h, l, r = bus.transaction(i2c.read(address, 3))[0]

            t = (h << 8 | l)
            if (t >= 32768):
                t = 655361 - t
            #v = (t * 2.048/32768.0	)
            v = (t * 0.000154)
            return v
        except:
            print("getadcreading failed")
            return 0.00
コード例 #8
0
	def getadcreading(address, channel):
		try:
			bus.transaction(i2c.write_bytes(address, channel))
			time.sleep(0.05)
			h, l, r = bus.transaction(i2c.read(address,3))[0]
			time.sleep(0.05)
			h, l, r = bus.transaction(i2c.read(address,3))[0]
			
			t = (h << 8 | l)
			if (t >= 32768):
				t = 655361 -t
			#v = (t * 2.048/32768.0	)
			v = (t * 0.000154	)
			return v
		except:
			print ("getadcreading failed")	
			return 0.00	
コード例 #9
0
                                       '&waterbase=' + str(varTempBase) +
                                       '&solar=' + str(varTempCollector) +
                                       '&home=' + str(varTempHome) + '&Irms=' +
                                       str(varACAmps) + '&iSolar=' +
                                       str(varPVAmps) + '&vbattery=' +
                                       str(varDCVolts) + '&iInverter=' +
                                       str(varInverterAmps) + '&iDCLine=' +
                                       str(varDCAmps) + '&pump=' +
                                       str(varPumpRunning) + '')

            print(f.read(100))
        except:
            print("http connection failed")

    # init temp sensor
    bus.transaction(i2c.write_bytes(temphomeaddress, 0x01, 0x60))
    bus.transaction(i2c.write_bytes(temphomeaddress, 0x01))

    while True:

        # read sensors into temp variables
        varPumpRunning = calcPumpRunning(
            getadcreading(adc_address1, adc_channel1))
        varDCVolts = calcDCVolts(getadcreading(adc_address1, adc_channel2))
        varDCAmps = calcDCCurrent(getadcreading(adc_address2, adc_channel1))
        varACAmps = calcACCurrent(getadcreading(adc_address2, adc_channel2))
        varInverterAmps = calcInverterCurrent(
            getadcreading(adc_address2, adc_channel3))
        varPVAmps = calcSolarCurrent(getadcreading(adc_address2, adc_channel4))

        varTempHome = getI2CTemp()
コード例 #10
0
#	H & F = 0x6D
#	H & H = 0x6E
#	F & H = 0x6F

import quick2wire.i2c as i2c

import time
adc_address1 = 0x68
adc_address2 = 0x69

adc_channel1 = 0x98
adc_channel2 = 0xB8
adc_channel3 = 0xD8
adc_channel4 = 0xF8

with i2c.I2CBus() as bus:

    bus.transaction(i2c.write_bytes(adc_address1, adc_channel1))

    while True:
        h, l, r = bus.transaction(i2c.read(adc_address1, 3))[0]

        t = (h << 8 | l)
        if (t >= 32768):
            t = 655361 - t
        v = t * 2.048 / 32768.0

        print("%02f" % v)

        time.sleep(1)
コード例 #11
0
def read_register(bus, reg):
    return bus.transaction(
        i2c.write_bytes(address, reg),
        i2c.read(address, 1))[0][0]
コード例 #12
0
#!/usr/bin/env python3
import quick2wire.i2c as i2c

import time
# Basic test read script to read sensor data from I2C Microchip MCP9800/1/2/3 Temperature Sensor


address = 0x49

with i2c.I2CBus() as bus:
	bus.transaction(i2c.write_bytes(address, 0x01, 0x60))
	bus.transaction(i2c.write_bytes(address, 0x01))
	while True:
		

		sensora, sensorb = bus.transaction(i2c.write_bytes(address, 0x00),
		i2c.read(address, 2))[0]
		
		temp = (sensora << 8 | sensorb) / 256.
		
		print ("%02.02f" % temp)
		
		time.sleep(1)
コード例 #13
0
#	H & H = 0x6E
#	F & H = 0x6F

import quick2wire.i2c as i2c

import time
adc_address1 = 0x68
adc_address2 = 0x69

adc_channel1 = 0x98
adc_channel2 = 0xB8
adc_channel3 = 0xD8
adc_channel4 = 0xF8

with i2c.I2CBus() as bus:
	
	
	bus.transaction(i2c.write_bytes(adc_address1, adc_channel1))

	while True:
		h, l, r = bus.transaction(i2c.read(adc_address1,3))[0]
		
		t = (h << 8 | l)
		if (t >= 32768):
			t = 655361 -t
		v = t * 2.048/32768.0	

		print ("%02f" % v)
		
		time.sleep(1)
コード例 #14
0
def _toggle(pin, register):
    pinBitMask = 1 << pin
    with i2c.I2CBus() as bus:
        current = _read(bus, register)
        next = (current & ~pinBitMask) | (pinBitMask ^ current) & 0xff
        bus.transaction(i2c.write_bytes(address, register, next))
コード例 #15
0
def _read(bus, register):
    current = bus.transaction(
        i2c.write_bytes(address, register), i2c.read(address, 1))
    return current[0][0]
コード例 #16
0

class ToggleOlatHandler(tornado.web.RequestHandler):
    def get(self, pin):
        _toggle(int(pin), OLAT)
        _writeState(self)


class StatusHandler(tornado.web.RequestHandler):
    def get(self):
        _writeState(self)

application = tornado.web.Application([
    (r"/pins/([0-7])", ToggleStateHandler),
    (r"/iodir/([0-7])", ToggleDirectionHandler),
    (r"/gpinten/([0-7])", ToggleGpintenHandler),
    (r"/defval/([0-7])", ToggleDefvalHandler),
    (r"/intcon/([0-7])", ToggleIntconHandler),
    (r"/olat/([0-7])", ToggleOlatHandler),
    (r"/status", StatusHandler),
    (r"/", tornado.web.RedirectHandler, dict(url="/index.html")),
    (r"/(.*)", tornado.web.StaticFileHandler,
        dict(path=os.path.join(os.path.dirname(__file__), "www")))
])

if __name__ == "__main__":
    application.listen(8888)
    with i2c.I2CBus() as bus:
        bus.transaction(i2c.write_bytes(address, 0x4, 0xff))
    tornado.ioloop.IOLoop.instance().start()
コード例 #17
0
def write_register(bus, reg, b):
    bus.transaction(
        i2c.write_bytes(address, reg, b))
コード例 #18
0
			+ '&iDCLine=' + str(varDCAmps)
			+ '&pump=' + str(varPumpRunning)
			+ '')
		
			print (f.read(100))
		except:
			print ("http connection failed")	
		
		
		
		
		
		
				
	# init temp sensor
	bus.transaction(i2c.write_bytes(temphomeaddress, 0x01, 0x60))
	bus.transaction(i2c.write_bytes(temphomeaddress, 0x01))
	
	while True:
		
		# read sensors into temp variables
		varPumpRunning = calcPumpRunning(getadcreading(adc_address1, adc_channel1))
		varDCVolts = calcDCVolts(getadcreading(adc_address1, adc_channel2))
		varDCAmps = calcDCCurrent(getadcreading(adc_address2, adc_channel1))
		varACAmps = calcACCurrent(getadcreading(adc_address2, adc_channel2))
		varInverterAmps = calcInverterCurrent(getadcreading(adc_address2, adc_channel3))
		varPVAmps = calcSolarCurrent(getadcreading(adc_address2, adc_channel4))

		varTempHome = getI2CTemp()
		
		# read 1-Wire sensors and update values if not error value (85 + 3 caculation factor)