MicroPython v1.9-8-gfcaadf92 on 2017-05-26; ESP module with ESP8266
Type "help()" for more information.
>>>
PYB: soft reboot
#6 ets_task(40100164, 3, 3fff829c, 4)
OSError: [Errno 2] ENOENT
MicroPython v1.9-8-gfcaadf92 on 2017-05-26; ESP module with ESP8266
Type "help()" for more information.
>>>
換 1.9 版韌體後發現執行 ampy 會出現 "could not enter raw repl" 錯誤 :
E:\test>ampy --port COM3 ls
b'#6 ets_task(40100164, 3, 3fff829c, 4)\r\n\r\n ets Jan 8 2013,rst cause:4, boot mode:(3,3)\r\n\r\nwdt reset\r\nload 0x40100000, len 32112, room 16 \r\ntail 0\r\nchksum 0xe0\r\nload 0x3ffe8000, len 1104, room 8 \r\ntail 8\r\nchksum 0x4d\r\nload 0x3ffe8450, len 3000, room 0 \r\ntail 8\r\nchksum 0x46\r\ncsum 0x46\r\n\x0e\xfc\x80\x0cl\x9c\x9e|\xfe\x82\x12rrnb\x8e\x8c\x0cl\xec\x12\x0c\x0cb\xecl\x0cb\xec\x8c\x9c\x9c\xe2\xe2\x0c\x8c\x0c\x0cb\x0c\x8elrl\x0el\x0cl\x9c\x9e|\xfe\x82\x12rrnb\x8e\x8cll\x9c\x1c\x82\x0c\x0cb\xec\x8c\x0cb\xec\x8c\x9c\x9c\xe2\x02\x12\x12\x02\x0cb\xec\x0c\x8elrl\x0e\x8c\x0cl\x9c\x9e|\xfe\x82\x12rrnb\x8e\x8cl\x0c\x9c\x1c\x92\x0c\x0cb\x8c\x0c\x0cb\xec\x8c\x9c\x9c\xe2\x02\x02\x8c\x0c\x0cb\xeclb\x0el\x8c\xe2\x02\xec\x12\x82n\xec\x92r\x82\xf2n|\xec\x0c\x8cl\x8eprl\x8c\xe2r\x92l\x8cl\x12\x8c\x0c\x0c\x0cl`\x02\x8c\xe2r\x92l\xecl\x12\x8c\x0c\x0c\x0cl`\x02\x8c\xe2r\x92l\x0c\x8e\x9e\x00\x8c\x0c\x0cll`\x02rl\x8e\x82rl\x8c\x9e\xe2\x8cb\x0c\x8c\x8cb\x8cb\x0cbr\x02\x02\xec\x8er\x0c\x12\x12b\xec\xf2n\xee\x80\x12nn\xe2\x10\x02\x0c\x02l\x92\xf2\x02\x0cl\x0c\x8c\x0cl\x8c\x8ell\x8e\x1e\x82\x8c\x8c\x8c\xec\x8e\x0el\x80\x02n\xfc\x00\x8c\x9e\xe2\x8cb\x0cl\x0cl\x8erp\x0c\x0c\x02\x02\x8c\x9e\xe2\x8cb\x0cl\x0c\x8cb\x1crlrlr\xf2n\x9c\xe2\x00\x8c\x0c\xec\x82\x12\x02b\xe0\x80\x8c\x8c\x0c\x8cl\xe2\x8c\x0c\xec\x8e\x1e\x02\x02\x8c\x8c\x92lb\xecb\xec\xf2n\x9c\x9e\x80\x80\x02b\xe0\x8c\x8c\x8c\x0c\x8cl\xe2\x8c\x0c\xec\x8e\x1e\x02\x02\x8c\x8c\x92lb\x0el\x0e\xec\x0cl\x9c\x9e|\xfe\x82\x12rrnb\x8e\x8c\x0cl\x9c\x9c\x0c\x0cb\x8c\x0c\x0cb\xec\x8c\x9c\x9c\x9c|\x90\x8c\x0c\x0cbl\x0clb\x0el\x02\x82\x82\x02ln\x9cl`\x02\x02\x82\x82\x02ln\x9cprl\x0e\x0c\x8el\x9c\x9e|\xfe\x82\x12rrnb\x8e\x8c\xfe#5 ets_task(40100164, 3, 3fff829c, 4)\r\nWebREPL daemon started on ws://192.168.4.1:8266\r\nWebREPL daemon started on ws://0.0.0.0:8266\r\nStarted webrepl in manual override mode\r\n\r\nMicroPython v1.9-8-gfcaadf92 on 2017-05-26; ESP module with ESP8266\r\nType "help()" for more information.\r\n>>> '
Traceback (most recent call last):
File "c:\python36\lib\runpy.py", line 193, in _run_module_as_main
"__main__", mod_spec)
File "c:\python36\lib\runpy.py", line 85, in _run_code
exec(code, run_globals)
File "C:\Python36\Scripts\ampy.exe\__main__.py", line 9, in <module>
File "c:\python36\lib\site-packages\click\core.py", line 722, in __call__
return self.main(*args, **kwargs)
File "c:\python36\lib\site-packages\click\core.py", line 697, in main
rv = self.invoke(ctx)
File "c:\python36\lib\site-packages\click\core.py", line 1066, in invoke
return _process_result(sub_ctx.command.invoke(sub_ctx))
File "c:\python36\lib\site-packages\click\core.py", line 895, in invoke
return ctx.invoke(self.callback, **ctx.params)
File "c:\python36\lib\site-packages\click\core.py", line 535, in invoke
return callback(*args, **kwargs)
File "c:\python36\lib\site-packages\ampy\cli.py", line 142, in ls
for f in board_files.ls(directory):
File "c:\python36\lib\site-packages\ampy\files.py", line 91, in ls
self._pyboard.enter_raw_repl()
File "c:\python36\lib\site-packages\ampy\pyboard.py", line 202, in enter_raw_repl
raise PyboardError('could not enter raw repl')
ampy.pyboard.PyboardError: could not enter raw repl
"Note that many end-user boards use their own adhoc pin numbering (marked e.g. D0, D1, ...). As MicroPython supports different boards and modules, physical pin numbering was chosen as the lowest common denominator. For mapping between board logical pins and physical chip pins, consult your board documentation."
import time
from machine import Pin
swPin=Pin(0, Pin.IN, Pin.PULL_UP)
ledPin=Pin(2, Pin.OUT)
while True:
if not swPin.value(): #若按鈕被按下 (接地)
ledPin.value(not ledPin.value()) #反轉 LED 狀態 time.sleep_ms(300) #暫停 0.3 秒
while not swPin.value(): #按鈕若還在按下狀態就在迴圈繞, 否則跳出去
pass
swPin=Pin(0, Pin.IN, Pin.PULL_UP)
ledPin=Pin(2, Pin.OUT)
while True:
wait_pin_change(swPin) #先至少等 20ms 開關趨於穩定
if not swPin.value(): #如果按鈕按下就反轉 LED 狀態
ledPin.value(not ledPin.value())
"we are shipping the ESP-12S version which no longer has the SPI flash pads brought out on the bottom row. Note that you couldn't use them for GPIOs or anything, they were there so you could program the FLASH chip only."
import time
from ntptime import settime
settime()
utc_epoch=time.mktime(time.localtime())
Y,M,D,H,m,S,ms,W=time.localtime(utc_epoch + 28800)
t=str(Y) + '-'
if M<10:
t += '0' + str(M)
else:
t += str(M)
t += '-'
if D<10:
t += '0' + str(D)
else:
t += str(D)
t += ' '
if H<10:
t += '0' + str(H)
else:
t += str(H)
t += ':'
if m<10:
t += '0' + str(m)
else:
t += str(m)
t += ':'
if S<10:
t += '0' + str(S)
else:
t += str(S)
print(t)
"Due to limitations of the ESP8266 chip the internal real-time clock (RTC) will overflow every 7:45h. If a long-term working RTC time is required then time() or localtime() must be called at least once within 7 hours. MicroPython will then handle the overflow."
"If your devices has 1Mbyte or more of storage then it will be set up (upon first boot) to contain a filesystem. This filesystem uses the FAT format and is stored in the flash after the MicroPython firmware."
MicroPython 事實上只納入基本的檔案目錄操作功能如檔案與目錄的讀寫而已, 雖有實作 os 模組但卻未實作 os.path 模組, 例如 :
>>> import os
>>> import os.path
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ImportError: no module named 'os'
Ampy is a tool to control MicroPython boards over a serial connection.
Using ampy you can manipulate files on the board's internal filesystem and
even run scripts.
Options:
-p, --port PORT Name of serial port for connected board. Can optionally
specify with AMPY_PORT environemnt variable. [required]
-b, --baud BAUD Baud rate for the serial connection (default 115200). Can
optionally specify with AMPY_BAUD environment variable.
--version Show the version and exit.
--help Show this message and exit.
Commands:
get Retrieve a file from the board.
ls List contents of a directory on the board.
mkdir Create a directory on the board.
put Put a file or folder and its contents on the...
reset Perform soft reset/reboot of the board.
rm Remove a file from the board.
rmdir Forcefully remove a folder and all its...
run Run a script and print its output.
這裡很重要的是 OPTION 中的 port, 在 Windows 是用 COMx (慣例是用大寫), 所以要先在裝置管理員中確定 USB-TTL 轉接線是哪一個 COM 埠. 另外因為 ampy 要使用串列埠, 所以如果有使用 PuTTY 開啟該 COM 埠的話, 必須關掉 Putty, 否則 ampy 的指令都會報錯, 例如 :
D:\test>ampy --port COM4 put main.py
Traceback (most recent call last):
File "c:\python36\lib\runpy.py", line 193, in _run_module_as_main
"__main__", mod_spec)
File "c:\python36\lib\runpy.py", line 85, in _run_code
exec(code, run_globals)
File "C:\Python36\Scripts\ampy.exe\__main__.py", line 9, in
File "c:\python36\lib\site-packages\click\core.py", line 722, in __call__
return self.main(*args, **kwargs)
File "c:\python36\lib\site-packages\click\core.py", line 697, in main
rv = self.invoke(ctx)
File "c:\python36\lib\site-packages\click\core.py", line 1063, in invoke
Command.invoke(self, ctx)
File "c:\python36\lib\site-packages\click\core.py", line 895, in invoke
return ctx.invoke(self.callback, **ctx.params)
File "c:\python36\lib\site-packages\click\core.py", line 535, in invoke
return callback(*args, **kwargs)
File "c:\python36\lib\site-packages\ampy\cli.py", line 70, in cli
_board = pyboard.Pyboard(port, baudrate=baud)
File "c:\python36\lib\site-packages\ampy\pyboard.py", line 143, in __init__
raise PyboardError('failed to access ' + device)
ampy.pyboard.PyboardError: failed to access COM4 (因為 PuTTY 也在連線 COM4 導致衝突)
** Micropython File Shell v0.8.0, sw@kaltpost.de **
-- Running on Python 3.6 using PySerial 3.3 --
mpfs [/]> help #指令列表
Documented commands (type help <topic>):
========================================
EOF cd exec get lcd lpwd md mput mrm put repl
cat close exit help lls ls mget mpyc open pwd rm
help 後面加上指令可以查看該指令說明, 例如 :
mpfs [/]> help put #顯示 put 指令之說明
put <LOCAL FILE> [<REMOTE FILE>]
Upload local file. If the second parameter is given,
its value is used for the remote file name. Otherwise the
remote file will be named the same as the local file.
mpfs [/]> md log #新增目錄 log
mpfs [/]> ls #顯示檔案與目錄列表
Remote files in '/':
boot.py
main.py
data.txt
hello.py
mpfs [/]> cd log #切換到 log 目錄
mpfs [/log]> pwd #顯示目前路徑
/log
mpfs [/log]> help put #顯示 put 指令說明
put <LOCAL FILE> [<REMOTE FILE>]
Upload local file. If the second parameter is given,
its value is used for the remote file name. Otherwise the
remote file will be named the same as the local file.
mpfs [/log]> put data.log #上傳 data.log 至 ESP8266
mpfs [/log]> ls #顯示檔案與目錄列表
Remote files in '/log':
<dir> .. data.log #log 下有剛上傳的 data.log
mpfs [/log]> cat data.log #顯示檔案內容
Hello World!
mpfs [/log]> get data.log #下載 data.log
mpfs [/log]> rm data.log #刪除檔案
mpfs [/log]> cd .. #切換目錄至上一層
mpfs [/]> rm log #刪除目錄 log
mpfs [/]> ls #顯示檔案與目錄列表
Remote files in '/': #已無 log 目錄
boot.py
main.py
data.txt
hello.py
mpfshell 也有本地端檔案系統操作指令 (L 開頭的除了 ls 外都是本機指令), 不須跳出 mpfshell 也可以切換本機路徑或顯示檔案 :
mpfs [/]> lpwd #顯示本機目前路徑
D:\test
mpfs [/]> lcd .. #切換本機目前路徑至上一層
mpfs [/]> lpwd #顯示本機目前路徑
D:\
mpfs [/]> lcd test #切換本機目前路徑至 test 目錄
mpfs [/]> lpwd #顯示本機目前路徑
D:\test
mpfs [/]> help mget #顯示 mget 指令說明
mget <SELECTION REGEX>
Download all remote files that match the given regular expression.
The local files will be named the same as the remote files.
"mget" does not get directories, and it is note recursive.
mpfs [/]> lls #顯示本機目前路徑下檔案目錄
Local files: #目前路徑下是空的
mpfs [/]> ls #顯示遠端目前路徑下檔案目錄
Remote files in '/': #有 4 個檔案
boot.py
main.py
data.txt
hello.py
mpfs [/]> mget .*\.py #以正規表達式整批下載 .py 檔
* get boot.py
* get main.py
* get hello.py
mpfs [/]> lls
MicroPython v1.8.7-7-gb5a1a20a3 on 2017-01-09; ESP module with ESP8266
Type "help()" for more information.
>>> print('Hello!')
Hello!
(按 Ctrl+Q)
mpfs [/]>
C:\Users\Tony<pip3 install d:\python\rshell-master.zip
Processing d:\python\rshell-master.zip
Requirement already satisfied: pyserial in c:\python36\lib\site-packages (from r
shell==0.0.9)
Requirement already satisfied: pyudev<=0.16 in c:\python36\lib\site-packages (fr
om rshell==0.0.9)
Requirement already satisfied: six in c:\python36\lib\site-packages (from pyudev
<=0.16-<rshell==0.0.9)
Installing collected packages: rshell
Running setup.py install for rshell ... done
Successfully installed rshell-0.0.9
但安裝完後輸入 rshell 卻出現錯誤 :
E:\test>rshell #開啟 rshell
Traceback (most recent call last):
File "C:\Python36\Scripts\rshell-script.py", line 11, in load_entry_point('rshell==0.0.9', 'console_scripts', 'rshell')()
File "c:\python36\lib\site-packages\pkg_resources\__init__.py", line 565, in l
oad_entry_point
return get_distribution(dist).load_entry_point(group, name)
File "c:\python36\lib\site-packages\pkg_resources\__init__.py", line 2631, in
load_entry_point
return ep.load()
File "c:\python36\lib\site-packages\pkg_resources\__init__.py", line 2291, in
load
return self.resolve()
File "c:\python36\lib\site-packages\pkg_resources\__init__.py", line 2297, in
resolve
module = __import__(self.module_name, fromlist=['__name__'], level=0)
File "c:\python36\lib\site-packages\rshell\command_line.py", line 1, in e>
import rshell.main
File "c:\python36\lib\site-packages\rshell\main.py", line 65, in import readline
ModuleNotFoundError: No module named 'readline'
"@doudz : Filesystem on modules with 512K flash is not supported (assuming yours is such). To help us diagnose it, move away _boot.py, build, boot, run "import port_diag", and provide its output."