本文整理汇总了Python中pyb.UART.init方法的典型用法代码示例。如果您正苦于以下问题:Python UART.init方法的具体用法?Python UART.init怎么用?Python UART.init使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类pyb.UART
的用法示例。
在下文中一共展示了UART.init方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: init
# 需要导入模块: from pyb import UART [as 别名]
# 或者: from pyb.UART import init [as 别名]
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"
示例2: uart_hash
# 需要导入模块: from pyb import UART [as 别名]
# 或者: from pyb.UART import init [as 别名]
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
示例3: MTC
# 需要导入模块: from pyb import UART [as 别名]
# 或者: from pyb.UART import init [as 别名]
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
示例4: uart_hashtag
# 需要导入模块: from pyb import UART [as 别名]
# 或者: from pyb.UART import init [as 别名]
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)
示例5: __init__
# 需要导入模块: from pyb import UART [as 别名]
# 或者: from pyb.UART import init [as 别名]
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))
示例6: remote
# 需要导入模块: from pyb import UART [as 别名]
# 或者: from pyb.UART import init [as 别名]
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()
示例7: keypad
# 需要导入模块: from pyb import UART [as 别名]
# 或者: from pyb.UART import init [as 别名]
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)
示例8: __init__
# 需要导入模块: from pyb import UART [as 别名]
# 或者: from pyb.UART import init [as 别名]
class SBUSReceiver:
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
def get_rx_channels(self):
"""
Used to retrieve the last SBUS channels values reading
:return: an array of 18 unsigned short elements containing 16 standard channel values + 2 digitals (ch 17 and 18)
"""
return self.sbusChannels
def get_rx_channel(self, num_ch):
"""
Used to retrieve the last SBUS channel value reading for a specific channel
:param: num_ch: the channel which to retrieve the value for
:return: a short value containing
"""
return self.sbusChannels[num_ch]
def get_failsafe_status(self):
"""
Used to retrieve the last FAILSAFE status
:return: a short value containing
"""
return self.failSafeStatus
def get_rx_report(self):
"""
Used to retrieve some stats about the frames decoding
:return: a dictionary containg three information ('Valid Frames','Lost Frames', 'Resync Events')
"""
rep = {}
rep['Valid Frames'] = self.validSbusFrame
rep['Lost Frames'] = self.lostSbusFrame
rep['Resync Events'] = self.resyncEvent
return rep
def decode_frame(self):
# TODO: DoubleCheck if it has to be removed
for i in range(0, self.SBUS_NUM_CHANNELS - 2):
self.sbusChannels[i] = 0
# counters initialization
byte_in_sbus = 1
bit_in_sbus = 0
ch = 0
bit_in_channel = 0
for i in range(0, 175): # TODO Generalization
if self.sbusFrame[byte_in_sbus] & (1 << bit_in_sbus):
self.sbusChannels[ch] |= (1 << bit_in_channel)
bit_in_sbus += 1
bit_in_channel += 1
if bit_in_sbus == 8:
bit_in_sbus = 0
byte_in_sbus += 1
if bit_in_channel == 11:
bit_in_channel = 0
ch += 1
# Decode Digitals Channels
# Digital Channel 1
if self.sbusFrame[self.SBUS_FRAME_LEN - 2] & (1 << 0):
self.sbusChannels[self.SBUS_NUM_CHAN - 2] = 1
else:
self.sbusChannels[self.SBUS_NUM_CHAN - 2] = 0
# Digital Channel 2
#.........这里部分代码省略.........
示例9: Pin
# 需要导入模块: from pyb import UART [as 别名]
# 或者: from pyb.UART import init [as 别名]
# main.py -- put your code here!
from pyb import Pin, ExtInt, UART, delay
from time import sleep
import pyb
start_pin = Pin('Y3', Pin.IN, Pin.PULL_UP) # PB8 monitors start button push event.
stop_pin = Pin('X2', Pin.IN, Pin.PULL_UP) # PA1 monitors stop button push event.
led_pin = Pin('X5', Pin.OUT_PP) # PA4 drives LED indicator.
led_pin.low()
uart = UART(2, 9600) # UART2 communcates to CSi8.
uart.init(9600, bits=7, parity=1, stop=1)
start_pressed = 0
# stop_pressed = 0
t1_set = 200
t1_last = 30
t2_set = 600
t1_t2_step = 1
t1_t2_last = 480
t2_last = 120
off_last = 390
cmd_prefix = '*P012' # Write to RAM of point 1 with positive sign and decimal point 2
cmd_standby = '*D03' # Standby mode with output off
cmd_dis_standby = '*E03'# Disable standby
start_value = 0
stop_value = 0
print("stop_pin.value="+str(stop_pin.value()))
print("start_pin.value="+str(start_pin.value()))
def start_callback(line):
global start_pressed, start_int, pyb, start_pin, stop_pin
示例10: range
# 需要导入模块: from pyb import UART [as 别名]
# 或者: from pyb.UART import init [as 别名]
if 'LaunchPad' in machine:
uart_id_range = range(0, 2)
uart_pins = [[('GP12', 'GP13'), ('GP12', 'GP13', 'GP7', 'GP6')], [('GP16', 'GP17'), ('GP16', 'GP17', 'GP7', 'GP6')]]
elif 'WiPy' in machine:
uart_id_range = range(0, 2)
uart_pins = [[('GP12', 'GP13'), ('GP12', 'GP13', 'GP7', 'GP6')], [('GP16', 'GP17'), ('GP16', 'GP17', 'GP7', 'GP6')]]
else:
raise Exception('Board not supported!')
# just in case we have stdio duplicated on any of the uarts
pyb.repl_uart(None)
for uart_id in uart_id_range:
uart = UART(uart_id, 38400)
print(uart)
uart.init(57600, 8, None, 1, pins=uart_pins[uart_id][0])
uart.init(baudrate=9600, stop=2, parity=UART.EVEN, pins=uart_pins[uart_id][1])
uart.init(baudrate=115200, parity=UART.ODD, stop=0, pins=uart_pins[uart_id][0])
uart = UART(baudrate=1000000)
uart.sendbreak()
uart = UART(baudrate=1000000)
uart = UART()
print(uart)
uart = UART(baudrate=38400, pins=('GP12', 'GP13'))
print(uart)
uart = UART(pins=('GP12', 'GP13'))
print(uart)
uart = UART(pins=(None, 'GP17'))
print(uart)
uart = UART(baudrate=57600, pins=('GP16', 'GP17'))
示例11: UART
# 需要导入模块: from pyb import UART [as 别名]
# 或者: from pyb.UART import init [as 别名]
from pyb import UART
uart = UART(1)
uart = UART(1, 9600)
uart = UART(1, 9600, bits=8, parity=None, stop=1)
print(uart)
uart.init(2400)
print(uart)
print(uart.any())
print(uart.write('123'))
print(uart.write(b'abcd'))
print(uart.writechar(1))
# make sure this method exists
uart.sendbreak()
示例12: UART
# 需要导入模块: from pyb import UART [as 别名]
# 或者: from pyb.UART import init [as 别名]
#programamos pines
wixel = pyb.Pin('Y11',pyb.Pin.OUT_PP)
wixel.low() #turn on
geigerPower = pyb.Pin('Y9', pyb.Pin.OUT_PP) #relay for power geiger
geigerPower.high() #turn off
geigerIn = pyb.Pin('Y10', pyb.Pin.IN)
#pitido inicial en salida Y8
tim12 = pyb.Timer(12, freq=3500)
ch2=tim12.channel(2, pyb.Timer.PWM, pin=pyb.Pin.board.Y8, pulse_width=12000)
pyb.delay(100) #in msecs
ch2.pulse_width(0)
#uart6 a wixel, pins Y1 y Y2
uart = UART(6,9600)
uart.init(9600,bits=8,stop=1,parity=None)
pyb.repl_uart(uart)
#initalize fram
fr = fram.fram()
frt = fram_t.fram_t(fr)
#rtc
rtc = pyb.RTC()
#initialize am2302
a = am2302.am2302(ch2, frt)
#initialize loop
l = loop.loop(geigerPower, a, fr, frt, ch2, uart, wixel)
示例13: range
# 需要导入模块: from pyb import UART [as 别名]
# 或者: from pyb.UART import init [as 别名]
if 'LaunchPad' in machine:
uart_id_range = range(0, 2)
uart_pins = [[('GP12', 'GP13'), ('GP12', 'GP13', 'GP7', 'GP6')], [('GP16', 'GP17'), ('GP16', 'GP17', 'GP7', 'GP6')]]
elif 'WiPy' in machine:
uart_id_range = range(0, 2)
uart_pins = [[('GP12', 'GP13'), ('GP12', 'GP13', 'GP7', 'GP6')], [('GP16', 'GP17'), ('GP16', 'GP17', 'GP7', 'GP6')]]
else:
raise Exception('Board not supported!')
# just in case we have stdio duplicated on any of the uarts
pyb.repl_uart(None)
for uart_id in uart_id_range:
uart = UART(uart_id, 38400)
print(uart)
uart.init(baudrate=57600, stop=1, parity=None, pins=uart_pins[uart_id][0])
uart.init(baudrate=9600, stop=2, parity=0, pins=uart_pins[uart_id][1])
uart.init(baudrate=115200, parity=1, pins=uart_pins[uart_id][0])
uart.sendbreak()
# now it's time for some loopback tests between the uarts
uart0 = UART(0, 1000000, pins=uart_pins[0][0])
print(uart0)
uart1 = UART(1, 1000000, pins=uart_pins[1][0])
print(uart1)
print(uart0.write(b'123456') == 6)
print(uart1.read() == b'123456')
print(uart1.write(b'123') == 3)
print(uart0.read(1) == b'1')
示例14: UART
# 需要导入模块: from pyb import UART [as 别名]
# 或者: from pyb.UART import init [as 别名]
#_________________________________________________
# Task 6: Function to generate UART sequence for '#' on Y1
# initialize UART(6) to output TX on Pin Y1
import pyb
from pyb import Pin, Timer, UART
print('Task 6: Using UART to send "#"')
uart = UART(6)
while True:
uart.init(9600, bits=8, parity = 0, stop = 2)
uart.writechar(ord('#'))
pyb.delay(5)
示例15: UART
# 需要导入模块: from pyb import UART [as 别名]
# 或者: from pyb.UART import init [as 别名]
from pyb import UART
uart = UART(1)
uart = UART(1, 9600)
uart = UART(1, 9600, bits=8, stop=1, parity=None)
print(uart)
uart.init(1200)
print(uart)
uart.any()
uart.send(1, timeout=500)