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
Ejemplo n.º 2
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
Ejemplo n.º 3
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
	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	
	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	
Ejemplo n.º 6
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
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
Ejemplo n.º 8
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)
def read_register(bus, reg):
    return bus.transaction(
        i2c.write_bytes(address, reg),
        i2c.read(address, 1))[0][0]
Ejemplo n.º 10
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)
#	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)
Ejemplo n.º 12
0
def _read(bus, register):
    current = bus.transaction(
        i2c.write_bytes(address, register), i2c.read(address, 1))
    return current[0][0]