MicroPython的系统结构
MicroPython连接电脑
STM32微控制器的pyboard系列的开发板,通常都是带有的开发板,在通过USB连接计算机后,默认情况下会出现两个设备:
- 虚拟磁盘(MSD)
- 虚拟串口(USB Comm Port)
Windows系统的设备管理器中显示的pyboard设备
Windows ● 超级终端(WinXP,可以在Win7/Win10下使用) ● putty ● kitty ● SecureCRT ● MobaXterm Linux ● putty ● screen ● picocom ● minicom MacOS ● screen
注:
MicroPython v1.11 on 2019-05-29; PYBv1.1 with STM32F405RG Type "help()" for more information.
MicroPython的REPL(read-evaluate-print-loop)
>>> help() Welcome to MicroPython! For online help please visit http://micropython.org/help/. Quick overview of commands for the board: pyb.info() -- print some general information pyb.delay(n) -- wait for n milliseconds pyb.millis() -- get number of milliseconds since hard reset pyb.Switch() -- create a switch object Switch methods: (), callback(f) pyb.LED(n) -- create an LED object for LED n (n=1,2,3,4) LED methods: on(), off(), toggle(), intensity(<n>) pyb.Pin(pin) -- get a pin, eg pyb.Pin('X1') pyb.Pin(pin, m, [p]) -- get a pin and configure it for IO mode m, pull mode p Pin methods: init(..), value([v]), high(), low() pyb.ExtInt(pin, m, p, callback) -- create an external interrupt object pyb.ADC(pin) -- make an analog object from a pin ADC methods: read(), read_timed(buf, freq) pyb.DAC(port) -- make a DAC object DAC methods: triangle(freq), write(n), write_timed(buf, freq) pyb.RTC() -- make an RTC object; methods: datetime([val]) pyb.rng() -- get a 30-bit hardware random number pyb.Servo(n) -- create Servo object for servo n (n=1,2,3,4) Servo methods: calibration(..), angle([x, [t]]), speed([x, [t]]) pyb.Accel() -- create an Accelerometer object Accelerometer methods: x(), y(), z(), tilt(), filtered_xyz() Pins are numbered X1-X12, X17-X22, Y1-Y12, or by their MCU name Pin IO modes are: pyb.Pin.IN, pyb.Pin.OUT_PP, pyb.Pin.OUT_OD Pin pull modes are: pyb.Pin.PULL_NONE, pyb.Pin.PULL_UP, pyb.Pin.PULL_DOWN Additional serial bus objects: pyb.I2C(n), pyb.SPI(n), pyb.UART(n) Control commands: CTRL-A -- on a blank line, enter raw REPL mode CTRL-B -- on a blank line, enter normal REPL mode CTRL-C -- interrupt a running program CTRL-D -- on a blank line, do a soft reset of the board CTRL-E -- on a blank line, enter paste mode For further help on a specific object, type help(obj) For a list of available modules, type help('modules') >>>
>>> help(pyb) object <module 'pyb'> is of type module __name__ -- pyb fault_debug -- <function> bootloader -- <function> hard_reset -- <function> info -- <function> unique_id -- <function> freq -- <function> repl_info -- <function> wfi -- <function> disable_irq -- <function> enable_irq -- <function> stop -- <function> standby -- <function> main -- <function> repl_uart -- <function> usb_mode -- <function> hid_mouse -- (1, 2, 4, 8, b'\x05\x01\t\x02\xa1\x01\t\x01\xa1\x00\x05\t\x19\x01)\x03\x15\x00%\x01\x95\x03u\x01\x81\x02\x95\x01u\x05\x81\x01\x05\x01\t0\t1\t8\x15\x81%\x7fu\x08\x95\x03\x81\x06\xc0\t<\x05\xff\t\x01\x15\x00%\x01u\x01\x95\x02\xb1"u\x06\x95\x01\xb1\x01\xc0') hid_keyboard -- (1, 1, 8, 8, b'\x05\x01\t\x06\xa1\x01\x05\x07\x19\xe0)\xe7\x15\x00%\x01u\x01\x95\x08\x81\x02\x95\x01u\x08\x81\x01\x95\x05u\x01\x05\x08\x19\x01)\x05\x91\x02\x95\x01u\x03\x91\x01\x95\x06u\x08\x15\x00%e\x05\x07\x19\x00)e\x81\x00\xc0') USB_VCP -- <class 'USB_VCP'> USB_HID -- <class 'USB_HID'> have_cdc -- <function> hid -- <function> millis -- <function> elapsed_millis -- <function> micros -- <function> elapsed_micros -- <function> delay -- <function> udelay -- <function> sync -- <function> mount -- <function> dht_readinto -- <function> Timer -- <class 'Timer'> rng -- <function> RTC -- <class 'RTC'> Pin -- <class 'Pin'> ExtInt -- <class 'ExtInt'> pwm -- <function> servo -- <function> Servo -- <class 'Servo'> Switch -- <class 'Switch'> Flash -- <class 'Flash'> SD -- <SDCard> SDCard -- <class 'SDCard'> LED -- <class 'LED'> I2C -- <class 'I2C'> SPI -- <class 'SPI'> UART -- <class 'UART'> CAN -- <class 'CAN'> ADC -- <class 'ADC'> ADCAll -- <class 'ADCAll'> DAC -- <class 'DAC'> Accel -- <class 'Accel'> LCD -- <class 'LCD'>
>>> help(pyb.Pin) object <class 'Pin'> is of type type init -- <function> value -- <function> off -- <function> on -- <function> irq -- <function> low -- <function> high -- <function> name -- <function> names -- <function> af_list -- <function> port -- <function> pin -- <function> gpio -- <function> mode -- <function> pull -- <function> af -- <function> mapper -- <classmethod> dict -- <classmethod> debug -- <classmethod> board -- <class 'board'> cpu -- <class 'cpu'> IN -- 0 OUT -- 1 OPEN_DRAIN -- 17 ALT -- 2 ALT_OPEN_DRAIN -- 18 ANALOG -- 3 PULL_UP -- 1 PULL_DOWN -- 2 IRQ_RISING -- 269549568 IRQ_FALLING -- 270598144 OUT_PP -- 1 OUT_OD -- 17 AF_PP -- 2 AF_OD -- 18 PULL_NONE -- 0 AF1_TIM1 -- 1 AF1_TIM2 -- 1 AF2_TIM3 -- 2 AF2_TIM4 -- 2 AF2_TIM5 -- 2 AF3_TIM10 -- 3 AF3_TIM11 -- 3 AF3_TIM8 -- 3 AF3_TIM9 -- 3 AF4_I2C1 -- 4 AF4_I2C2 -- 4 AF5_SPI1 -- 5 AF5_SPI2 -- 5 AF7_USART1 -- 7 AF7_USART2 -- 7 AF7_USART3 -- 7 AF8_UART4 -- 8 AF8_USART6 -- 8 AF9_CAN1 -- 9 AF9_CAN2 -- 9 AF9_TIM12 -- 9 AF9_TIM13 -- 9 AF9_TIM14 -- 9
甚至可以一级一级深入查看,如:
>>> help(pyb.Pin.board) object <class 'board'> is of type type X1 -- Pin(Pin.cpu.A0, mode=Pin.OUT) X2 -- Pin(Pin.cpu.A1, mode=Pin.OUT) X3 -- Pin(Pin.cpu.A2, mode=Pin.IN) X4 -- Pin(Pin.cpu.A3, mode=Pin.IN) X5 -- Pin(Pin.cpu.A4, mode=Pin.IN) X6 -- Pin(Pin.cpu.A5, mode=Pin.IN) X7 -- Pin(Pin.cpu.A6, mode=Pin.IN) X8 -- Pin(Pin.cpu.A7, mode=Pin.IN) X9 -- Pin(Pin.cpu.B6, mode=Pin.OUT) X10 -- Pin(Pin.cpu.B7, mode=Pin.IN) X11 -- Pin(Pin.cpu.C4, mode=Pin.IN) X12 -- Pin(Pin.cpu.C5, mode=Pin.IN) X17 -- Pin(Pin.cpu.B3, mode=Pin.IN, pull=Pin.PULL_UP) X18 -- Pin(Pin.cpu.C13, mode=Pin.IN) X19 -- Pin(Pin.cpu.C0, mode=Pin.IN) X20 -- Pin(Pin.cpu.C1, mode=Pin.IN) X21 -- Pin(Pin.cpu.C2, mode=Pin.IN) X22 -- Pin(Pin.cpu.C3, mode=Pin.IN) Y1 -- Pin(Pin.cpu.C6, mode=Pin.OUT) Y2 -- Pin(Pin.cpu.C7, mode=Pin.OUT) Y3 -- Pin(Pin.cpu.B8, mode=Pin.IN) Y4 -- Pin(Pin.cpu.B9, mode=Pin.IN) Y5 -- Pin(Pin.cpu.B12, mode=Pin.IN) Y6 -- Pin(Pin.cpu.B13, mode=Pin.IN) Y7 -- Pin(Pin.cpu.B14, mode=Pin.IN) Y8 -- Pin(Pin.cpu.B15, mode=Pin.IN) Y9 -- Pin(Pin.cpu.B10, mode=Pin.IN) Y10 -- Pin(Pin.cpu.B11, mode=Pin.IN) Y11 -- Pin(Pin.cpu.B0, mode=Pin.IN) Y12 -- Pin(Pin.cpu.B1, mode=Pin.IN) SW -- Pin(Pin.cpu.B3, mode=Pin.IN, pull=Pin.PULL_UP) LED_RED -- Pin(Pin.cpu.A13, mode=Pin.OUT) LED_GREEN -- Pin(Pin.cpu.A14, mode=Pin.OUT) LED_YELLOW -- Pin(Pin.cpu.A15, mode=Pin.OUT) LED_BLUE -- Pin(Pin.cpu.B4, mode=Pin.OUT) MMA_INT -- Pin(Pin.cpu.B2, mode=Pin.IN) MMA_AVDD -- Pin(Pin.cpu.B5, mode=Pin.OUT) SD_D0 -- Pin(Pin.cpu.C8, mode=Pin.ALT, pull=Pin.PULL_UP, af=12) SD_D1 -- Pin(Pin.cpu.C9, mode=Pin.ALT, pull=Pin.PULL_UP, af=12) SD_D2 -- Pin(Pin.cpu.C10, mode=Pin.ALT, pull=Pin.PULL_UP, af=12) SD_D3 -- Pin(Pin.cpu.C11, mode=Pin.ALT, pull=Pin.PULL_UP, af=12) SD_CMD -- Pin(Pin.cpu.D2, mode=Pin.ALT, pull=Pin.PULL_UP, af=12) SD_CK -- Pin(Pin.cpu.C12, mode=Pin.ALT, pull=Pin.PULL_UP, af=12) SD -- Pin(Pin.cpu.A8, mode=Pin.IN, pull=Pin.PULL_UP) SD_SW -- Pin(Pin.cpu.A8, mode=Pin.IN, pull=Pin.PULL_UP) USB_VBUS -- Pin(Pin.cpu.A9, mode=Pin.IN) USB_ID -- Pin(Pin.cpu.A10, mode=Pin.ALT_OPEN_DRAIN, pull=Pin.PULL_UP, af=10) USB_DM -- Pin(Pin.cpu.A11, mode=Pin.ALT, af=10) USB_DP -- Pin(Pin.cpu.A12, mode=Pin.ALT, af=10) >>>
查看模块包含的变量和函数--dir()
>>> import pyb >>> import math >>> import os >>> dir() ['os', 'start1', 'run', 'x1', '__name__', 'Pin', 'flag', 'Timer', 'x2', 'Echo', 'start', 'y1', 'left', 'back', 'y2', 'num', 'math', 'stop', 'Trig', 'stop1', 'pyb', 'go', 'right', 'machine'] >>>
>>> MicroPython v1.11 on 2019-05-29; PYBv1.0 with STM32F405RG Type "help()" for more information. >>>
● 1MB Flash和196KB SRAM ● 168MHz主频 ● RTC实时时钟 ● 51个通用GPIO ● 17个定时器 ● 多路PWM输出 ● 16路ADC输入 ● 2路DAC输出 ● 3个I2C接口 ● 4个UART接口 ● 3个SPI接口 ● 一个USB2.0全速接口 ● 2个CAN接口 ● SDIO接口 ● 硬件随机数发生器 ● 唯一ID号 ● 1.8~3.6V工作电压 pyboard的主要功能: ● 一个复位按键 ● 一个用户按键 ● 4个不同颜色的LED(其中两个带有亮度调节功能) ● MMA7660C三轴加速度传感器 ● microSD插座
LED(1-4)
SD存储卡
Power电源分配
引出的I/0口端子
来源:博客园
作者:iBoundary
链接:https://www.cnblogs.com/iBoundary/p/11493941.html