• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Python i2c.reading函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Python中quick2wire.i2c.reading函数的典型用法代码示例。如果您正苦于以下问题:Python reading函数的具体用法?Python reading怎么用?Python reading使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



在下文中一共展示了reading函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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
开发者ID:cznewt,项目名称:TSL2561,代码行数:27,代码来源:TSL2561.py


示例2: 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
开发者ID:argn,项目名称:AlarmPi,代码行数:35,代码来源:setalarm.py


示例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)
开发者ID:abelectronicsuk,项目名称:AlarmPi,代码行数:25,代码来源:wakeup.py


示例4: 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
开发者ID:sonite,项目名称:abelectronics,代码行数:30,代码来源:adcpiv2.py


示例5: getadcreading

def getadcreading(address, adcConfig, res):
    bus.transaction(i2c.writing_bytes(address, adcConfig))
    if res == 0:
        h, m, l, s = bus.transaction(i2c.reading(address, 4))[0]
        while s & 128:
            h, m, l, s = bus.transaction(i2c.reading(address, 4))[0]
        # shift bits to product result
        t = ((h & 0b00000001) << 16) | (m << 8) | l
        # check if positive or negative number and invert if needed
        if h > 128:
            t = ~(0x020000 - t)
        return t / 64000
    else:
        m, l, s = bus.transaction(i2c.reading(address, 3))[0]
        while s & 128:
            m, l, s = bus.transaction(i2c.reading(address, 3))[0]
        # shift bits to product result
        t = (m << 8) | l
        # check if positive or negative number and invert if needed
        if m > 128:
            t = ~(0x02000 - t)
        if res == 4:
            return t / 16000
        if res == 8:
            return t / 4000
        if res == 12:
            return t / 1000
开发者ID:richtoy,项目名称:RPi_Wobbulator,代码行数:27,代码来源:rpi_wobbulator.py


示例6: read_raw

 def read_raw(self, channel):
     if channel != self._last_channel_read:
         self.master.transaction(writing_bytes(self.address, self._control_flags|channel),
                                 reading(self.address, 2))
         self._last_channel_read = channel
     
     results = self.master.transaction(
         reading(self.address, 2))
     return results[0][-1]
开发者ID:rhorenov,项目名称:quick2wire-python-api-py27,代码行数:9,代码来源:pcf8591.py


示例7: getadcreading

	def getadcreading(address):
		h, l ,s = bus.transaction(i2c.reading(address,3))[0]
		while (s & 128):
			h, l, s  = bus.transaction(i2c.reading(address,3))[0]
		# shift bits to product result
		t = (h << 8) | l
		# check if positive or negative number and invert if needed
		if (h > 128):
			t = ~(0x020000 - t)
		return t * varMultiplier
开发者ID:cpyarger,项目名称:adc2socket,代码行数:10,代码来源:chris.py


示例8: 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]
开发者ID:TwitALU,项目名称:Twitalu,代码行数:10,代码来源:twitalu_I2C.py


示例9: getadcreading

 def getadcreading(address):
     h, m, l, s = bus.transaction(i2c.reading(address, 4))[0]
     while s & 128:
         h, m, l, s = bus.transaction(i2c.reading(address, 4))[0]
         # shift bits to product result
     t = ((h & 0b00000001) << 16) | (m << 8) | l
     # check if positive or negative number and invert if needed
     if h > 128:
         t = ~(0x020000 - t)
     return t * varMultiplier
开发者ID:rstaehli,项目名称:soundLevelMeter,代码行数:10,代码来源:soundLevelMeter.py


示例10: getadcreading

	def getadcreading(address, channel):
		bus.transaction(i2c.writing_bytes(address, channel))
		time.sleep(0.001)
		h, l, r = bus.transaction(i2c.reading(address,3))[0]
		time.sleep(0.001)
		h, l, r = bus.transaction(i2c.reading(address,3))[0]
		
		t = (h << 8 | l)
		if (t >= 32768):
			t = 65536 -t
		v = (t * 0.000154	)
		if (v < 5.5):
			return v
		return 0.00
开发者ID:Beatlor,项目名称:adcpi,代码行数:14,代码来源:adcpi-read-inputs.py


示例11: __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])) 
开发者ID:mrmarkgray,项目名称:haldane,代码行数:14,代码来源:sensor.py


示例12: get_resolutions

 def get_resolutions(self):
     user_reg = self.bus.transaction(
         i2c.writing_bytes(self.ADDR, self.CMD_READ_USER_REG),
         i2c.reading(self.ADDR, 1),
     )
     user_reg_int = int.from_bytes(user_reg[0], byteorder="big")
     return self.RESOLUTIONS[user_reg_int >> 6, user_reg_int & 0x1]
开发者ID:1self,项目名称:quick2wire-HTU21D,代码行数:7,代码来源:htu21d.py


示例13: select_mifare

	def select_mifare(self):
		with I2CMaster() as master:
			# select mifare card
			# <len> <cmd> 
			master.transaction(writing_bytes(ADDRESS, 1, CMD_SELECT_MIFARE))
			time.sleep(WR_RD_DELAY)

			# read the response
			responses = master.transaction(reading(ADDRESS, 15))
			response = responses[0]
			# <len> <cmd> <status> <UUID> <type>
			len    = response[0]
			cmd    = response[1]
			status = response[2]

			if (status != 0x00):
				self.uid  = None
				self.type = None
				return False 

			# uid length varies on type, and type is after uuid
			uid       = response[3:len]
			type      = response[len]
			self.type = type
			self.uid  = uid
			return True
开发者ID:callanwhite,项目名称:pyRFID,代码行数:26,代码来源:rfid.py


示例14: read_response

    def read_response(self):
        """Wait, then read for a response from the PN532."""
        logging.debug("readResponse...")
        response = [b'\x00\x00\x00\x00\x00\x00\x00']

        while True:

            try:
                logging.debug("readResponse..............Reading.")

                sleep(DEFAULT_DELAY)
                response = self.PN532.transaction(
                    reading(self.address, 255))
                logging.debug(response)
                logging.debug("readResponse..............Read.")
            except Exception:
                pass
            else:
                try:
                    frame = Pn532Frame.from_response(response)

                    # Acknowledge Data frames coming from the PN532
                    if frame.get_frame_type() == PN532_FRAME_TYPE_DATA:
                        self.send_command(Pn532Frame(
                            frame_type=PN532_FRAME_TYPE_ACK))

                except Exception as ex:
                    logging.debug(ex)
                    logging.debug(ex.args)
                    pass
                else:
                    return frame
开发者ID:mheathfield,项目名称:nfc-login,代码行数:32,代码来源:nfc2.py


示例15: getReady

 def getReady(self):

   readyFlag = 0 
   i = False
   attempt = 0
   results=[]
   standbyFlag = 0
   sys.stdout.flush()
   time.sleep(0.1) 
   print("Getting ready ", end ="")
   while (i==False):
     results = self.bus.transaction(
       reading(self.add, 5)
     )

     readyFlag = 1 if (results[0][0]&0x80)==128 else 0
     standbyFlag = 1 if (results[0][3]&0x40)!=319 else 0
   
     sys.stdout.flush()
     time.sleep(0.1)
     print(".", end = "")
     i=standbyFlag*readyFlag
     attempt+=1
     if(attempt>20):
       break
     time.sleep(0.2)
 
   if(i==True):
     print("Ready! (",attempt,")")
     return True
# print("Raw output ", results[0])
   else:
     self.i2c.read_byte(self.add)
     print("Not ready! (", attempt, ")")
     return False
开发者ID:chinshou,项目名称:tea5767,代码行数:35,代码来源:tea5767stationscanner.py


示例16: getLevel

 def getLevel(self):
   level = 0
   results = self.bus.transaction(
     reading(self.add, 5)
   )
   level = results[0][3]>>4
   return level
开发者ID:chinshou,项目名称:tea5767,代码行数:7,代码来源:tea5767stationscanner.py


示例17: scan

 def scan(self,direction):
   i=False
   self.freq = self.getFreq()
   fadd = 0
   while (i==False):
     if(direction==1):
       fadd+=0.05
     else:
       fadd-=0.05
     self.freq = self.getFreq() #round((self.calculateFrequency()+self.getFreq())/2,2)
     if(self.freq<87.5):
       self.freq=108
     elif(self.freq>108):
       self.freq=87.5
     self.writeFrequency(self.freq+fadd,1) 
     time.sleep(0.1)
     results = self.bus.transaction(
       reading(self.add, 5)
     )

     readyFlag = 1 if (results[0][0]&0x80)==128 else 0
     level = results[0][3]>>4
     #print(results[0][0]&0x80 , " " , results[0][3]>>4)
     if(readyFlag and level>9):
       i=True
       print("Frequency tuned: ",self.calculateFrequency(), "FM (Strong Signal: ",level,")")

     else:
       i=False
       print("Station skipped: ",self.calculateFrequency(), "FM (Weak Signal: ",level,")")

   self.writeFrequency(self.calculateFrequency(),0)
开发者ID:chinshou,项目名称:tea5767,代码行数:32,代码来源:radio-smbus-tea5767-class.py


示例18: getReady

 def getReady(self):

   readyFlag = 0 
   i = False
   attempt = 0
   results=[]
   standbyFlag = 0
   sys.stdout.flush()
   time.sleep(0.1) 
   print("Getting ready ", end ="")
   while (i==False):
     results = self.bus.transaction(
       reading(self.add, 5)
     )

     readyFlag = 1 if (results[0][0]&0x80)==128 else 0
     standbyFlag = 1 if (results[0][3]+0x40)!=319 else 0
   
   #print("result search mode:" , results[0][0]+0x40)
   #s = results[0][3]+0x40
     sys.stdout.flush()
     time.sleep(0.9)
     print(".", end = "")
#   print("Soft mute ", results[0][3]&0x08)
   #print(results[0][3]+0x40)
     i=standbyFlag*readyFlag
     attempt+=1
     if(attempt>10):
       break
   if(i==True):
     print("Ready! (",attempt,")")
# print("Raw output ", results[0])
   else:
     self.i2c.read_byte(self.add)
     print("Not ready!")
开发者ID:chinshou,项目名称:tea5767,代码行数:35,代码来源:radio-smbus-tea5767-class.py


示例19: read_card

    def read_card(self):
        logging.info("Fetching card id from %0X" % self.i2c_address)
        # Fetch the card ID by sending 1/1 to the SL030 card reader
        with i2c.I2CMaster() as bus:
            bus.transaction(
                i2c.writing_bytes(0x50, 0x1, 0x1))
            time.sleep(0.1)      # SL030 requires this time to respond reliably
            read_results = bus.transaction(
                i2c.reading(0x50, 10))

        returned_len = read_results[0][0]
        status = read_results[0][2]

        if returned_len == 0:
            logging.info("Error fetching from card reader")
            return(None)

        if status == 0x1:       # No Tag
            logging.info("No tag detected")
            return(None)
        else:
            # Format the read card ID as a hex string
            card_as_hex = []
            for x in range(3, returned_len):
                card_as_hex.append('{1:02x}'.format(x,
                        read_results[0][x]).upper())
            logging.debug("Card presented: " % card_as_hex)
            return(''.join(card_as_hex))
开发者ID:jorgmota,项目名称:raspberry-pi-access-control-system,代码行数:28,代码来源:strong_link_sl030_reader.py


示例20: getadcreading

	def getadcreading(address, adcConfig):
		# Select port to read
		bus.transaction(i2c.writing_bytes(address, adcConfig))
	
		# 18 bit mode
		h, m, l ,s = bus.transaction(i2c.reading(address,4))[0]
		while (s & 128):
			h, m, l, s  = bus.transaction(i2c.reading(address,4))[0]
		# shift bits to product result
		t = ((h & 0b00000001) << 16) | (m << 8) | l
		
		# check if positive or negative number and invert if needed
		if (h > 128):
			t = ~(0x020000 - t)
		# return result 	
		return (t/varDivisior)
开发者ID:JohnMcLear,项目名称:deltasigmapi,代码行数:16,代码来源:deltasigmapi.py



注:本文中的quick2wire.i2c.reading函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Python i2c.writing_bytes函数代码示例发布时间:2022-05-26
下一篇:
Python GenomeInfo.GenomeInfo类代码示例发布时间:2022-05-26
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap