Cov txheej txheem:

MicroPython Program: Zais Qhov Loj ntawm Lub Vajvoog: 9 Kauj Ruam
MicroPython Program: Zais Qhov Loj ntawm Lub Vajvoog: 9 Kauj Ruam

Video: MicroPython Program: Zais Qhov Loj ntawm Lub Vajvoog: 9 Kauj Ruam

Video: MicroPython Program: Zais Qhov Loj ntawm Lub Vajvoog: 9 Kauj Ruam
Video: Raspberry Pi Pico RP2040 Programming in MicroPython, Complete Course for Beginners with Examples 2024, Kaum ib hlis
Anonim

Qhov kev sim no siv MakePython ESP8266 module, uas tso cai rau peb kawm MicroPython programming ntawm ESP8266. Qhov kev sim tswj hwm qhov loj ntawm lub voj voog ntawm lub vijtsam los ntawm kev tig lub hwj chim. Hauv cov txheej txheem, peb yuav kawm txog kev siv ADC, SSD1306 OLED zaub thiab uPyCraft IDE.

Kauj Ruam 1: Txog ADC thiab I2C

Txog ADC thiab I2C
Txog ADC thiab I2C

ADC: ADC yog Analog/Digital Converter uas hloov pauv Analog cov cim rau hauv Digital. Nyob rau pem hauv ntej tswj LED rau, PWM sab hauv, peb paub qhov sib txawv ntawm cov teeb liab digital thiab cov teeb liab sib xws. Cov cim qhia peb siv hauv lub neej txhua hnub, xws li kev siv lub teeb ci, lub suab nrov, thiab lub roj teeb hluav taws xob, yog txhua qhov txiaj ntsig zoo sib xws. Yog tias peb xav ntsuas lub teeb liab sib piv (qhov hluav taws xob, lub teeb pom kev zoo, lub suab yoj) los ntawm ib leeg-nti microcomputer thiab nthuav tawm los ntawm lub teeb liab digital, tom qab ntawd peb xav tau ADC analog digital teeb liab hloov pauv

I2C kev sib txuas lus: I2C tau siv dav rau kev tswj kev sib txuas lus nrog cov khoom siv sab hauv xws li ntsuas/ ntsuas. Kev xa cov ntaub ntawv tuaj yeem ua tiav los ntawm tsuas yog ob kab teeb liab, raws kab moos SCL thiab kab teeb liab SDA. Tsuas muaj ib lub cuab yeej tseem ceeb Master thiab ob peb Cov cuab yeej siv ntawm kab I2C. Txhawm rau kom ntseeg tau tias ob lub tsheb npav nyob rau qib siab thaum tsis ua haujlwm, SDA thiab SCL yuav tsum txuas nrog lub zog rub tawm. Tus nqi ib txwm muaj ntawm tus tiv thaiv rub yog 10K.

Kauj ruam 2: Cov khoom siv

Khoom siv
Khoom siv

Kho vajtse:

  • MakePython ESP8266 Cov
  • Potentiometer
  • Pawg mov ci
  • Dhia kab
  • USB cable

MakePython ESP8266: Muaj lub onboard OLED 1.3 'OLED module ntawm MakePython board, nrog 128x64 pixel … Ib lub pixel ntawm lub vijtsam monochrome yog lub teeb ci ci. OLED yog "kev pom tus kheej", pixel nws tus kheej yog lub teeb ci, yog li qhov sib txawv yog siab heev. Cov ntxaij vab tshaus OLED muaj I2C thiab SPI kev sib txuas lus cov txheej txheem, uas tsis sib xws kiag li vim muaj cov txheej txheem sib txawv. Hauv peb zaj lus qhia, OLED tau teeb tsa kom haum nrog I2C raws tu qauv. Module yuav khoom txuas:

Potentiometer : Potentiometer yog qhov ntsuas tau kho tau nrog peb qhov ua ntej thiab qhov tsis kam ua haujlwm uas tuaj yeem hloov kho raws li qee txoj cai kev hloov pauv. Lub hwj chim feem ntau suav nrog lub cev tiv thaiv kab mob thiab txhuam txhuam. Thaum txhuam txav mus raws lub cev tiv taus, tus nqi tiv thaiv lossis qhov hluav taws xob cuam tshuam nrog kev hloov pauv tau txais ntawm qhov tso tawm kawg.

Cov software

uPyCraft IDE

Muaj ntau cov lej & cov txheej txheem txheej txheem nrog MicroPython. Txog qhov kev qhia no, peb siv uPyCraft IDE, uas yog qhov yooj yim tshaj plaws & txoj hauv kev yooj yim rau pib hla mus rau MicroPython.

Kauj Ruam 3: Kev thaiv kab hlau

Thaiv
Thaiv
Thaiv
Thaiv
Thaiv
Thaiv

Nov yog lub voj voog yooj yim heev uas yuav tsum muaj ob peb lub xov hlau, tsuas yog peb leeg. Tsuas yog txuas VCC tus pin ntawm lub hwj chim rau 3.3v ntawm MakePython ESP8266, thiab OUT tus pin (nruab nrab) rau A0, thiab txuas GND rau ib leeg. Cov zaub OLED siv I2C kev sib txuas lus thiab pawg thawj coj tau txuas nrog yog li koj tsis tas yuav txhawj txog nws.

Kauj Ruam 4: Txhim Kho UPyCraft IDE Windows PC

Txhim kho UPyCraft IDE Windows PC
Txhim kho UPyCraft IDE Windows PC
Txhim kho UPyCraft IDE Windows PC
Txhim kho UPyCraft IDE Windows PC

Nyem qhov txuas no mus rub uPyCraft IDE rau Windows:

randomnerdtutorials.com/uPyCraftWindows.

Tom qab ob peb feeb, koj yuav tsum pom cov ntawv zoo sib xws (uPyCraft_VX.exe) hauv koj daim ntawv rub tawm

Nyem ob npaug rau cov ntawv ntawd. Lub qhov rai tshiab qhib nrog uPyCraft IDE software.

Kauj Ruam 5: Tsim Kev Sib Txuas Nrog Pawg Thawj Coj

Tsim Kev Sib Txuas Nrog Pawg Thawj Coj
Tsim Kev Sib Txuas Nrog Pawg Thawj Coj

Tom qab muaj MicroPython firmware tau teeb tsa (MicroPython Firmware twb tau teeb tsa thaum koj tau txais Makerfabs MakePython ESP8266), txuas nws mus rau koj lub computer los ntawm USB cable, ua raws cov kauj ruam:

  • Mus rau Cov Cuab Yeej> Pawg Thawj Coj thiab xaiv pawg thawj coj uas koj siv. Xaiv qhov esp8266
  • Mus rau Cov Cuab Yeej> Serial thiab xaiv qhov chaw nres nkoj com koj ESP txuas nrog (rub lub USB tsav tsheb ntawm:

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

Nias lub pob Txuas kom tsim kev sib txuas lus nrog koj pawg thawj coj.

Koj yuav pom ">>>" tshwm nyob rau hauv lub Plhaub qhov rai tom qab ua tiav kev sib txuas nrog koj lub rooj tsavxwm.

Kauj Ruam 6: Tsim Main.py Cov Ntaub Ntawv ntawm Koj Lub Rooj Tsav Xwm

Tsim Main.py Cov Ntaub Ntawv ntawm Koj Lub Rooj Tsav Xwm
Tsim Main.py Cov Ntaub Ntawv ntawm Koj Lub Rooj Tsav Xwm
Tsim Main.py Cov Ntaub Ntawv ntawm Koj Lub Rooj Tsav Xwm
Tsim Main.py Cov Ntaub Ntawv ntawm Koj Lub Rooj Tsav Xwm
  • Nias lub pob "New file" los tsim cov ntawv tshiab.
  • Nias lub pob "Save file" kom txuag tau cov ntaub ntawv ntawm koj lub computer.
  • Ib lub qhov rai tshiab qhib, sau koj cov ntaub ntawv main.py thiab khaws nws hauv koj lub computer.
  • Tom qab ntawd, koj yuav tsum pom boot.py cov ntaub ntawv hauv koj lub cuab yeej thiab tab tshiab nrog cov ntawv main.py.
  • Nyem rau "Download thiab khiav" khawm kom rub cov ntawv mus rau koj li ESP board.
  • Cov npe khoom siv yuav tsum tam sim no thauj cov ntawv main.py. Koj ESP muaj cov ntaub ntawv main.py khaws cia.

Kauj ruam 7: Ntxiv Driver File

Txij li lub vijtsam OLED siv SSD1306 tus tsav tsheb, peb yuav tsum rub tus tsav tsheb ntawm SSD1306. Koj tuaj yeem mus rau GitHub lub vev xaib txhawm rau tshawb nrhiav thiab rub tawm lub tsev qiv ntawv SSD1306 lossis nyem rau rub peb cov ntawv tsav tsheb ssd1306.py.

Tom qab rub tawm, txuag ssd1306.py mus rau workSpace cov ntawv teev npe. Tom qab ntawd, nyem qhib ssd1306.py cov ntaub ntawv thiab nyem ua haujlwm, thiab cov ntaub ntawv hauv tsev qiv ntawv tuaj yeem thauj mus rau hauv phau ntawv teev npe ntaus ntawv. Lub sijhawm no, cov ntaub ntawv hauv tsev qiv ntawv ntawm ssd1306.py tau ua tiav tiav rau hauv MakePython ESP8266, uas tuaj yeem hu nrog ntshuam ssd1306 nqe lus.

*ceeb toom: Thawj zaug koj qhib uPyCraft IDE, txoj hauv kev ua haujlwm tsis muaj. Thaum koj nyem, lub npov ua haujlwm sib tham yuav tshwm. Koj tuaj yeem tsim cov npe chaw ua haujlwm kom khaws cov neeg siv cov ntaub ntawv los ntawm kev xaiv cov npe uas koj xav khaws.

Kauj Ruam 8: Txoj Haujlwm Tseem Ceeb

Lub luag haujlwm tseem ceeb
Lub luag haujlwm tseem ceeb
Lub luag haujlwm tseem ceeb
Lub luag haujlwm tseem ceeb

Kev piav qhia cov qauv lus:

  • i2c: teeb tsa SCL thiab SDA tus pin
  • oled: tsim cov khoom OLED
  • adc.read (): Nyeem ADC cov ntaub ntawv piv txwv
  • vajvoog (): Kev kos lub voj voog ua haujlwm uas siv sqrt () ua haujlwm los xam lub vojvoog ntawm lub voj voog
  • lej.sqrt (r): Rov qab lub hauv paus cag ntawm tus lej
  • pixel (x, y, c): Kos lub ntsiab lus ntawm (x, y)
  • hline (x, y, w, c): Kos kab kab rov tav, pib ntawm (x, y), ntev w
  • vline (x, y, w, c): Kos kab ntsug, pib ntawm (x, y), nrog qhov siab ntawm w
  • oled.fill (n): Nthuav qhov screen thaum n = 0, thiab sau qhov screen thaum n> yog 0
  • oled.show (): Qhib cov zaub ua haujlwm

Koj tuaj yeem ncaj qha ntxiv cov ntawv no lossis luam nws cov ntsiab lus rau cov ntaub ntawv tsim tshiab.

Kauj Ruam 9: Cov Kev Ntsuam Xyuas

Cov Kev Ntsuam Xyuas
Cov Kev Ntsuam Xyuas

Tig lub potentiometer maj mam, raws lub moos, thiab lub voj voos ntawm lub vijtsam yuav loj dua, tig rov qab me dua.

Pom zoo: