Cov txheej txheem:

Pib Nrog MicroPython ntawm ESP8266: 10 Cov Kauj Ruam (nrog Duab)
Pib Nrog MicroPython ntawm ESP8266: 10 Cov Kauj Ruam (nrog Duab)

Video: Pib Nrog MicroPython ntawm ESP8266: 10 Cov Kauj Ruam (nrog Duab)

Video: Pib Nrog MicroPython ntawm ESP8266: 10 Cov Kauj Ruam (nrog Duab)
Video: Raspberry Pi Pico для робототехники 2024, Kaum ib hlis
Anonim
Pib Nrog MicroPython ntawm ESP8266
Pib Nrog MicroPython ntawm ESP8266

Koj puas xav tau txoj hauv kev sib txawv los teeb tsa ESP8266-based cov laug cam ntau dua li txoj hauv kev siv Arduino IDE nrog rau C/C ++ programing language?

Hauv qhov kev qhia no peb yuav kawm paub leej twg teeb tsa thiab tswj hwm ESP8266 pawg thawj coj siv MicroPython.

ZOO TSHAJ PLAWS: 60 QHOV TSEEB QHOV TSEEB: RATING: Yooj yim

Kauj Ruam 1: MicroPython yog dab tsi?

MicorPython yog ib ntawm ntau hom lus programming uas peb tuaj yeem siv los ua haujlwm ESP8266 tus qauv. Nws yog cov ntawv ntshiv thiab nrawm ntawm Python 3 cov lus programming thiab muaj ntau qhov zoo ntawm cov lus ib txwm siv xws li C thiab C ++.

MicroPython tau tsim los kom sib haum nrog Python li qub kom ntau li ntau tau. Nws tau ua tiav Python compiler thiab runtime, thiab muab kev sib tham sib tham tam sim hu ua REPL (Read-Eval-Print Loop).

MicorPython tau tsim los txhawb ob peb hom microcontrollers sib txawv. Tab sis rau qhov kev qhia no kuv yuav ua haujlwm nrog ib tus qauv xwb: ESP8266-based board (NodeMCU). Nco ntsoov tias muaj ob peb lub rooj sib txawv uas koj tuaj yeem yuav nrog tib lub nti.

Nyeem & Cov peev txheej:

MicroPython

NodeMCU

Kauj ruam 2: Yuav tsum tau ua

Yuav tsum muaj
Yuav tsum muaj
Yuav tsum muaj
Yuav tsum muaj
Yuav tsum muaj
Yuav tsum muaj
Yuav tsum muaj
Yuav tsum muaj

Txhawm rau tuaj yeem ua raws cov lus qhia no koj tsuas yog yuav tsum muaj kev paub ua lej yooj yim nrog Python. Koj tsis tas yuav muaj kev paub dhau los ntawm microcontrollers, hluav taws xob, lossis txawm tias MicroPython.

Koj tseem yuav xav tau lub khoos phis tawj Windows, Mac lossis Linux nrog lub chaw nres nkoj USB dawb, raws li koj yuav txuas lub microcontroller rau koj lub khoos phis tawj los teeb tsa nws.

Qhov Yuav Tsum Tau:

1 x NodeMCU (lossis lwm yam ESP8266-based board)

1 x Liab 5mm LED

1 x 220Ω 1/4W Resistor

1 x 10KΩ Teb Potentiometer

1 x Breadboard

1 x USB rau MicroUSB cable

Jumper Hlau.

Kauj Ruam 3: Vim Li Cas ESP8266 Raws li pawg thawj coj saib?

Vim li cas ESP8266 Raws li pawg thawj coj saib?
Vim li cas ESP8266 Raws li pawg thawj coj saib?

Ib txoj hauv kev koj tuaj yeem tau txais txiaj ntsig ntau tshaj ntawm koj li ESP8266 yog siv MicroPython. Tsis tas li, ESP8266 tus qauv yog ib lub platform zoo tshaj plaws uas yuav kawm paub siv MicroPython li cas. Qhov no vim tias ESP8266 muab qhov yooj yim GPIO tus lej tswj kev ua haujlwm nrog rau kev ua haujlwm tsis muaj zog, tso cai rau koj sim txhua yam ntawm MicroPython programming lus.

ESP8266 nti yog nrov nyob rau hauv qhov qhib kev txhim kho kev lag luam. Muaj ntau qhov kev txhim kho cov laug cam los ntawm cov tuam txhab sib txawv uas siv ESP8266 nti. MicroPython tau tsim los muab cov chaw nres nkoj dav dav uas tuaj yeem ua haujlwm ntawm feem ntau ntawm cov laug cam, nrog rau qee qhov kev txwv ntau li ntau tau. Qhov chaw nres nkoj yog ua raws Adafruit Feather HUZZAH pawg thawj coj thaum siv lwm ESP8266 cov laug cam, xyuas kom tseeb tias koj txheeb xyuas lawv cov lej thiab cov ntawv teev tseg kom koj tuaj yeem txheeb xyuas qhov sib txawv ntawm lawv thiab Adafruit Feather HUZZAH board. Txoj kev ntawd, koj tuaj yeem haum qhov sib txawv ntawm koj tus lej.

Nyeem & Cov peev txheej:

ESP8266

Adafruit Feather HUZZAH

Kauj ruam 4: Teeb Koj Lub Computer

Teeb Koj Lub Computer
Teeb Koj Lub Computer
Teeb Koj Lub Computer
Teeb Koj Lub Computer
Teeb Koj Lub Computer
Teeb Koj Lub Computer
Teeb Koj Lub Computer
Teeb Koj Lub Computer

Muaj ntau yam uas koj yuav tsum tau teeb tsa ua ntej siv MicroPython los teeb tsa koj li ESP8266 pawg thawj coj. Peb yuav dhau los ntawm cov txheej txheem teeb tsa hauv theem no. Txoj hauv kev no koj yuav paub paub teeb tsa ESP8266 pawg thawj coj los siv nrog MicroPython.

Npaj kom txhij

Txhua yam koj xav tau los ntawm qib no mus rau qib 6 yog koj li ESP8266 thiab USB cable. Txuas koj lub rooj tsav xwm ESP8266 rau koj lub computer.

Yuav ua li cas nws …

KAUJ RUAM 1: Nruab cov tsav tsheb

Yog tias koj muaj lub khoos phis tawj Linux, tom qab ntawd koj tsis tas yuav teeb tsa ib lub cuab yeej tsav tsheb rau cov tsav tsheb rau lub microcontroller kom tau txais kev lees paub tab sis nws koj muaj Mac lossis lub tshuab Windows, xav tau tus tsav tsheb los tso cai rau lub khoos phis tawj lees paub lub microcontroller raws li cov khoom siv.

www.silabs.com/products/development-tools/software/usb-to-uart-bridge-vcp-drivers.

STEP2: Nruab Python

Cov cuab yeej uas koj yuav siv los sib txuas lus nrog ESP8266 tau sau hauv Python, yog li koj yuav tsum nruab Python ntawm koj lub computer.

Yog tias koj lub khoos phis tawj tsis muab lub Python ntim ua ntej, koj tuaj yeem mus rau https://python.org txhawm rau rub tawm ib qho kev tsim tsa rau ib qho ntawm cov haujlwm ua haujlwm txhawb nqa.

STEP3: Nruab esptool thiab rshell

Nruab ob pob khoom uas yuav pab koj tswj hwm koj lub rooj tsavxwm siv pip. Ua li no qhib koj lub davhlau ya nyob twg thiab khiav

pip nruab esptool rshell

STEP4: Rub MicroPython

Rub tawm qhov tseeb MicroPython firmware.bin los ntawm qhov txuas hauv qab no:

Thaum lub sijhawm kuv sau qhov no, qhov tam sim no yog 1.11, thiab cov ntaub ntawv firmware tau hu ua esp8266-20190529-v1.11.bin

Los ntawm lub sijhawm koj ua qhov no koj yuav pom qhov tso tawm tshiab.

Kauj Ruam 5: Teeb MicroPython Nrog Esptool.py

Flashing MicroPython Nrog Esptool.py
Flashing MicroPython Nrog Esptool.py
Flashing MicroPython Nrog Esptool.py
Flashing MicroPython Nrog Esptool.py

Ua ntej flashing lub firmware tshiab rau hauv pawg thawj coj nws yog lub tswv yim zoo kom tshem tawm cov ntaub ntawv yav dhau los. Qhov no yog qee yam uas koj yuav tsum tau ua tas li kom lub firmware tshiab khiav los ntawm lub xeev huv.

Mus qhov twg koj tau tso cov ntaub ntawv.bin. Siv esptool.py los lwv lub flash.

Rau Linux:

esptool.py --port /dev /ttyUSB0 lwv_flash

Rau Windows:

esptool.py --port COM3 lwv_flash

Tej zaum koj yuav tsum tau hloov qhov chaw nres nkoj hauv koj cov lus txib mus rau qhov chaw nres nkoj uas koj ESP8266 pawg thawj coj tau txuas nrog. Yog tias koj tsis paub tus lej xov tooj ntawm koj tus ESP8266, koj tuaj yeem tshawb xyuas hauv Arduino IDE. Tsuas yog qhib IDE thiab tom qab ntawv nyem rau Cov Cuab Yeej | Chaw nres nkoj Koj yuav tsum pom qhov chaw nres nkoj ntawm koj li ESP8266 pawg thawj coj teev tseg nyob ntawd. Hloov qhov chaw nres nkoj hauv kab lus txib (/dev/ttyUSB0) nrog qhov chaw nres nkoj txuas ntawm koj lub rooj tsav xwm.

Tam sim no tias lub rooj tsavxwm tau raug lwv tag, koj tuaj yeem nyem MicroPython tsim uas koj nyuam qhuav rub tawm. Qhov no tseem ua tiav nrog esptool.py hais kom ua:

esptool.py --port /dev /ttyUSB0 --baud 460800 write_flash 0 esp8266-20190529-v1.11.bin

Cov lus txib no yuav sau cov ntsiab lus ntawm MicroPython.bin cov ntaub ntawv mus rau pawg thawj coj ntawm chaw nyob 0.

Nco ntsoov koj hloov lub npe ntawm firmware.bin cov ntaub ntawv hauv qhov hais kom ua (esp82688-2019-080529-v1.11.bin) mus rau qhov firmware uas koj rub tawm.

Thaum lub khoos phis tawj tau ua tiav tiav ntawm koj lub rooj tsav xwm ESP8266, koj tuaj yeem nkag mus rau REPL ntawm koj lub rooj tsavxwm ntawm kev txuas txuas (UART chaw nres nkoj txuas) lossis xav WiFi.

Kauj Ruam 6: Siv MicroPython REPL Nrog Rshell

Siv MicroPython REPL Nrog Rshell
Siv MicroPython REPL Nrog Rshell
Siv MicroPython REPL Nrog Rshell
Siv MicroPython REPL Nrog Rshell

Tam sim no koj npaj tau pib MicroPython ntawm koj li ESP8266 pawg thawj coj.

Qhov kuv yuav qhia koj yuav ua li cas txuas rau Python tam sim ua haujlwm ntawm koj lub khoos phis tawj no hu ua REPL, uas sawv rau "Nyeem-Txheeb Xyuas-Sau-Loop". Qhov no yog tus txheej txheem Python tam sim uas koj tau siv los pom thaum ua haujlwm nrog tus kws txhais lus Python li niaj zaus, tab sis lub sijhawm no nws yuav tau khiav ntawm koj lub rooj tsav xwm, thiab cuam tshuam nrog nws koj yuav siv txuas txuas mus rau koj lub computer. Npaj?

Txhawm rau txuas rau koj lub rooj tsavxwm thiab qhib REPL ntu, sau cov lus txib hauv qab no:

rshell --cov

Cov lus txib no yuav coj koj mus rau qhov rshell prompt. Saib daim duab saum toj no.

Yog tias koj ua raws cov lus qhia no ntawm Windows, nco ntsoov tias rshell muaj keeb kwm muaj teeb meem thaum ua haujlwm ntawm Windows.

Yog li txhawm rau txhim kho hom ntawd:

rshell -a --port COM3

Los ntawm qhov tam sim no koj tuaj yeem ua haujlwm tswj hwm cuam tshuam nrog koj lub microcontroller board, thiab tseem pib Python REPL uas koj tuaj yeem siv los cuam tshuam nrog pawg thawj coj hauv lub sijhawm tiag. Yog li tsuas yog nkag mus rau cov lus txib hauv qab no:

rov qab

Kom paub tseeb tias txhua yam ua haujlwm, ntaus kab lus Python yooj yim:

print ("Nyob Zoo Ntiaj Teb")

Kauj Ruam 7: Tswj Pins Siv MicroPython

Tswj Pins Siv MicroPython
Tswj Pins Siv MicroPython
Tswj Pins Siv MicroPython
Tswj Pins Siv MicroPython

Hauv qib no, peb yuav kawm paub tswj hwm ESP8266 pins nrog MicroPython. Txhawm rau ua qhov ntawd peb yuav los nrog teeb tsa qhov twg peb yuav hloov pauv lub xeev ntawm LED txuas nrog ESP8266 board GPIO tus pin. Qhov no yuav pab koj nkag siab yuav ua li cas tswj cov txiaj ntsig digital siv MicoPython.

Npaj kom txhij

Koj yuav xav tau cov hauv qab no los ua kom tiav STEP:

1 x NodeMCU

1 x Liab 5mm LED

1 x 220 Ω Resistor

1 x Breadboard

Jumper Hlau

Tsim

Pib los ntawm kev teeb tsa LED mus rau lub khob cij. Txuas ib kawg ntawm 220 Ω tus tiv thaiv mus rau qhov zoo ntawm LED (cov ceg zoo ntawm LED feem ntau yog siab dua ib ntawm ob txhais ceg). Txuas lwm qhov kawg ntawm tus tiv thaiv tus pin D1 ntawm ESP8266 pawg thawj coj saib. Tom qab ntawd txuas qhov tsis zoo ntawm LED mus rau GND tus pin ntawm ESP8266 pawg thawj coj saib. Kev sib txuas yog raws li qhia hauv daim duab saum toj no.

Thaum teeb tsa tiav, txuas ESP8266 lub rooj tsavxwm rau koj lub khoos phis tawj ntawm USB cable.

Yuav ua li cas nws …

Ntaus cov cai hauv qab no hauv koj li REPL:

# ntsais LED txhua 1 thib ob

def blink (tus pin = 5, lub sijhawm = 1) # ntsais ntsais ua haujlwm los ntawm tus lej pin = 5, sijhawm = 1s ntshuam tshuab # lub tshuab module tuav tus pin teeb tsa thiab hom los ntawm lub sijhawm ntshuam ntshuam # ntshuam tsaug zog rau qee qhov qeeb LED = tshuab. Pin (led_pin, tshuab. PIN. OUT) # teeb tsa LED ua OUTPUT thaum Muaj Tseeb: # khiav mus ib txhis LED.value (1) # teeb LED mus rau HIGH pw tsaug zog (sijhawm) # tos 1 thib ob los ntawm lub neej ntawd LED.value (0) # teeb LED kom LOW tsaug zog (sijhawm) # tos 1 thib ob los ntawm lub neej ntawd

Ntaus blink () hauv koj qhov kev sib tham RPEL txhawm rau ntsuas tus lej no qhov no yuav ntsais lub LED txuas nrog GPIO5 txhua 1 thib ob.

Koj tuaj yeem hloov tus pin thiab/lossis sijhawm los ntawm kev hu:

blink (tus pin =, sijhawm =)

Nias ctrl+c kom tawm ntawm txoj cai khiav.

Koj tuaj yeem siv MicroPython los nyeem cov lus nkag los ntawm kev txuas nrog ESP8266. Ua mus rau qib tom ntej kom paub yuav ua li cas.

Txheeb cov vis dis aus yog tias koj daig.

Kauj Ruam 8: Teeb LED

Fading lub LED
Fading lub LED
Fading lub LED
Fading lub LED

Hauv theem no, peb yuav kawm paub yuav kho lub teeb ci ntawm LED siv lub tshuab ntsuas hluav taws xob teb li cas. Peb yuav siv cov txheej txheem hu ua Pulse Width Modulation (PWM), nws tso cai rau peb kom dim lub LED nrog txog 256 chaw.

Daim ntawv ceeb toom: Txhua tus pin ntawm ESP8266 tuaj yeem siv ua tus PWM tus pin tshwj tsis yog GPIO16 (D0).

Npaj kom txhij:

Koj yuav xav tau cov hauv qab no los ua kom tiav STEP:

1 x NodeMCU

1 x Liab 5mm LED

1 x 50 KΩ Teb Potentiometer.

1 x Breadboard

Jumper Hlau

Tsim

Kev sib txuas yog raws li qhia hauv daim duab saum toj no: Thaum teeb tsa tiav, txuas ESP8266 lub rooj tsavxwm rau koj lub khoos phis tawj ntawm USB cable.

Yuav ua li cas nws …

Ntaus cov cai hauv qab no hauv koj li REPL:

# Fading LED txhua 0.5 los ntawm kev nyeem cov ntaub ntawv los ntawm Potentiometer

ntshuam tshuab los ntawm lub sijhawm ntshuam pw led_pin = 5 # coj tus pin POT = tshuab. ADC (0) # ADC0 tus pin LED = tshuab. Pin (coj_pin) # tsim cov khoom LED LED_pwm = tshuab. PWM (LED, freq = 500) # tsim LED_pwm khoom thiab teeb zaus mus rau 500Hz thaum Tseeb: LED_pwm.duty (POT.read ()) # tau txais tus nqi los ntawm lub lauj kaub thiab teeb nws mus rau lub luag haujlwm voj voog pw (0.5) # tos 0.5

Qhov no yuav hloov qhov ci ci ntawm LED txuas nrog GPIO 5 los ntawm kev hloov tus nqi ntawm lub hwj chim.

Nias ctrl+c kom tawm ntawm txoj cai khiav.

Txheeb cov vis dis aus yog tias koj daig.

Kauj Ruam 9: Qhov Twg Los Ntawm No?

Txog tam sim no peb tau pom yuav teeb tsa thiab ua haujlwm MicroPython ntawm ESP8266-based boards. peb tau kawm paub tswj hwm tus pin kom ntsais ib lub LED ces peb tau ntxiv lub hwj chim ntsuas kom tswj tau qhov ci ci ntawm LED siv cov txheej txheem dav tes taws los piav taw.

Tam sim no peb tuaj yeem nyeem cov ntaub ntawv los ntawm lub ntsuas cua thiab xa nws mus rau huab, peb tseem tuaj yeem tsim HTTP server uas koj tuaj yeem luam peb cov ntaub ntawv hauv lub vev xaib yooj yim, thiab lwm yam …

Qhov no muab rau peb ntau lub tswv yim ntawm Internet ntawm yam (IoT).

Kauj ruam 10: Xaus

Muaj koj muaj nws! Tawm mus thiab kov yeej lub ntiaj teb ntawm MicroPython.

yog tias koj muaj lus nug ntawm chav kawm koj tuaj yeem tawm lus.

Txhawm rau pom ntau ntxiv txog kuv cov haujlwm thov mus saib kuv tus YouTube channel:

kuv tus YouTube

myGitHub

myLinkedin

Ua tsaug rau kev nyeem cov lus qhia no ^^ thiab muaj hnub zoo.

Saib koj.

Ahmed Nouira: koj puas xav tau ntau tus thwjtim?

Pom zoo: