Пример #1
0
def read(source, count):
    with i2c.I2CMaster() as bus:
        print("reading %d bytes from %02x" % (count, source))
        result = bus.transaction(i2c.writing_bytes(I2C_SLAVE_ADDRESS, source),
                                 i2c.reading(I2C_SLAVE_ADDRESS, count))

        return result[0]
Пример #2
0
 def update(self):
     self.update_i2c_buffer()
     length = bytearray(1)
     length[0] = 23 + 1
     with i2c.I2CMaster() as bus:
         bus.transaction(
             i2c.writing_bytes(self.i2c_address, 0x00),
             i2c.writing(self.i2c_address, self.i2c_buffer[0:23] + length))
def read(source, count):
	with i2c.I2CMaster() as bus:
		print("reading %d bytes from %02x" % (count, source))
		result = bus.transaction(
			i2c.writing_bytes(I2C_SLAVE_ADDRESS, source),
			i2c.reading(I2C_SLAVE_ADDRESS, count))

		return result[0]
	def update(self):
		self.update_i2c_buffer()
		length = bytearray(1)
		length[0] = 23 + 1
		with i2c.I2CMaster() as bus:
			bus.transaction(
				i2c.writing_bytes(self.i2c_address, 0x00),
				i2c.writing(self.i2c_address, self.i2c_buffer[0:23] + length))
Пример #5
0
    def scan_i2c_bus(self):
        '''
		scan a range of the I2C bus in order to find new RGBControllers,
		skip known addresses,
		add newly found RGBControllers to the local list
		'''
        controllers = []
        for addr in range(5, 127, 1):
            if addr not in self.controllers.keys():
                try:
                    with i2c.I2CMaster() as bus:
                        bus.transaction(i2c.writing_bytes(addr, 0x00))
                    controllers.append(addr)
                except Exception as e:
                    None
                    # no controller for this address
        for addr in controllers:
            self.controllers[addr] = RgbController(addr,
                                                   "Controller" + str(addr))
        pprint(controllers)
	def scan_i2c_bus(self):
		'''
		scan a range of the I2C bus in order to find new RGBControllers,
		skip known addresses,
		add newly found RGBControllers to the local list
		'''
		controllers = []
		for addr in range(5, 127, 1):
			if addr not in self.controllers.keys():
				try:
					with i2c.I2CMaster() as bus:
						bus.transaction(
							i2c.writing_bytes(addr, 0x00))
					controllers.append(addr)
				except Exception as e:
					None
					# no controller for this address
		for addr in controllers:
			self.controllers[addr] = RgbController(addr, "Controller"+str(addr))
		pprint(controllers)
Пример #7
0
def i2c_write(data):
    i2cm.transaction(i2c.writing_bytes(SW_ADDR, *data))
Пример #8
0
 def i2c_write(self, data):
     self.i2c.transaction(i2c.writing_bytes(SW_ADDR, *data))
Пример #9
0
def i2c_write(data):
    i2cm.transaction(i2c.writing_bytes(SW_ADDR, *data))
Пример #10
0
#!/usr/bin/env python3
import i2c as i2c
import time

address = 0x28
# 0x28 = bin0101000 = dec40
# DF command = 7 bit slave address + 0 = 0x28 = dec40
# MR command = 7 bit slave address + 1 = 0x29 = dec41

with i2c.I2CMaster() as bus:
	
	print ("send MR command")
	bus.transaction(i2c.writing_bytes(address, 0x29, 0x00))
	time.sleep(0.2)
	print ("send DF command and read 4 bytes")
	read_b1 = bus.transaction(
		i2c.writing_bytes(address, 0x28),
		i2c.reading(address, 1))
	print ("Bye 1: %d" % read_b1[0][0])
	read_b2 = bus.transaction(
		i2c.writing_bytes(address, 0x28),
		i2c.reading(address, 2))
	print ("Bye 2: %d" % read_b2[0][1])
	read_b3 = bus.transaction(
		i2c.writing_bytes(address, 0x28),
		i2c.reading(address, 3))
	print ("Bye 3: %d" % read_b3[0][2])
	read_b4 = bus.transaction(
		i2c.writing_bytes(address, 0x28),
		i2c.reading(address, 4))
	print ("Bye 4: %d" % read_b4[0][3])
Пример #11
0
 def i2c_write(self, data):
   self.i2c.transaction(i2c.writing_bytes(SW_ADDR, *data))