Cov txheej txheem:

CircuitPython Nrog Itsybitsy M4 Express 1: Teeb: 9 Kauj Ruam
CircuitPython Nrog Itsybitsy M4 Express 1: Teeb: 9 Kauj Ruam

Video: CircuitPython Nrog Itsybitsy M4 Express 1: Teeb: 9 Kauj Ruam

Video: CircuitPython Nrog Itsybitsy M4 Express 1: Teeb: 9 Kauj Ruam
Video: Arduino VS CircuitPython Speed Comparison 2024, Hlis ntuj nqeg
Anonim
CircuitPython Nrog Itsybitsy M4 Express 1: Teeb
CircuitPython Nrog Itsybitsy M4 Express 1: Teeb

Tshiab rau coding? Tsuas yog siv Kos thiab xav txav mus rau cov lus sau uas muab nkag tau yooj yim rau Kev suav lub cev nrog LEDs, hloov pauv, qhia thiab ntsuas? Ces qhov no yuav yog rau koj.

Kuv tau pom tias lub xaib no muaj ntau Cov Lus Qhia txog kev coding nrog Arduinos siv Arduino IDE tab sis tsawg tsawg txog Python. Kuv tau qhia kev sau lej txij li xyoo 1968. (Rov qab los peb tau hu nws lub programming thiab siv FORTRAN IV nrog Hollerith daim npav rau kev tawm tswv yim!) Txij li hnub ntawd kuv tau siv ntau yam lus sib txawv nrog cov tub ntxhais kawm (11 xyoos rau neeg laus) suav nrog LISP, Pascal thiab ntau yam sib txawv ntawm BASIC.

Tsis ntev los no ntau lub tsev kawm ntawv hauv tebchaws Askiv tau pib siv Python hauv lawv cov kev kawm raws li cov tub ntxhais kawm ua qhov txav los ntawm 'thaiv' coding nrog Kos lossis zoo ib yam li cov ntawv sau. Nab hab sej yog qhov yooj yim nce qib dua li siv Arduino IDE. Txoj Cai CircuitPython tuaj yeem ua tiav los ntawm kev yooj yim khaws cov cai rau pawg tswj hwm kev txhim kho zoo li nws yog USB tsav. Kuv tau ua tiav siv Python rau Kev Siv Lub Cev nrog 8 txog 11 xyoos hauv kuv tus ntxhais xeeb ntxwv thawj lub tsev kawm ntawv Coding Club.

Kuv tau txiav txim siab siv Adafruit's Itsybitsy M4 Express rau Cov Lus Qhia rau cov laj thawj hauv qab no:

  • Tsis kim - qis dua $ 15 (£ 15)
  • Yooj yim teeb tsa thiab ua haujlwm nrog CircuitPython (version ntawm Python zoo tagnrho rau cov tshiab rau coding)
  • Digital Input/Output pins - nws yog qhov lom zem ua si nrog Blinkies
  • Cov koob sib piv - 12 ntsis ADC thiab DAC - qhov raug siab
  • Liab LED thiab RGB DotStar LEDs ua hauv
  • Tsav Neopixels ncaj qha
  • I2C thiab SPI txhawb nqa - rau cov ntsuas thiab ntsuas
  • Ntau tus tsav tsheb hauv lub tsev qiv ntawv nthuav dav
  • Ceev thiab muaj zog - nrawm heev ATSAMD51 Cortex M4 processor khiav ntawm 120 MHz
  • Muaj ntau lub cim xeeb - 2MB ntawm SPI Flash nco rau CircuitPython code lossis cov ntaub ntawv cov ntaub ntawv
  • Kev txhawb nqa zoo los ntawm Adafruit nrog cov ntaub ntawv pov thawj tag nrho, cov lus qhia thiab kev sib tham hauv internet pab
  • Tsuas yog xav tau lub khoos phis tawj qub lossis lub khoos phis tawj - tsis muaj kev saib xyuas tshwj xeeb, keyboard, lub hwj chim lossis nas.
  • Tus neeg siv tuaj yeem hloov pauv mus rau Arduino IDE, ntawm tib lub rooj tsavxwm, thaum lawv tau txais kev paub nrog Python.

Thawj Qhov Qhia Qhia no piav qhia yuav teeb tsa koj lub rooj tsavxwm li cas thiab khiav koj thawj tsab ntawv.

Kauj Ruam 1: Yam Koj Yuav Tsum Tau Pib

Yam Koj Yuav Tsum Tau Pib
Yam Koj Yuav Tsum Tau Pib

Kho vajtse:

  • Itsybitsy M4 Express (adafruit.com, Pimoroni.com)
  • microUSB cable
  • Khoos phis tawj - lub khoos phis tawj qub yuav ua
  • Soldering hlau
  • Solder
  • Cov qhob cij
  • Poj niam header strip (Tsis teb los tau)

Software:

Mus Editor

Rub tawm Mu editor los ntawm

Nruab nws hauv koj lub computer. Yooj yim heev nrog cov lus qhia tag nrho ntawm lub xaib.

Kauj ruam 2: Txheeb xyuas tias CircuitPython raug teeb tsa

Txheeb xyuas tias CircuitPython raug teeb tsa
Txheeb xyuas tias CircuitPython raug teeb tsa

Qhib File Explorer ntawm koj lub computer.

Txuas qhov kawg me me ntawm USB cable rau hauv qhov txuas ntawm Itsybitsy.

Txuas lwm qhov kawg ntawm kab lus rau hauv USB chaw nres nkoj ntawm koj lub computer.

Koj yuav tsum pom tus tsav tshiab tshwm sim hu ua CIRCUITPY. (Yog tias tsis yog, tom qab ntawd mus rau nplooj ntawv hloov tshiab.)

Ob npaug nias boot_out thiab koj yuav tsum pom cov lus zoo li no:

Adafruit CircuitPython 3.1.1on 2018-11-02; Adafruit ItsyBitsy M4 Qhia nrog samd51g19

Qhov no qhia tau tias koj muaj qhov qub ntawm CircuitPython zoo li peb tam sim no ntawm version 4. Qhov no yuav zoo rau tam sim no, peb yuav hloov kho tom qab. Adafruit nquag txhim kho CircuitPython thiab tshaj tawm qhov hloov tshiab. Cov hloov tshiab no yooj yim heev rau nruab.

Nkag mus rau koj cov ntawv tais ceev tseg thiab tsim daim nplaub tshev tshiab hu ua Code-with-Mu hauv nws.

Pib li Mu Editor

Kauj Ruam 3: Siv Mu Editor rau Koj Thawj Txoj Haujlwm

Siv Mu Editor rau Koj Thawj Txoj Haujlwm
Siv Mu Editor rau Koj Thawj Txoj Haujlwm

Nyem rau Serial icon nyob rau sab saum toj ntawm tus khoos phis tawj. Qhov no yuav tsum qhib lub qhov rai REPL hauv qab ntawm qhov screen. Hauv qab kaum sab laug nws yuav tsum hais Adafruit. Mu tau lees paub tias CircuitPython board tau txuas nrog lub khoos phis tawj.

Tam sim no peb tuaj yeem sau peb thawj qhov haujlwm lossis tsab ntawv. Nyem tus nas nyob rau sab saud thiab ntaus hauv:

print ("Nyob zoo, Ntiaj Teb!")

Nyem rau ntawm Save icon. Xaiv CIRCUITPY tsav. Ntaus main.py hauv lub npov npe thiab nyem rau khawm Txuag.

Qhov no ua tau zoo heev. Koj tsab ntawv raug khaws tseg rau koj Itsybitsy nrog lub npe "main.py". Txhua cov ntaub ntawv nrog lub npe no tau ua tiav los ntawm pawg thawj coj. Cov txiaj ntsig los ntawm cov ntawv luam tawm tshwm nyob rau sab qis, REPL qhov rai.

Kho cov kab kab ntawv rau:

print ("\ n Nyob zoo, coder!") thiab nyem rau ntawm Save icon.

Sim ntxiv ob peb nqe lus sau zoo sib xws thiab khiav koj cov cai tshiab.

Saib koj li Itsybitsey thaum koj tso tsab ntawv. Lub teeb ntsuab DotStar mus RED thaum tsab ntawv tau txais kev cawmdim thiab rov qab mus rau GREEN.

Cia peb ua yuam kev kom pom tias muaj dab tsi tshwm sim. Tsuas yog rho tawm tus cim cim kawg thiab rov sau tsab ntawv. Tus kws kho mob qhia qhov ua yuam kev thiab cov txiaj ntsig tau qhia tawm hom kev ua yuam kev - syntax - thiab kab lej - los pab koj kho qhov yuam kev. DotStar qhia qhov ua txhaum los ntawm kev hloov xim. Xav paub ntau ntxiv txog qhov no hauv ntu tom qab.

Kho qhov yuam kev thiab khiav tsab ntawv dua.

Tam sim no peb yuav tsum khaws peb tsab ntawv qhov chaw nyab xeeb kom peb tuaj yeem siv nws tom qab.

Ob npaug nias lub tab saum toj no koj tsab ntawv. Nkag mus rau koj cov ntaub ntawv Code-nrog-Mu nplaub tshev thiab khaws koj cov ntawv nyob rau ntawd nrog cov npe siv tau zoo xws li FirstProg.py. Daim ntawv ceeb toom lub npe cov ntaub ntawv thiab txoj hauv kev tau flashed rau hauv qab ntawm tus editor.

Kauj Ruam 4: Koj Tsab Ntawv Thib Ob - Blink

Koj Tsab Ntawv Thib Ob - Blink
Koj Tsab Ntawv Thib Ob - Blink

Ntaus rau hauv tsab ntawv, txuag nws rau CIRCUITPY ua main.py thiab nyem Yog los hloov qhov qub.py.

(Ib txwm siv lub npe lub npe main.py rau koj tsab ntawv thaum khaws cia rau koj ItsyBitsy. CircuitPython tom qab ntawv sau tsab ntawv tshiab tam sim ntawd.)

Tsab ntawv ua dab tsi:

  • Kev xa cov tsev qiv ntawv rau tus pin npe ntawm lub rooj tsavxwm, lub sijhawm los tswj kev qeeb thiab kev tswj hwm tus lej digital,
  • Teeb tus pin 13 kom tso tawm qhov hluav taws xob mus rau ntawm lub nkoj liab LED
  • Khiav lub voj tsis muaj qhov kawg kom tig LED ON thiab OFF
  • Tos kom ncua qeeb kom LED ntsais muag.

Tsab ntawv muaj ntau cov lus los piav qhia txog dab tsi tshwm sim. Cov lus pib nrog tus cim##. Lawv yog rau tib neeg siv los pab qhia koj txog koj txoj kev xav thaum lub sijhawm ntawd. Cov ntawv zoo muaj ntau cov lus pom.

  1. Sim hloov qhov tseem ceeb hauv kev pw () nqe lus.
  2. Khaws lub LED rau ob zaug ntev npaum li nws tawm.
  3. Yuav ua li cas yog tias ncua sij hawm luv heev? (0.001 vib nas this)

Ob npaug nias lub tab saum toj no koj tsab ntawv thiab khaws nrog lub npe Blink.py rau koj li Code-nrog-Mu nplaub tshev.

Kauj Ruam 5: Hloov Kho Koj Li Version ntawm CircuitPython

Hloov kho koj li Version ntawm CircuitPython
Hloov kho koj li Version ntawm CircuitPython

Mus rau https://circuitpython.org/downloads hauv internet. Nyem rau ntawm daim duab ntawm Itsybitsy M4 Express (Tsis yog M0 version).

Nyem rau ntawm lub pob paj liab kom rub tawm cov ntawv. UF2.

Pib File Explorer thiab nrhiav cov ntaub ntawv. UF2

Txuas koj Itsybitsy M4 Express rau USB chaw nres nkoj thiab nrhiav nws txoj kev tsav - CIRCUITPY

Ob npaug nias lub pob pib dua me me thiab lub npe cov ntaub ntawv yuav tsum hloov mus rau ITSYM4BOOT los ntawm CIRCUITPY. Koj yuav tsum tau nyem ob zaug sai heev.

Luag cov ntaub ntawv UF2 thiab tso rau ntawm ITSYM4BOOT tsav. Cov ntaub ntawv UF2 yuav tau theej rau IBM4 pawg thawj coj thiab lub npe tsav yuav rov qab mus rau CIRCUITPY.

Xaiv CIRCUITPY tsav thiab ob npaug nias rau boot_out cov ntaub ntawv.

Koj tuaj yeem nyeem tus lej tshiab los tshuaj xyuas nws tau hloov kho tshiab.

Ua ib daim ntawv tshiab ntawm CIRCUITPY tsav hu ua lib. Peb yuav xav tau qhov no tom qab Cov Lus Qhia los tuav cov tsav tsheb rau cov ntsuas thiab ntsuas.

Rov pib dua Mu editor. Thauj koj cov ntaub ntawv main.py los ntawm IBM4 thiab khaws nws rov qab rau IBM4. Liab LED yuav tsum pib ntsais muag.

Yog tias koj ib zaug nias lub pob pib dua nws yuav rov pib dua qhov ntawv main.py.

Kauj Ruam 6: REPL

Tus REPL
Tus REPL

Lub qhov rai nyob hauv qab ntawm tus kws kho ntawv, qhib thiab tawm nrog Cov cim cim, yog ntau dua li tsuas yog lub qhov rai luam tawm.

"Kev nyeem-ntsuas loop luam tawm lub voj (REPL), tseem hais txog kev sib tham sab saum toj lossis qib lus, yog qhov yooj yim, sib tham sib tham nrog lub khoos phis tawj ib puag ncig uas siv tib tus neeg siv nkag (piv txwv li, kab lus ib leeg), ntsuas lawv, thiab xa rov qab cov txiaj ntsig. rau tus neeg siv; txoj haujlwm sau hauv REPL ib puag ncig tau ua tiav ib leeg. " (Google)

Yeej, yog tias koj sau ib nqe lus nab nab rau hauv REPL nws ua nws ib zaug. Cia peb sim nws.

Nyem koj nas hauv REPL qhov rai.

Thaum khiav koj tsab ntawv tuav tus yuam sij thiab coj mus rhaub (CTRL-C). Qhov no txwv koj tsab ntawv.

Coj mus rhaub cov yuam sij nkag mus rau REPL thiab '>>>' tam sim tshwm sim.

ntaus ntawv (4 + 100)

Tam sim ntawd rov qab los lus teb 104

Saib daim duab thiab sim ob peb ntawm koj tus kheej. (Sim +, -, *, /, // thiab %)

Sim qhov no:

>> import board

>> dir (pawg thawj coj saib)

['_class_', 'A0', 'A1', 'A2', 'A3', 'A4', 'A5', 'APA102_MOSI', 'APA102_SCK', 'D0', 'D1', 'D10', ' D11 ',' D12 ',' D13 ',' D2 ',' D3 ',' D4 ',' D5 ',' D7 ',' D9 ',' I2C ',' MISO ',' MOSI ',' RX ', 'SCK', 'SCL', 'SDA', 'SPI', 'TX', 'UART']

>>

Nov yog cov npe ntawm tus lej pin muaj nyob ntawm IBM4 pawg thawj coj

Txhawm rau rov zoo li qub nrog kev rov pib muag tsuas yog ntaus CTRL-D thiab main.py rov pib dua.

Disconnecting koj board

Nco ntsoov tshem CIRCUITPY tsav ua ntej koj txiav tawm ntawm lub khoos phis tawj. Tsis txhob rub nws tawm thaum nws xa cov ntaub ntawv.

Kauj Ruam 7: Muab tso rau ntawm ob txhais ceg

Muab tso rau ntawm ob txhais ceg
Muab tso rau ntawm ob txhais ceg
Muab tso rau ntawm ob txhais ceg
Muab tso rau ntawm ob txhais ceg

Tus txiv neej lub taub hau ntev dhau rau pawg thawj coj saib yog li txiav/txiav 2 ntawm lawv kom raug qhov ntev.

Thawb lawv mus rau hauv lub khob cij, tso IBM4 rau saum thiab muab tshuaj txhuam rau lawv. Xyuas kom lub rooj tsavxwm yog txoj hauv kev nce! (Chip rau saum)

Tsis txhob muab txiv neej lub taub hau hla saum toj. Kuv siv ib kab ntawm 5 tus poj niam lub taub hau hla saum toj kom kuv tuaj yeem siv txhua tus pin. Siv tus lej tuav tuav kab txaij ntawm lub taub hau khov kho, ze rau qhov txiav tawm. Siv lub hacksaw ntse los txiav qhov nruab nrab ntawm lub qhov - cov tooj dag txuas yuav poob thaum koj txiav. Ua daim ntawv txiav ntug kom ua tiav zoo - tsis muaj zawj..

Soldering ntawm tus pin tsis nyuaj. Saib ntawm Arduino thiab Electronics cov chav kawm yog tias koj tsis tau siv cov hlau txuas ua ntej. Kev muaj peev xwm tuaj yeem txhais tau tias koj tuaj yeem ua kom zoo ntawm cov ntawv ntev ntawm koj cov phiaj xwm ntawm kab laug sab thiab tom qab ntawd rov qab siv lub khob cij.

Txhawm rau pab tiv thaiv lub rooj tsavxwm kom sov dhau kuv hais kom koj tsis txhob txhuam ib sab thiab nce mus rau lwm qhov. Tawm qhov khoob thiab sau tom qab. ie pins 10, RX, 2, A3, RS, BAT, 9, MI …… thiab lwm yam

Kauj Ruam 8: CircuitPython RGB Status Light - los Pab Koj Pom Qhov Yuam Kev

CircuitPython RGB Teeb Pom Kev Zoo - los Pab Koj Pom Qhov Yuam Kev
CircuitPython RGB Teeb Pom Kev Zoo - los Pab Koj Pom Qhov Yuam Kev

ItsyBitsy M4 Express, thiab ntau lwm M0 thiab M4 cov laug cam txhua tus muaj NeoPixel lossis DotStar RGB LED ntawm lub rooj tsav xwm uas qhia txog xwm txheej ntawm CircuitPython. Ntawm no nws nyob nruab nrab ntawm (C) thiab tus pin A0.

Nov yog cov xim thiab ntsais muag txhais li cas:

  • GREEN khov kho: code.py (lossis code.txt, main.py, lossis main.txt) tab tom khiav
  • pulsing GREEN: code.py (thiab lwm yam) tau ua tiav lossis tsis muaj
  • YELLOW khov kho thaum pib: (4.0.0-alpha.5 thiab tshiab dua) CircuitPython tab tom tos kom rov pib dua los qhia tias nws yuav tsum pib hauv kev nyab xeeb
  • pulsing YELLOW: Circuit Python nyob rau hauv hom nyab xeeb: nws poob thiab rov pib dua
  • DAWB DAWB: REPL tab tom khiav
  • BLUE khov kho: boot.py tab tom khiav

Cov xim uas muaj ntau qhov muag tom qab qhia qhov kev zam sej thiab tom qab ntawd qhia tus lej kab ntawm qhov ua yuam kev. Cov xim ntawm thawj nyem qhia txog hom kev ua yuam kev:

  • GREEN: IndentationError
  • CYAN: SyntaxError
  • LUS QHIA: NpeError
  • ORANGE: OSError
  • PURPLE: ValueError
  • YELLOW: lwm qhov yuam kev

Cov no yog ua raws los ntawm qhov qhia qhov qhia tus lej kab, suav nrog qhov chaw. WHITE flashes yog txhiab qhov chaw, XIAV yog pua qhov chaw, YELLOW yog kaum qhov chaw, thiab CYAN yog ib qho chaw. Yog li, piv txwv li, qhov ua yuam kev ntawm kab 32 yuav nyem YELLOW peb zaug thiab tom qab ntawd CYAN ob zaug. Zeroes tau qhia los ntawm qhov tsaus ntuj ntev ntxiv.

Cov no nyuaj heev rau suav. Ib txwm muaj lub qhov rai REPL qhib thaum tsim tsab ntawv thiab cov lus yuam kev, ua lus Askiv, yuav tshwm rau ntawd.

Kauj Ruam 9: Nrhiav Yav Tom Ntej - Ntxiv rau Koj

Nrhiav rau pem hauv ntej - Tshaj rau koj
Nrhiav rau pem hauv ntej - Tshaj rau koj

Thaum kuv pib qhov Kev Qhia Kuv xav tias nws yuav yog thawj qhov ntawm kev tshawb nrhiav CircuitPython thiab Kev Siv Lub Cev. Kuv txoj kev npaj rau tom ntej yog txhawm rau suav cov tswv yim yooj yim thiab tso tawm nrog cov lej, LEDs, hloov pauv, potentiometers thiab cov lus hais tawm. Nws tseem yuav npog cov txheej txheem looping thiab cov npe (arrays).

Ua ntej kuv sau nws kuv tau thov qee qhov kev tawm tswv yim, yog li kuv tuaj yeem txiav nws rau cov neeg mloog.

Yam khoom kuv xav paub yog:

  • Puas yog qhov nrawm?
  • Puas yog qhov nthuav dav ntau dhau, tsawg dhau lossis hais txog txoj cai?
  • Koj puas xav tau qee qhov kev xyaum ua?

Ntxiv rau koj.

Pom zoo: