Micropython Library เพื่อโต้ตอบกับ Winbond W25Q Flash Chips
เอกสารล่าสุดมีอยู่ที่ Micropython Winbond ReadtheDocs
ต้องติดตั้ง Python3 ในระบบของคุณ ตรวจสอบเวอร์ชัน Python ปัจจุบันด้วยคำสั่งต่อไปนี้
python --version
python3 --version ขึ้นอยู่กับคำสั่ง Python 3.xy (ที่มี XY เป็นตัวเลขบางตัว) จะถูกส่งคืนใช้คำสั่งนั้นเพื่อดำเนินการต่อ
python3 -m venv .venv
source .venv/bin/activate
pip install -r requirements.txtสำหรับการโต้ตอบกับระบบไฟล์ของอุปกรณ์สามารถใช้เชลล์ micropython ระยะไกลได้
ทดสอบเครื่องมือโดยแสดงคำอธิบายข้อมูลผู้ชาย/ความช่วยเหลือ
rshell --helpเชื่อมต่ออุปกรณ์ micropython เข้ากับเครือข่าย (ถ้าเป็นไปได้)
import network
station = network . WLAN ( network . STA_IF )
station . active ( True )
station . connect ( 'SSID' , 'PASSWORD' )
station . isconnected ()ติดตั้งเวอร์ชันแพ็คเกจล่าสุดของ lib นี้บนอุปกรณ์ micropython
import mip
mip . install ( "github:brainelectronics/micropython-winbond" ) สำหรับรุ่น micropython ต่ำกว่า 1.19.1 ใช้แพ็คเกจ upip แทน mip
import upip
upip . install ( 'micropython-winbond' )ติดตั้งเวอร์ชันแพ็คเกจที่แน่นอนและคงที่ของ lib นี้บนอุปกรณ์ micropython
import mip
# install a verions of a specific branch
mip . install ( "github:brainelectronics/micropython-winbond" , version = "feature/add-docs-and-detailed-examples" )
# install a tag version
mip . install ( "github:brainelectronics/micropython-winbond" , version = "0.4.0" ) สำหรับรุ่น micropython ต่ำกว่า 1.19.1 ใช้แพ็คเกจ upip แทน mip ด้วย upip เสมอจะมีการติดตั้งเวอร์ชันล่าสุดที่มีอยู่
import upip
upip . install ( 'micropython-winbond' )ติดตั้งเวอร์ชันผู้สมัครรุ่นเฉพาะที่อัปโหลดเพื่อทดสอบดัชนีแพ็คเกจ Python ในทุก ๆ PR บนอุปกรณ์ Micropython หากไม่มีการตั้งค่าเวอร์ชันเฉพาะเวอร์ชันที่เสถียรล่าสุดจะถูกใช้
import mip
mip . install ( "github:brainelectronics/micropython-winbond" , version = "0.4.0-rc2.dev4" ) สำหรับรุ่น micropython ต่ำกว่า 1.19.1 ใช้แพ็คเกจ upip แทน mip ด้วย upip เสมอจะมีการติดตั้งเวอร์ชันล่าสุดที่มีอยู่
import upip
# overwrite index_urls to only take artifacts from test.pypi.org
upip . index_urls = [ 'https://test.pypi.org/pypi' ]
upip . install ( 'micropython-winbond' )ดูเพิ่มเติมที่ Brainelectronics Test Server PYPI ใน Docker สำหรับเซิร์ฟเวอร์ทดสอบ PYPI ที่ทำงานบน Docker
คัดลอกโมดูลไปยังบอร์ด micropython และนำเข้าดังที่แสดงด้านล่างโดยใช้เชลล์ micropython ระยะไกล
เปิดเชลล์ระยะไกลด้วยคำสั่งต่อไปนี้ นอกจากนี้ยังใช้ -b 115200 ในกรณีที่ไม่มีการใช้ CP210X แต่เป็น CH34X
rshell -p /dev/tty.SLAB_USBtoUART --editor nano ดำเนินการคำสั่งต่อไปนี้ภายใน rshell เพื่อคัดลอกไฟล์และโฟลเดอร์ทั้งหมดไปยังอุปกรณ์
mkdir /pyboard/lib
mkdir /pyboard/lib/winbond
cp winbond/ * /pyboard/lib/winbond
cp main.py /pyboard/lib/winbond
cp boot.py /pyboard/lib/winbond from machine import SPI , Pin
import os
from winbond import W25QFlash
# the used SPI and CS pin is setup specific, change accordingly
# check the boot.py file of this repo for further boards
flash = W25QFlash ( spi = SPI ( 2 ), cs = Pin ( 5 ), baud = 2000000 , software_reset = True )
flash_mount_point = '/external'
try :
os . mount ( flash , flash_mount_point )
except Exception as e :
if e . errno == 19 :
# [Errno 19] ENODEV aka "No such device"
# create the filesystem, this takes some seconds (approx. 10 sec)
print ( 'Creating filesystem for external flash ...' )
print ( 'This might take up to 10 seconds' )
os . VfsFat . mkfs ( flash )
else :
# takes some seconds/minutes (approx. 40 sec for 128MBit/16MB)
print ( 'Formatting external flash ...' )
print ( 'This might take up to 60 seconds' )
# !!! only required on the very first start (will remove everything)
flash . format ()
# create the filesystem, this takes some seconds (approx. 10 sec)
print ( 'Creating filesystem for external flash ...' )
print ( 'This might take up to 10 seconds' )
# !!! only required on first setup and after formatting
os . VfsFat . mkfs ( flash )
print ( 'Filesystem for external flash created' )
# finally mount the external flash
os . mount ( flash , flash_mount_point )ความรุ่งโรจน์และขอบคุณมากสำหรับ Crizeo of the Micropython Forum และโพสต์ของเขาเพื่อใช้ Winbond Flash Chips