当前位置: 首页>>代码示例>>Python>>正文


Python pyb.UART类代码示例

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


在下文中一共展示了UART类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: uart_hash

def  uart_hash():
	#  initialize UART(6) to output TX on Pin Y1
	uart = UART(6)
	while True:
		uart.init(9600, bits=8, parity = 0, stop = 2)
		uart.writechar(ord('#'))		# letter '#'
		pyb.delay(5)					# delay by 5ms
开发者ID:old-blighty,项目名称:de1-electonics-group-project,代码行数:7,代码来源:full.py

示例2: lcd

class lcd():
    def __init__(self,uart=3):
        #UART serial
        self.lcd = UART(uart, 115200)  # init with given baudrate

        #set lcd to same baudrate
        b = bytearray(3)
        b[0] = 0x7C
        b[1] = 0x07
        b[2] = 0x36
        self.lcd.write(b)

        #set background duty
        b = bytearray(3)
        b[0] = 0x7C
        b[1] = 0x02
        b[2] = 80
        self.lcd.write(b)

    def clear(self):
        b = bytearray(2)
        b[0] = 0x7c
        b[1] = 0x00
        self.lcd.write(b)

    def send(self,string):
        self.lcd.write(string)

    def replace(self,string):
        self.clear()
        self.lcd.write(string)
开发者ID:B3AU,项目名称:micropython,代码行数:31,代码来源:lcd.py

示例3: init

def init():
	print ("Initializing")

	# Initialize GPS
	# UART(1) is on PB: 
	# (TX,  RX) 
	# (X9,  X10)
	# (PB6, PB7)
	uart = UART(1, 9600)
	# Maybe add read_buf_len=128?
	# Maybe add timeout_char=200
	uart.init(9600, bits=8, stop=1, parity=None, timeout=5000)


	# Initialize Radio (RFM69)
	# SPI(1) is on PA:
	# (DIO0, RESET, NSS, SCK, MISO, MOSI) 
	# (X3,   X4,    X5,  X6,  X7,   X8) 
	# (PA2,  PA3,   PA4, PA5, PA6,  PA7)
	rfm69 = RFM69.RFM69()
	sleep(1)
	# Check version
	if (rfm69.getVersion() == 0x24):
		print ("RFM69 Version Valid: 0x24")
	else:
		print ("RFM69 Version Invalid!")
		return "FAULT"

	return "GPS_ACQ"
开发者ID:arkorobotics,项目名称:PyHAB,代码行数:29,代码来源:PyHAB.py

示例4: MTC

class MTC():

  def __init__(self):
      self.clock = {'frames':0, 'seconds':0, 'mins':0, 'hours':0, 'mode':0}
      self.frame_count = 1
      self.uart1 = UART(1)

      self.message = [-1] * 8
      self.uart1.init(31250, parity=None, stop=1,read_buf_len=1)
      print(dir(self.uart1))

  def saveClock(self):
      self.clock['frames'] = (self.message[1] << 4) + self.message[0] # 2 half bytes 000f ffff
      self.clock['seconds'] = (self.message[3] << 4) + self.message[2] # 2 half bytes 00ss ssss
      self.clock['mins'] =  (self.message[5] << 4) + self.message[4] # 2 half bytes 00mm mmmm
      self.clock['hours'] = ((self.message[7] & 1) << 4) + self.message[6] # 2 half bytes 0rrh hhhh the msb has to be masked as it contains the mode
      self.clock['mode'] = ((self.message[7] & 6) >> 1) # get the fps mode by masking 0rrh with 0110 (6)

  def getMs(self):

      self.readFrame()
      mins = ((self.clock['hours'] * 60) + self.clock['mins'])
      seconds = (mins * 60) + self.clock['seconds']
      frames = (seconds * 25) + self.clock['frames']
      milliseconds = frames * 40
      return milliseconds

  def readFrame(self):


      indice = 0
      self.message = [-1] * 8

      while True:

          data = self.uart1.read(1)

          if data != None:

              if ord(data) == 241:              # if Byte for quater frame message

                  try: mes = ord(self.uart1.read(1))        # Read next byte
                  except: continue

                  piece = mes >> 4             # Get which part of the message it is (e.g seconds mins)

                  if piece == indice:
                      self.message[piece] = mes & 15    # store message using '&' to mask the bit type
                      indice += 1

          if indice > 7:
              self.saveClock()
              break

      #self.uart1.deinit()
      return self.clock
开发者ID:clacktronics,项目名称:MTC-system,代码行数:56,代码来源:MTC.py

示例5: ESP8266

class ESP8266(object):

    def __init__(self):
        self.uart = UART(6, 115200)
    
    def write(self, command):
        self.uart.write(command)
        count = 5
        while count >= 0:
            if self.uart.any():
                print(self.uart.readall().decode('utf-8'))
            time.sleep(0.1)
            count-=1
开发者ID:hiroki8080,项目名称:micropython,代码行数:13,代码来源:esp8266.py

示例6: __init__

class UART_Port:
    """Implements a port which can send or receive commands with a bioloid
    device using the pyboard UART class. This particular class takes
    advantage of some features which are only available on the STM32F4xx processors.
    """

    def __init__(self, uart_num, baud):
        self.uart = UART(uart_num)
        self.baud = 0
        self.set_baud(baud)
        base_str = 'USART{}'.format(uart_num)
        if not hasattr(stm, base_str):
            base_str = 'UART{}'.format(uart_num)
        self.uart_base = getattr(stm, base_str)

        # Set HDSEL (bit 3) in CR3 - which puts the UART in half-duplex
        # mode. This connects Rx to Tx internally, and only enables the
        # transmitter when there is data to send.
        stm.mem16[self.uart_base + stm.USART_CR3] |= (1 << 3)

    def any(self):
        return self.uart.any()

    def read_byte(self):
        """Reads a byte from the bus.

        This function will return None if no character was read within the
        designated timeout (set when we call self.uart.init).
        """
        byte = self.uart.readchar()
        if byte >= 0:
            return byte

    def set_baud(self, baud):
        """Sets the baud rate.

        Note, the pyb.UART class doesn't have a method for setting the baud
        rate, so we need to reinitialize the uart object.
        """
        if self.baud != baud:
            self.baud = baud
            # The max Return Delay Time is 254 * 2 usec = 508 usec. The default
            # is 500 usec. So using a timeout of 2 ensures that we wait for
            # at least 1 msec before considering a timeout.
            self.uart.init(baudrate=baud, timeout=2)

    def write_packet(self, packet_data):
        """Writes an entire packet to the serial port."""
        _write_packet(self.uart_base, packet_data, len(packet_data))
开发者ID:dhylands,项目名称:bioloid3,代码行数:49,代码来源:stm_uart_port.py

示例7: __init__

    def __init__(self, uart_port):
        self.sbus = UART(uart_port, 100000)
        self.sbus.init(100000, bits=8, parity=0, stop=2, timeout_char=3, read_buf_len=250)

        # constants
        self.START_BYTE = b'0f'
        self.END_BYTE = b'00'
        self.SBUS_FRAME_LEN = 25
        self.SBUS_NUM_CHAN = 18
        self.OUT_OF_SYNC_THD = 10
        self.SBUS_NUM_CHANNELS = 18
        self.SBUS_SIGNAL_OK = 0
        self.SBUS_SIGNAL_LOST = 1
        self.SBUS_SIGNAL_FAILSAFE = 2

        # Stack Variables initialization
        self.validSbusFrame = 0
        self.lostSbusFrame = 0
        self.frameIndex = 0
        self.resyncEvent = 0
        self.outOfSyncCounter = 0
        self.sbusBuff = bytearray(1)  # single byte used for sync
        self.sbusFrame = bytearray(25)  # single SBUS Frame
        self.sbusChannels = array.array('H', [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0])  # RC Channels
        self.isSync = False
        self.startByteFound = False
        self.failSafeStatus = self.SBUS_SIGNAL_FAILSAFE
开发者ID:Sokrates80,项目名称:sbus_driver_micropython,代码行数:27,代码来源:sbus_receiver.py

示例8: __init__

  def __init__(self):
      self.clock = {'frames':0, 'seconds':0, 'mins':0, 'hours':0, 'mode':0}
      self.frame_count = 1
      self.uart1 = UART(1)

      self.message = [-1] * 8
      self.uart1.init(31250, parity=None, stop=1,read_buf_len=1)
      print(dir(self.uart1))
开发者ID:clacktronics,项目名称:MTC-system,代码行数:8,代码来源:MTC.py

示例9: __init__

 def __init__(self, uart_num, pin_rw, dev_id):
     self.error = []
     self.uart = UART(uart_num)
     self.uart.init(57600, bits=8, parity=0, timeout=10, read_buf_len=64)
     self.pin_rw = Pin(pin_rw)
     self.pin_rw.init(Pin.OUT_PP)
     self.pin_rw.value(0)
     self.dev_id = dev_id
     
     self.file_parts = 0
     self.file_parts_i = 1
     self.file_is_open = False
开发者ID:SolitonNew,项目名称:pyhome,代码行数:12,代码来源:rs485.py

示例10: init

 def init(self, type=BLE_SHIELD):
     self.deinit()
     if type==self.BLE_SHIELD:
         self.rst=Pin("P7",Pin.OUT_OD,Pin.PULL_NONE)
         self.uart=UART(3,115200,timeout_char=1000)
         self.type=self.BLE_SHIELD
         self.rst.low()
         sleep(100)
         self.rst.high()
         sleep(100)
         self.uart.write("set sy c m machine\r\nsave\r\nreboot\r\n")
         sleep(1000)
         self.uart.readall() # clear
开发者ID:Killercotton,项目名称:OpenMV_medialab,代码行数:13,代码来源:ble.py

示例11: uart_hashtag

def  uart_hashtag():
	the_word = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789'
	#  initialize X5 as  trigger output
	uart = UART(6)
	uart.init(9600, bits=8, parity = None, stop = 2)
	while True:
	#  initialize UART(6) to output TX on Pin Y1
		for i in range(36):
			uart.writechar(ord(the_word[i]))
		uart.writechar(13)
		uart.writechar(10)
		pyb.delay(1000)
开发者ID:old-blighty,项目名称:de1-electonics-group-project,代码行数:12,代码来源:full.py

示例12: __init__

    def __init__(self,uart=3):
        #UART serial
        self.lcd = UART(uart, 115200)  # init with given baudrate

        #set lcd to same baudrate
        b = bytearray(3)
        b[0] = 0x7C
        b[1] = 0x07
        b[2] = 0x36
        self.lcd.write(b)

        #set background duty
        b = bytearray(3)
        b[0] = 0x7C
        b[1] = 0x02
        b[2] = 80
        self.lcd.write(b)
开发者ID:B3AU,项目名称:micropython,代码行数:17,代码来源:lcd.py

示例13: __init__

class WIFI:
  """docstring for wifi"""

  def __init__(self, uart, baudrate = 115200):
    """ uart = uart #1-6, baudrate must match what is set on the ESP8266. """
    self._uart = UART(uart, baudrate)

  def write( self, aMsg ) :
    self._uart.write(aMsg)
    res = self._uart.readall()
    if res:
      print(res.decode("utf-8"))

  def read( self ) : return self._uart.readall().decode("utf-8")

  def _cmd( self, cmd ) :
    """ Send AT command, wait a bit then return results. """
    self._uart.write("AT+" + cmd + "\r\n")
    udelay(500)
    return self.read()

  @property
  def IP(self): return self._cmd("CIFSR")

  @property
  def networks( self ) : return self._cmd("CWLAP")

  @property
  def baudrate(self): return self._cmd("CIOBAUD?")

  @baudrate.setter
  def baudrate(self, value): return self._cmd("CIOBAUD=" + str(value))

  @property
  def mode(self): return self._cmd("CWMODE?")

  @mode.setter
  def mode(self, value): self._cmd("CWMODE=" + str(value))

  def connect( self, ssid, password = "" ) :
    """ Connect to the given network ssid with the given password """
    constr = "CWJAP=\"" + ssid + "\",\"" + password + "\""
    return self._cmd(constr)

  def disconnect( self ) : return self._cmd("CWQAP")

  def reset( self ) : return self._cmd("RST")
开发者ID:rolandvs,项目名称:GuyCarverMicroPythonCode,代码行数:47,代码来源:ESP8266.py

示例14: remote

def  remote():

	#initialise UART communication
	uart = UART(6)
	uart.init(9600, bits=8, parity = None, stop = 2)

	# define various I/O pins for ADC
	adc_1 = ADC(Pin('X19'))
	adc_2 = ADC(Pin('X20'))

	# set up motor with PWM and timer control
	A1 = Pin('Y9',Pin.OUT_PP)
	A2 = Pin('Y10',Pin.OUT_PP)
	pwm_out = Pin('X1')
	tim = Timer(2, freq = 1000)
	motor = tim.channel(1, Timer.PWM, pin = pwm_out)

	# Motor in idle state
	A1.high()	
	A2.high()	
	speed = 0
	DEADZONE = 5

	# Use keypad U and D keys to control speed
	while True:				# loop forever until CTRL-C
		while (uart.any()!=10):    #wait we get 10 chars
			n = uart.any()
		command = uart.read(10)
		if command[2]==ord('5'):
			if speed < 96:
				speed = speed + 5
				print(speed)
		elif command[2]==ord('6'):
			if speed > - 96:
				speed = speed - 5
				print(speed)
		if (speed >= DEADZONE):		# forward
			A1.high()
			A2.low()
			motor.pulse_width_percent(speed)
		elif (speed <= -DEADZONE):
			A1.low()		# backward
			A2.high()
			motor.pulse_width_percent(-speed)
		else:
			A1.low()		# idle
			A2.low()		
开发者ID:old-blighty,项目名称:de1-electonics-group-project,代码行数:47,代码来源:full.py

示例15: keypad

def  keypad():
	key = ('1','2','3','4','U','D','L','R')
	uart = UART(6)
	uart.init(9600, bits=8, parity = None, stop = 2)
	while True:
		while (uart.any()!=10):    #wait we get 10 chars
			n = uart.any()
		command = uart.read(10)
		key_index = command[2]-ord('1')
		if (0 <= key_index <= 7) :
			key_press = key[key_index]
		if command[3]==ord('1'):
			action = 'pressed'
		elif command[3]==ord('0'):
			action = 'released'
		else:
			action = 'nothing pressed'
		print('Key',key_press,' ',action)
开发者ID:old-blighty,项目名称:de1-electonics-group-project,代码行数:18,代码来源:full.py


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