Cov txheej txheem:

MicroPython ntawm Txoj Kev Nyuaj Siab Sensor Board: 3 Cov Kauj Ruam
MicroPython ntawm Txoj Kev Nyuaj Siab Sensor Board: 3 Cov Kauj Ruam

Video: MicroPython ntawm Txoj Kev Nyuaj Siab Sensor Board: 3 Cov Kauj Ruam

Video: MicroPython ntawm Txoj Kev Nyuaj Siab Sensor Board: 3 Cov Kauj Ruam
Video: Вводный урок по программированию ESP32, ESP8266 на MicroPython 2024, Hlis ntuj nqeg
Anonim
MicroPython ntawm Txoj Kev Nyuaj Siab Sensor Sensor Board
MicroPython ntawm Txoj Kev Nyuaj Siab Sensor Sensor Board
MicroPython ntawm Pawg Ua Yeeb Yam Zoo Sensor
MicroPython ntawm Pawg Ua Yeeb Yam Zoo Sensor

Ib qho ntawm qhov zoo tshaj plaws ntawm ESP32 microcontroller yog nws lub peev xwm los ua haujlwm MicroPython. Qhov no tuaj yeem ua tiav hauv ob txoj hauv kev: khiav tag nrho cov haujlwm Python, lossis sib cuam tshuam los ntawm daim ntawv thov console. Cov Lus Qhia no yuav ua kom pom kev siv MicroPython yog ob txoj hauv kev siv Kev Nyuaj Siab Zoo Sensor Board. Peb yuav xub xub ua piv txwv daim ntawv thov uas sau cov ntaub ntawv ntsuas qhov ntsuas los ntawm BNO_085 IMU, tom qab ntawd peb yuav siv cov phiaj xwm txuas mus rau cuam tshuam nrog hauv program Python.

Qib: Cov ntawv qhia no kwv yees qee qhov kev paub txog Python, thiab Python tau teeb tsa. Nws tseem kwv yees kev paub txog cov lus txib dav dav dav dav.

Cov Cuab Yeej: Tsuas yog cov cuab yeej peb yuav xav tau yuav yog Lub Rooj Tswjhwm Saib Xyuas Sensor, lub davhlau ya nyob twg, thiab cov phiaj xwm phiaj xwm phiaj xwm. Ntawm Mac, koj tuaj yeem siv qhov davhlau ya nyob twg. Ntawm lub tshuab Windows, koj yuav tsum rub tawm thiab teeb tsa lub davhlau ya nyob twg. Rau serial console. Putty ib txwm yog qhov kev xaiv zoo.

Kauj ruam 1: Tau txais Firmware thiab Libraries

Txhawm rau pib, peb yuav tsum rub tawm cov kev cai tsim los ntawm Complex Arts thiab tom qab ntawd nyem nws mus rau Sensor Board. Cov firmware tuaj yeem pom ntawm no:

Rub tawm cov ntaub ntawv firmware.bin thiab muab tso rau hauv daim nplaub tshev uas koj xaiv. Koj kuj tseem yuav xav tau Txoj Haujlwm Piv Txwv Piv Txwv li no, yog li yuav ua tau tam sim no; mus rau: https://github.com/ComplexArts/SensorBoardPython thiab git clone lossis rub mus rau qhov chaw koj xaiv.

Thaum koj tau txais cov ntaub ntawv, peb yuav xav tau ob peb pob rau cuam tshuam nrog ESP32. Thawj pob peb yuav xav tau yog esptool.py. Txhawm rau nruab nws, tsuas yog ntaus

pip nruab esptool

hauv lub davhlau ya nyob twg.

Thaum esptool raug teeb tsa, peb tuaj yeem tshem tawm tom qab rov nyem lub nti. Txhawm rau ua li ntawd, nkag mus

esptool.py --chip esp32 --port COM4 lwv_flash

rau qhov chaw nres nkoj, nkag mus rau qhov chaw nres nkoj txuas uas ua ke nrog Sensor Board. Ntawm Mac, uas yuav zoo ib yam li --port /dev /ttyUSB0

Thaum qhov no ua tiav, peb yuav nyem lub nti nrog:

esptool.py --chip esp32 --port COM4 --baud 460800 write_flash -z 0x1000 firmware.bin

Ib zaug ntxiv, hloov chaw nres nkoj raws li.

Kauj Ruam 2: Ua Haujlwm Nrog MicroPython

Ua haujlwm nrog MicroPython
Ua haujlwm nrog MicroPython

Yog tias peb tshuaj xyuas cov ntawv tso tawm ntawm Sensor Board ntawm lub sijhawm no, peb yuav pom Python REPL (nyeem-ntsuas-luam tawm lub voj: >>>) Txhawm rau ua qhov no, peb yuav xav tau qhov kev pabcuam txuas ntxiv. Putty yog qhov kev xaiv zoo raws li nws muab kev xaiv rau SSH thiab telnet, tab sis kuj tseem muaj kev sib txuas lus yooj yim raws li peb yuav ua ntawm no. putty.org. Thaum koj tau teeb tsa qhov ntawd, qhib nws thiab xaiv "Serial" nyob rau hauv "Hom Kev Sib Txuas:" Koj yuav tsum tau ntaus hauv tib lub npe chaw nres nkoj uas koj tau nkag rau esptool saum toj no, tom qab ntawd baud tus nqi ntawm 115200 rau Kev Ceev. Mus tom ntej thiab nyem "Qhib". Thiab muaj Python!

Tam sim no peb yuav xav upload thiab khiav peb tus piv txwv piv txwv. Txhawm rau ua qhov ntawd, mus rau daim nplaub tshev uas koj tau khaws tseg ua ntej SensorBoardPython piv txwv. Peb yuav xav tau Adafruit qhov txaus ampy pob. Koj tuaj yeem nruab qhov ntawd nrog:

pip nruab adafruit-ampy = 0.6.3

Thaum koj muaj nws, siv ampy txhawm rau rub tus piv txwv ntsuas mus rau pawg thawj coj:

ampy -p COM4 muab accelerometer.py

(hloov chaw nres nkoj raws li, tau kawg). Tam sim no rov pib dua koj lub rooj tsavxwm nrog khawm rov pib dua. Peb yuav rov qab mus rau Putty ntawm qhov no thiab ntawm >>> sai, ntaus ntawv

ntshuam accelerometer

Viola! Tam sim no koj tab tom khiav qhov accelerometer.py code ntawm Sensor Board! Txoj cai yuav khiav rau 20 vib nas this, tom qab ntawd nres. Daim ntawv ceeb toom tias thaum tus lej ntsuas tus lej ua haujlwm, lub xiav LED ntawm lub rooj tsavxwm ntsais muag. Txog rau cov paub ntau dua nrog Python, koj yuav pom qhov no ua tiav yam tsis muaj xov thiab tsis ncua (). Qhov ntawd yog vim siv Python lub tsev qiv ntawv asyncio, uas muab txoj hauv kev zoo rau kev ua haujlwm ib txhij thiab muaj txiaj ntsig zoo ntawm kev teeb tsa platform xws li ESP32. Yog tias koj tsis paub nrog nws, nws tsim nyog txheeb xyuas; muaj cov lus qhia zoo ntawm no: https://github.com/peterhinch/micropython-async/b… (tab sis ceeb toom, nws 'taub hau me ntsis).

Kauj Ruam 3: MicroPython Hla Serial

Rov qab mus rau txoj haujlwm ntawm tes! Thaum tus lej ntsuas qhov ntsuas nres, koj yuav pom Python >>>. Tam sim no peb tuaj yeem cuam tshuam cov phiaj xwm siv Sensor Board ua peb tus neeg txhais lus Python. Txhawm rau ua li ntawd, nkag mus

>> x = np

>> y = 11

>> x + y

21

Thaum qhov no yog qhov piv txwv yooj yim tshaj plaws, peb tuaj yeem pib tsim ntau txoj cai siv Complex Arts cov tsev qiv ntawv los ua qhov pib. Qhov no tso cai rau koj los ntsuas qhov ntsuas thiab txav ntawm ya, nrog kev tswj lub sijhawm tiag. Nrog GPIO pins muaj nyob ntawm Sensor Board, koj tuaj yeem npaj tau yooj yim txuas servos, teeb, ntsuas, lub cev muaj zog, lossis ib tus lej ntawm lub cev, siv lawv ob qho tib si sib tham, lossis dhau los ntawm Python program. Muaj kev lom zem!

Yog xav paub ntxiv, txheeb xyuas lwm cov peev txheej no:

complexarts.net/home/

complexarts.net/docs/bno085/

Pom zoo: