立即注册

micropython-microbit 中文社区

查看: 357|回复: 1

Python神器 Jupyter Notebook 玩转microPython(3)

[复制链接]
  • TA的每日心情
    开心
    2018-10-26 16:33
  • 签到天数: 10 天

    [LV.3]偶尔看看II

    发表于 2019-2-19 14:55:31 | 显示全部楼层 |阅读模式

    马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。

    您需要 登录 才可以下载或查看,没有帐号?立即注册

    x

    1、用串口方式打开连接
    1. %serialconnect --port=COM16
    复制代码
       
        Connecting to --port=COM16 --baud=115200 Ready.

    2、查看支持命令

    1. %lsmagic
    复制代码

        %capture [--quiet] [--QUIET] outputfilename
            records output to a file
       
        %comment
            print this into output
       
        %disconnect [--raw]
            disconnects from web/serial connection
       
        %esptool [--port PORT] {erase,esp32,esp8266} [binfile]
            commands for flashing your esp-device
       
        %fetchfile [--binary] [--print] [--quiet] [--QUIET]
                          sourcefilename [destinationfilename]
            fetch and save a file from the device
       
        %lsmagic
            list magic commands
       
        %mpy-cross [--set-exe SET_EXE] [pyfile]
            cross-compile a .py file to a .mpy file
       
        %readbytes [--binary]
            does serial.read_all()
       
        %rebootdevice
            reboots device
       
        %sendtofile [--append] [--mkdir] [--binary] [--execute]
                           [--source [SOURCE]] [--quiet] [--QUIET]
                           [destinationfilename]
            send cell contents or file/direcectory to the device
       
        %serialconnect [--raw] [--port PORT] [--baud BAUD] [--verbose]
            connects to a device over USB wire
       
        %socketconnect [--raw] ipnumber portnumber
            connects to a socket of a device over wifi
       
        %suppressendcode
            doesn't send x04 or wait to read after sending the contents of the cell
          (assists for debugging using %writebytes and %readbytes)
       
        %websocketconnect [--raw] [--password PASSWORD] [--verbose]
                                 [websocketurl]
            connects to the webREPL websocket of an ESP8266 over wifi
            websocketurl defaults to ws://192.168.4.1:8266 but be sure to be connected
       
        %writebytes [--binary] [--verbose] stringtosend
            does serial.write() of the python quoted string given
       
        %%writefile [--append] [--execute] destinationfilename
            write contents of cell to a file

    3、重启设备

    1. %rebootdevice
    复制代码
       repl is in normal command mode
        [\r\x03\x03] b'\r\nMicroPython v1.10-8-g8b7039d7d on 2019-01-26; ESP module with ESP8266\r\nType "help()" for more information.\r\n>>> \r\n>>> \r\nPYB: soft reboot\rnetwork config: (\'192.168.0.7\', \'255.255.255.0\', \'192.168.0.1\', \'192.168.0.1\')\r\nWebREPL daemon started on ws://192.168.0.7:8266\r\nStarted webrepl in manual override mode\r\nOSError: [Errno 2] ENOENT\r\nMicroPython v1.10-8-g8b7039d7d on 2019-01-26; ESP module with ESP8266\r\nType "help()" for more information.\r\n>>> \r\n>>> \r\n>>> '
        [\r\x01] b'\r\n>>> \r\nraw REPL; CTRL-B to exit\r\n>'

    4、查看os模块
    1. import os
    2. help(os)
    复制代码
       object <module 'uos'> is of type module
          __name__ -- uos
          uname -- <function>
          urandom -- <function>
          dupterm -- <function>
          dupterm_notify -- <function>
          VfsFat -- <class 'VfsFat'>
          ilistdir -- <function>
          listdir -- <function>
          mkdir -- <function>
          rmdir -- <function>
          chdir -- <function>
          getcwd -- <function>
          remove -- <function>
          rename -- <function>
          stat -- <function>
          statvfs -- <function>
          mount -- <function>
          umount -- <function>
       

    5.测试脚本


    * 点击 interrupt the kernel 可以中断程序
    1. # slow function to test streaming and interrupts
    2. import time
    3. def k(n):
    4.     for i in range(n):
    5.         print(9**i)
    6.         time.sleep(2)
    7. k(19)
    复制代码
       1
        9
        81
       
        *** Sending Ctrl-C
       

        Traceback (most recent call last):
          File "<stdin>", line 7, in <module>
          File "<stdin>", line 6, in k
        KeyboardInterrupt:
       

    6、查看开发板文件

    1. import os
    2. print(os.listdir())
    复制代码
       ['boot.py', 'templates']

    7、在开发板新建文件夹

    1. import os
    2. os.mkdir("test")
    3. print(os.listdir())
    4. print('test:',os.listdir("test"))
    复制代码
       ['boot.py', 'templates', 'test']
        test: []
       

    8、保存脚本到开发板
    1. %sendtofile test/test.py
    2. #test sendtofile to micropython board
    3. import time
    4. def k(n):
    5.     for i in range(n):
    6.         print(9**i)
    7.         time.sleep(2)
    8. k(19)
    复制代码

        Sent 7 lines (130 bytes) to test/test.py.

    1. import os
    2. print(os.listdir("test"))
    复制代码
       ['test.py']

    9、运行脚本
    1. exec(open('./test/test.py').read(),globals())
    复制代码
       1
        9
        81
       
        *** Sending Ctrl-C

        Traceback (most recent call last):
          File "<stdin>", line 1, in <module>
          File "<string>", line 7, in <module>
          File "<string>", line 6, in k
        KeyboardInterrupt:
       

    10、关闭连接
    1. %disconnect
    复制代码
       mattempt to exit paste mode
        [\r\x03\x02] [0mb'\r\nMicroPython v1.10-8-g8b7039d7d on 2019-01-26; ESP module with ESP8266\r\nType "help()" for more information.\r\n>>> '[34m
        Closing serial Serial<id=0x2f5eb1320f0, open=True>(port='COM16', baudrate=115200, bytesize=8, parity='N', stopbits=1, timeout=0.5, xonxoff=False, rtscts=False, dsrdtr=False)

    microPython.rar

    2.39 KB, 下载次数: 5

    jupyter文件

    回复

    使用道具 举报

    该用户从未签到

    发表于 2019-3-2 22:41:09 | 显示全部楼层
    python编程:www.99kao.com
    回复 支持 反对

    使用道具 举报

    游客
    回复
    您需要登录后才可以回帖 登录 | 立即注册

    Archiver|手机版|小黑屋|micropython-microbit 中文社区

    GMT+8, 2019-12-9 13:52 , Processed in 0.108581 second(s), 24 queries .

    Powered by Discuz! X3.4

    © 2001-2013 Comsenz Inc.

    快速回复 返回顶部 返回列表