本文整理汇总了Python中quick2wire.i2c.writing_bytes函数的典型用法代码示例。如果您正苦于以下问题:Python writing_bytes函数的具体用法?Python writing_bytes怎么用?Python writing_bytes使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了writing_bytes函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: getFullLuminosity
def getFullLuminosity(self):
self.enable()
self.wait()
with i2c.I2CMaster(self.i2cbus) as bus:
read_results = bus.transaction(
i2c.writing_bytes(address, self.COMMAND_BIT | self.WORD_BIT | self.REGISTER_CHAN1_LOW ),
i2c.reading(address, 2),
i2c.writing_bytes(address, self.COMMAND_BIT | self.WORD_BIT | self.REGISTER_CHAN0_LOW ),
i2c.reading(address, 2)
)
self.disable()
full = read_results[0][1]
# print("---- full: %#08x" % full)
full = full << 8
full += read_results[0][0]
# print("---- full: %#08x" % full)
full = full << 8
full += read_results[1][1]
# print("---- full: %#08x" % full)
full = full << 8
full += read_results[1][0]
# print("---- full: %#08x" % full)
return full
示例2: initSensor
def initSensor(self):
""" initalizes the first channel if the MAX1164 device in single
endded mode with vdd as ref
"""
with i2c.I2CMaster(1) as bus:
bus.transaction(i2c.writing_bytes(self.address, 0x8a ))
bus.transaction(i2c.writing_bytes(self.address, 0x01 ))
示例3: getDate
def getDate():
# get date and return value
#get day
day, day2 = bus.transaction(
i2c.writing_bytes(rtc_address1, 0x05),
i2c.reading(rtc_address1,2))[0]
timeday1 = ((day >> 4) & 0x03)
timeday2 = (day & 0x0F)
#get month
month, month2 = bus.transaction(
i2c.writing_bytes(rtc_address1, 0x07),
i2c.reading(rtc_address1,2))[0]
timemonth1 = ((month >> 4) & 0x01)
timemonth2 = (month & 0x0F)
#get year
year, year2 = bus.transaction(
i2c.writing_bytes(rtc_address1, 0x08),
i2c.reading(rtc_address1,2))[0]
timeyear1 = ((year >> 4))
timeyear2 = (year & 0x0F)
return str(timeday1) + str(timeday2) + "/" + str(timemonth1) + str(timemonth2) + "/" + str(timeyear1) + str(timeyear2)
示例4: readAlarmTime
def readAlarmTime(month, year):
#---------
# minute
#--------
minute, minute2 = bus.transaction( i2c.writing_bytes(rtc_address1, 0x09),
i2c.reading(rtc_address1,2))[0]
timeminute1 = ((minute >> 4) & 0x07)
timeminute2 = (minute & 0x0F)
#------
# hour
#------
hour, hour2 = bus.transaction( i2c.writing_bytes(rtc_address1, 0x0A),
i2c.reading(rtc_address1,2))[0]
timehour1 = ((hour >> 4) & 0x03)
timehour2 = (hour & 0x0F)
#------
# Day
#-----
day, day2 = bus.transaction( i2c.writing_bytes(rtc_address1, 0x0B),
i2c.reading(rtc_address1,2))[0]
timeday1 = ((day >> 4) & 0x05)
timeday2 = (day & 0x0F)
alminute = int(str(timeminute1)+str(timeminute2))
alhour = int(str(timehour1)+str(timehour2))
alday = int(str(timeday1)+str(timeday2))
weekday,dayname = weekDay(year,month,alday)
return alminute, alhour, alday, weekday, dayname
示例5: set_IO_DIR
def set_IO_DIR(port_expand_addr, port, value):
with q2w_i2c.I2CMaster() as bus:
if port == 'A':
bus.transaction(
q2w_i2c.writing_bytes(port_expand_addr, IODIRA, value))
elif port == 'B':
bus.transaction(
q2w_i2c.writing_bytes(port_expand_addr, IODIRB, value))
示例6: write_data
def write_data(port_expand_addr, port, value):
with q2w_i2c.I2CMaster() as bus:
if port == 'A':
bus.transaction(
q2w_i2c.writing_bytes(port_expand_addr, GPIOA, value))
elif port == 'B':
bus.transaction(
q2w_i2c.writing_bytes(port_expand_addr, GPIOB, value))
示例7: readSensor
def readSensor() :
bus.transaction(i2c.writing_bytes(ADDR, 0x22, 0x20))
time.sleep(0.05)
readout = bus.transaction(i2c.writing_bytes(ADDR, 0xE0, 0x00), i2c.reading(ADDR, 6))
time.sleep(1.0)
return readout
示例8: set_IO_PULL_UP
def set_IO_PULL_UP(port_expand_addr, port, value):
with q2w_i2c.I2CMaster() as bus:
if port == 'A':
bus.transaction(
q2w_i2c.writing_bytes(port_expand_addr, GPPUA, value))
elif port == 'B':
bus.transaction(
q2w_i2c.writing_bytes(port_expand_addr, GPPUB, value))
示例9: read_data
def read_data(port_expand_addr, port):
with q2w_i2c.I2CMaster() as bus:
if port == 'A':
return bus.transaction(
q2w_i2c.writing_bytes(port_expand_addr, GPIOA),
q2w_i2c.reading(port_expand_addr, 1))[0][0]
elif port == 'B':
return bus.transaction(
q2w_i2c.writing_bytes(port_expand_addr, GPIOB),
q2w_i2c.reading(port_expand_addr, 1))[0][0]
示例10: write_cgchar
def write_cgchar(self, pos, data):
cgaddr = pos & 0x07
cgaddr = (cgaddr << 3) | 0x40
time.sleep(0.1)
self.bus.transaction(i2c.writing_bytes(self.address, 0x00, 0x38)) # Function Set, 8bit, 2lines, NoDoubleHeight, InstructionTable=0
time.sleep(0.1)
self.bus.transaction(i2c.writing_bytes(self.address, 0x00, cgaddr)) # select CGRAM address
time.sleep(0.1)
for datum in data:
self.bus.transaction(i2c.writing_bytes(self.address, 0x40, datum)) # Write data, byte by byte (normally 8)
self.bus.transaction(i2c.writing_bytes(self.address, 0x00, 0x80)) # return to DDRAM
示例11: write
def write(self, register, value):
log.debug("Writing to address {0:#4X} register 0x{1:#4X} value {2:#10b}".format(self.ADDRESS, register, value))
if self.TOGGLE_MODE:
a = value & 0b11111111
b = (value >> 8) & 0b11111111
BUS.transaction(
i2c.writing_bytes(self.ADDRESS, register, a, b),
)
else:
BUS.transaction(
i2c.writing_bytes(self.ADDRESS, register ,value),
)
示例12: bank_mode
def bank_mode(self, bank):
self.BANK = bank
log.info("Bank set to {0:d}".format(bank))
#EVERYTHING else goes to zero - some magic to write bit on both settings
if self.BANK == 1: #assume has been bank=0 before
BUS.transaction(
i2c.writing_bytes(self.ADDRESS,0x15, IOCON['BANK']),
i2c.writing_bytes(self.ADDRESS,0x0A, IOCON['BANK']))
elif self.BANK == 0:
BUS.transaction(
i2c.writing_bytes(self.ADDRESS,0x15, 0 ),
i2c.writing_bytes(self.ADDRESS,0x0A, 0 ))
示例13: resetAlarm
def resetAlarm():
#-----------------------
# Clear status register
#-----------------------
bus.transaction(i2c.writing_bytes(rtc_address1, 0x01, 0x00))
#-----------------------
# Clear alarm registers
#-----------------------
bus.transaction(i2c.writing_bytes(rtc_address1, 0x09, 0x00))
bus.transaction(i2c.writing_bytes(rtc_address1, 0x0A, 0x00))
bus.transaction(i2c.writing_bytes(rtc_address1, 0x0B, 0x00))
bus.transaction(i2c.writing_bytes(rtc_address1, 0x0C, 0x00))
示例14: __readADC
def __readADC(self):
command = 0x00
#Read D1
self.bus.transaction(i2c.writing_bytes(self.address, 0x48))
time.sleep(0.01)
values = self.bus.transaction(i2c.writing_bytes(self.address, command), i2c.reading(self.address, 3))
self.D[1] = (values[0][0] << 16) | (values[0][1] << 8) | (values[0][2])
self.logger.debug("CMD(" + "{0:#04x}".format(command) + ") -> D1 = " + str(self.D[1]))
# Read D2
self.bus.transaction(i2c.writing_bytes(self.address, 0x58))
time.sleep(0.01)
values = self.bus.transaction(i2c.writing_bytes(self.address, command), i2c.reading(self.address, 3))
self.D[2] = (values[0][0] << 16) | (values[0][1] << 8) | (values[0][2])
self.logger.debug("CMD(" + "{0:#04x}".format(command) + ") -> D2 = " + str(self.D[2]))
示例15: getadcreading
def getadcreading(address, channel, gain, res):
channel = channel - 1
adcConfig = MCP342X_START | MCP342X_CHANNEL_1 | MCP342X_CONTINUOUS
adcConfig |= channel << 5 | res << 2 | gain
#print("adcConfig")
#print(adcConfig)
varDivisior = 1 << (gain + 2*res)
bus.transaction(i2c.writing_bytes(address, adcConfig))
time.sleep(0.05)
if (res ==3):
h, m, l ,s = bus.transaction(i2c.reading(address,4))[0]
time.sleep(0.05)
h, m, l, s = bus.transaction(i2c.reading(address,4))[0]
t = ((h & 0b00000001) << 16) | (m << 8) | l
else:
h, m, l = bus.transaction(i2c.reading(address,3))[0]
time.sleep(0.05)
h, m, l = bus.transaction(i2c.reading(address,3))[0]
t = (h << 8) | m
if (h > 128):
t = ~(0x020000 - t)
# remove / 1000 to return value in milivolts
return ((t/varDivisior) * 2.4705882) / 1000