本文整理汇总了Python中pyb.UART属性的典型用法代码示例。如果您正苦于以下问题:Python pyb.UART属性的具体用法?Python pyb.UART怎么用?Python pyb.UART使用的例子?那么恭喜您, 这里精选的属性代码示例或许可以为您提供帮助。您也可以进一步了解该属性所在类pyb
的用法示例。
在下文中一共展示了pyb.UART属性的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: __init__
# 需要导入模块: import pyb [as 别名]
# 或者: from pyb import UART [as 别名]
def __init__(self, path, trigger=None, uart="YA", baudrate=9600):
super().__init__(path)
self.button = "Scan QR code"
if simulator:
self.EOL = b"\r\n"
else:
self.EOL = b"\r"
self.data = b""
self.uart_bus = uart
self.uart = pyb.UART(uart, baudrate, read_buf_len=2048)
self.trigger = None
self.is_configured = False
if trigger is not None or simulator:
self.trigger = pyb.Pin(trigger, pyb.Pin.OUT)
self.trigger.on()
self.is_configured = True
self.scanning = False
示例2: init
# 需要导入模块: import pyb [as 别名]
# 或者: from pyb import UART [as 别名]
def init(self):
if self.is_configured:
return
# if failed to configure - probably a different scanner
# in this case fallback to PIN trigger mode FIXME
self.clean_uart()
self.is_configured = self.configure()
if self.is_configured:
print("Scanner: automatic mode")
return
# Try one more time with different baudrate
self.uart = pyb.UART(self.uart_bus, 115200, read_buf_len=2048)
self.clean_uart()
self.is_configured = self.configure()
if self.is_configured:
print("Scanner: automatic mode")
return
# PIN trigger mode
self.uart = pyb.UART(self.uart_bus, 9600, read_buf_len=2048)
self.trigger = pyb.Pin(QRSCANNER_TRIGGER, pyb.Pin.OUT)
self.trigger.on()
self.is_configured = True
print("Scanner: Pin trigger mode")
示例3: log_kml
# 需要导入模块: import pyb [as 别名]
# 或者: from pyb import UART [as 别名]
def log_kml(fn='/sd/log.kml', interval=10):
yellow.on() # Waiting for data
uart = pyb.UART(4, 9600, read_buf_len=200) # Data on X2
sreader = asyncio.StreamReader(uart)
gps = AS_GPS(sreader, fix_cb=toggle_led)
await gps.data_received(True, True, True, True)
yellow.off()
with open(fn, 'w') as f:
f.write(str_start)
while not sw.value():
f.write(gps.longitude_string(KML))
f.write(',')
f.write(gps.latitude_string(KML))
f.write(',')
f.write(str(gps.altitude))
f.write('\r\n')
for _ in range(interval * 10):
await asyncio.sleep_ms(100)
if sw.value():
break
f.write(str_end)
red.off()
green.on()
示例4: shutdown
# 需要导入模块: import pyb [as 别名]
# 或者: from pyb import UART [as 别名]
def shutdown():
global gps
# Normally UART is already at BAUDRATE. But if last session didn't restore
# factory baudrate we can restore connectivity in the subsequent stuck
# session with ctrl-c.
uart.init(BAUDRATE)
await asyncio.sleep(0.5)
await gps.command(FULL_COLD_START)
print('Factory reset')
gps.close() # Stop ISR
#print('Restoring default baudrate (9600).')
#await gps.baudrate(9600)
#uart.init(9600)
#gps.close() # Stop ISR
#print('Restoring default 1s update rate.')
#await asyncio.sleep(0.5)
#await gps.update_interval(1000) # 1s update rate
#print('Restoring satellite data.')
#await gps.command(as_rwGPS.DEFAULT_SENTENCES) # Restore satellite data
# Setup for tests. Red LED toggles on fix, blue on PPS interrupt.
示例5: gps_test
# 需要导入模块: import pyb [as 别名]
# 或者: from pyb import UART [as 别名]
def gps_test():
global gps, uart # For shutdown
print('Initialising')
# Adapt UART instantiation for other MicroPython hardware
uart = pyb.UART(4, 9600, read_buf_len=200)
# read_buf_len is precautionary: code runs reliably without it.
sreader = asyncio.StreamReader(uart)
swriter = asyncio.StreamWriter(uart, {})
timer = Delay_ms(cb_timeout)
sentence_count = 0
gps = GPS(sreader, swriter, local_offset=1, fix_cb=callback,
fix_cb_args=(timer,), msg_cb = message_cb)
await asyncio.sleep(2)
await gps.command(DEFAULT_SENTENCES)
print('Set sentence frequencies to default')
#await gps.command(FULL_COLD_START)
#print('Performed FULL_COLD_START')
print('awaiting first fix')
asyncio.create_task(sat_test(gps))
asyncio.create_task(stats(gps))
asyncio.create_task(navigation(gps))
asyncio.create_task(course(gps))
asyncio.create_task(date(gps))
await gps.data_received(True, True, True, True) # all messages
await change_status(gps, uart)
示例6: log_kml
# 需要导入模块: import pyb [as 别名]
# 或者: from pyb import UART [as 别名]
def log_kml(fn='/sd/log.kml', interval=10):
yellow.on() # Waiting for data
uart = pyb.UART(4, 9600, read_buf_len=200) # Data on X2
sreader = asyncio.StreamReader(uart)
gps = as_GPS.AS_GPS(sreader, fix_cb=toggle_led)
await gps.data_received(True, True, True, True)
yellow.off()
with open(fn, 'w') as f:
f.write(str_start)
while not sw.value():
f.write(gps.longitude_string(as_GPS.KML))
f.write(',')
f.write(gps.latitude_string(as_GPS.KML))
f.write(',')
f.write(str(gps.altitude))
f.write('\r\n')
for _ in range(interval * 10):
await asyncio.sleep_ms(100)
if sw.value():
break
f.write(str_end)
red.off()
green.on()
示例7: shutdown
# 需要导入模块: import pyb [as 别名]
# 或者: from pyb import UART [as 别名]
def shutdown():
global gps
# Normally UART is already at BAUDRATE. But if last session didn't restore
# factory baudrate we can restore connectivity in the subsequent stuck
# session with ctrl-c.
uart.init(BAUDRATE)
await asyncio.sleep(0.5)
await gps.command(as_rwGPS.FULL_COLD_START)
print('Factory reset')
gps.close() # Stop ISR
#print('Restoring default baudrate (9600).')
#await gps.baudrate(9600)
#uart.init(9600)
#gps.close() # Stop ISR
#print('Restoring default 1s update rate.')
#await asyncio.sleep(0.5)
#await gps.update_interval(1000) # 1s update rate
#print('Restoring satellite data.')
#await gps.command(as_rwGPS.DEFAULT_SENTENCES) # Restore satellite data
# Setup for tests. Red LED toggles on fix, blue on PPS interrupt.
示例8: pins_test
# 需要导入模块: import pyb [as 别名]
# 或者: from pyb import UART [as 别名]
def pins_test():
i2c = I2C(1, I2C.MASTER)
spi = SPI(2, SPI.MASTER)
uart = UART(3, 9600)
servo = Servo(1)
adc = ADC(Pin.board.X3)
dac = DAC(1)
pin = Pin('X4', mode=Pin.AF_PP, af=Pin.AF3_TIM9)
pin = Pin('Y1', mode=Pin.AF_OD, af=3)
pin = Pin('Y2', mode=Pin.OUT_PP)
pin = Pin('Y3', mode=Pin.OUT_OD, pull=Pin.PULL_UP)
pin.high()
pin = Pin('Y4', mode=Pin.OUT_OD, pull=Pin.PULL_DOWN)
pin.high()
pin = Pin('X18', mode=Pin.IN, pull=Pin.PULL_NONE)
pin = Pin('X19', mode=Pin.IN, pull=Pin.PULL_UP)
pin = Pin('X20', mode=Pin.IN, pull=Pin.PULL_DOWN)
print('===== output of pins() =====')
pins.pins()
print('===== output of af() =====')
pins.af()
示例9: main
# 需要导入模块: import pyb [as 别名]
# 或者: from pyb import UART [as 别名]
def main():
serial = pyb.UART(2, BAUDRATE)
lcd = STM_LCDShield()
monitor = MidiMonitor(lcd)
midiin = MidiIn(serial, monitor, debug=True)
lcd.write("MIDI Mon ")
pyb.delay(1000)
lcd.write("ready")
pyb.delay(1000)
lcd.write(" ", col=9)
while True:
midiin.poll()
pyb.delay(POLL_INTERVAL)
示例10: main
# 需要导入模块: import pyb [as 别名]
# 或者: from pyb import UART [as 别名]
def main():
switch = Switch()
while not switch():
delay(200)
# Initialize UART for MIDI
uart = UART(2, baudrate=31250)
midi = MidiOut(uart)
seq = Sequencer(midi, bpm=124)
seq.play(Pattern(PATTERN), kit=9)
示例11: main
# 需要导入模块: import pyb [as 别名]
# 或者: from pyb import UART [as 别名]
def main():
# Initialize UART for MIDI
uart = UART(2, baudrate=31250)
midi = MidiOut(uart)
button1 = Switch()
button2 = Pin('PC0', Pin.IN, Pin.PULL_UP)
button3 = Pin('PC1', Pin.IN, Pin.PULL_UP)
led1 = LED(1)
led2 = LED(2)
led3 = LED(3)
tune = program = 0
# send a PROGRAM CHANGE to set instrument to #0 (Grand Piano)
midi.program_change(program)
while True:
if button1():
# When button 1 is pressed, play the current tune
play(midi, TUNES[TUNENAMES[tune]], led1)
led1.off()
if not button2():
# When button 2 is pressed, select the next of the tunes
led2.on()
tune = (tune+1) % len(TUNENAMES)
delay(BLINK_DELAY)
led2.off()
if not button3():
# When button 3 is pressed, change to next program (instrument)
led3.on()
program = (program+1) % len(PROGRAMS)
midi.program_change(PROGRAMS[program])
delay(BLINK_DELAY)
led3.off()
delay(200)
示例12: __init__
# 需要导入模块: import pyb [as 别名]
# 或者: from pyb import UART [as 别名]
def __init__(self, uart_no = 4):
self.uart = UART(uart_no, 9600)
self.loop = asyncio.get_event_loop()
self.swriter = asyncio.StreamWriter(self.uart, {})
self.sreader = asyncio.StreamReader(self.uart)
loop = asyncio.get_event_loop()
loop.create_task(self._run())
示例13: __init__
# 需要导入模块: import pyb [as 别名]
# 或者: from pyb import UART [as 别名]
def __init__(self,uartno): # pos =1 or 2 depending on skin position
self._uart = pyb.UART(uartno, 9600, read_buf_len=2048)
self.incoming_action = None
self.no_carrier_action = None
self.clip_action = None
self._clip = None
self.msg_action = None
self._msgid = 0
self.savbuf = None
self.credit = ''
self.credit_action = None
示例14: test
# 需要导入模块: import pyb [as 别名]
# 或者: from pyb import UART [as 别名]
def test(duration):
if use_utime: # Not running in low power mode
pyb.LED(3).on()
uart2 = pyb.UART(1, 115200)
uart4 = pyb.UART(4, 9600)
# Instantiate event loop before using it in Latency class
loop = asyncio.get_event_loop()
lp = Latency(50) # ms
loop.create_task(sender(uart4))
loop.create_task(receiver(uart4, uart2))
loop.run_until_complete(killer(duration))
示例15: setup
# 需要导入模块: import pyb [as 别名]
# 或者: from pyb import UART [as 别名]
def setup():
red = pyb.LED(1)
green = pyb.LED(2)
uart = pyb.UART(UART_ID, 9600, read_buf_len=200)
sreader = asyncio.StreamReader(uart)
pps_pin = pyb.Pin(PPS_PIN, pyb.Pin.IN)
return GPS_Timer(sreader, pps_pin, local_offset=1,
fix_cb=lambda *_: red.toggle(),
pps_cb=lambda *_: green.toggle())
# Test terminator: task sets the passed event after the passed time.