Cov txheej txheem:

MicroPython ntawm SPIKE Prime: 12 Kauj Ruam
MicroPython ntawm SPIKE Prime: 12 Kauj Ruam

Video: MicroPython ntawm SPIKE Prime: 12 Kauj Ruam

Video: MicroPython ntawm SPIKE Prime: 12 Kauj Ruam
Video: Вводный урок по программированию ESP32, ESP8266 на MicroPython 2024, Kaum ib hlis
Anonim
MicroPython ntawm SPIKE Prime
MicroPython ntawm SPIKE Prime

Koj tuaj yeem ua tus lej SPIKE Prime siv MicroPython uas yog ntu me me ntawm nab nab rau me me microprocessors.

Koj tuaj yeem siv ib lub davhlau ya nyob twg emulator rau code SPIKE Prime hub.

Khoom siv

SPIKE Prime hub

Khoos phis tawj nrog USB Port / bluetooth

USB cable txuas lub hub rau lub khoos phis tawj

Kauj ruam 1: Khiav Terminal Emulator

Rub lub Terminal Emulator
Rub lub Terminal Emulator
Khiav Terminal Emulator
Khiav Terminal Emulator

Muaj ntau txoj kev xaiv los ntawm.

CoolTerm ua haujlwm ntawm txhua lub platform, suav nrog Pi

Putty ua haujlwm ntawm lub qhov rais

screen hais kom ua hauv Terminal ntawm lub unix operating system

Kauj Ruam 2: Txuas SPIKE Prime rau USB Port

Txuas SPIKE Prime rau USB Port
Txuas SPIKE Prime rau USB Port
Txuas SPIKE Prime rau USB Port
Txuas SPIKE Prime rau USB Port

Siv lub microUSB cable txuas SPIKE Prime rau lub khoos phis tawj.

Kauj Ruam 3: Nrhiav Chaw Nres Nkoj

Nrhiav Chaw nres nkoj
Nrhiav Chaw nres nkoj
Nrhiav Chaw nres nkoj
Nrhiav Chaw nres nkoj

Peb yuav tsum paub dab tsi qhov chaw nres nkoj txuas SPIKE Prime hub txuas nrog.

Hauv mac, ntaus ntawv

ls /dev/tty.usbmodem*

Ntawm lub pc, saib hauv koj tus thawj tswj ntaus ntawv hauv qab kab ntawv kom pom cov chaw nres nkoj twg koj tau txuas nrog

Ntawm pi, nws yuav yog qee yam xws li ttyAMC0 - txheeb xyuas hauv koj /dev /nplaub tshev

Kauj ruam 4: Txuas Txuas

Txuas Txuas
Txuas Txuas
Txuas Txuas
Txuas Txuas

Txuas mus rau qhov chaw nres nkoj raug (los ntawm cov kauj ruam dhau los) ntawm 115200 baud

Hauv Terminal, ntaus ntawv

usercomputer $ screen / dev / 115200

Hauv lwm qhov IDE, ntaus qhib/ txuas (tom qab teeb tsa cov chaw nres nkoj thiab baudrates)

Nco tseg: tsis muaj qhov sib npaug, 8 cov ntaub ntawv me me, thiab 1 nres me ntsis

Kauj Ruam 5: Pib REPL

Pib REPL
Pib REPL
Pib REPL
Pib REPL
Pib REPL
Pib REPL

Thaum koj txuas rau SPIKE Prime los ntawm lub davhlau ya nyob twg/ PUTTY koj yuav pom cov kwj ntawm cov lej thiab cov cim. Cov no yog cov ntaub ntawv los ntawm sab hauv lub cim xeeb ntawm SPIKE Prime hub. Txhawm rau pib nias tswj + c

Nws yuav cuam tshuam qhov chaw nres nkoj thiab koj yuav tsum pom qee yam zoo li no.

MicroPython v1.9.4-1146-gca9944357 ntawm 2019-09-25; LEGO Technic Loj Hub nrog STM32F413xx Hom "pab ()" kom paub ntau ntxiv.

Tam sim no koj npaj txhij rau code.

Kauj Ruam 6: Koj Thawj Txoj Cai

Koj Thawj Txoj Cai
Koj Thawj Txoj Cai

ntshuam hub

hub.display.show ('Tufts')

Pom qhov "ntshuam" hais kom ua - uas rub hauv lub tsev qiv ntawv nab nab uas cia koj tham nrog SPIKE Prime. Koj yuav tsum pom Tufts sau rau ntawm LED matrix ntawm lub hub.

Kauj Ruam 7: Qhia Koj Lub Npe

tam sim no sim ntaus ntawv

hub.display.show ('')

nco ntsoov tias txij li koj twb tau xa cov hub saum toj no, nws twb tau nco lawm. Yog tias nws tsis yog, koj yuav tau txais qhov yuam kev xws li:

Rov qab (hu xov tooj tsis ntev los no): Cov ntaub ntawv "", kab 1, inNameError: lub npe 'hub' tsis tau txhais

Kauj Ruam 8: Siv REPL

Ib qho ntawm cov yam ntxwv muaj zog ntau dua ntawm Python yog tias koj tuaj yeem sim txhua yam tawm ua ntej sau cov cai hauv REPL (nyeem ntsuas ntsuas luam tawm lub voj).

Nws yuav ua ib qho lus txib nab nab - sim ntaus 2 + 2 hauv qab no thiab saib nws hais dab tsi:

2+2

Kauj Ruam 9: Tshawb MicroPython ntawm SPIKE Prime

Tam sim no nws yog lub sijhawm los tshawb nrhiav.

hub muaj ntau txoj haujlwm - koj tuaj yeem paub los ntawm kev ntaus "hub." (tsis txhob hnov qab lub sijhawm tom qab lub hub) thiab tom qab ntawd tsoo tus lej TAB hauv REPL. Qhov ntawd yuav qhia koj txhua txoj hauv kev sib txawv uas koj tuaj yeem ua tiav cov lus txib.

Kev sib tw: Saib seb koj puas tuaj yeem nyeem nrawm dua.

Kauj Ruam 10: Nyeem Sensor Qhov Muaj Nqes… 1

Cov ntaub ntawv nrawm tau rov qab los raws li qhov muaj nuj nqis. yog li yog tias koj tsuas xav tau tus nqi X, koj tuaj yeem sim

hub.motion.accelerometer () [0]

lossis txoj hauv kev zoo dua rau tus lej no yuav yog siv cov lej zoo li no:

ntshuam hub

accel = hub.motion.accelerometer () xAccel = accel [0] hub.display.show (str (xAccel))

Kauj Ruam 11: Nyeem Sensor Qhov Muaj Nqes… 2

Nyeem Ntawv Qhov Tseem Ceeb … 2
Nyeem Ntawv Qhov Tseem Ceeb … 2

Koj kuj tseem tuaj yeem tso tawm tag nrho peb qhov nrawm siv lub voj.

Peb tseem yuav ntshuam lub tsev qiv ntawv siv sijhawm kom peb tuaj yeem ncua thiab muab sijhawm rau koj los nyeem tus lej ntawm lub vijtsam.

Sim cov cai no:

ntshuam hub, utimeaccel = hub.motion.accelerometer () rau Acc hauv accel: hub.display.show (str (Acc)) utime.sleep (0.8)

Hauv qhov no, ob peb yam tseem ceeb:

qhov chaw - Python yog txhua yam hais txog kev nkag mus rau sab xis - zoo ib yam li cov kab sib dhos hauv lwm yam lus, kev nkag mus qhia rau koj paub dab tsi yog sab hauv rau lub voj thiab dab tsi tsis yog.

thaum siv REPL, koj yuav pom tias thaum koj nkag mus, nws tsis ua txoj kab ntxiv lawm tab sis tos kom koj ua tiav cov kab rau lub voj ua ntej ua tiav (thiab >>> yog hloov los ntawm …). Txhawm rau ua kom tiav rau lub voj, tsuas yog ntaus rov qab peb zaug thiab lub voj yuav ua tiav.

Kauj Ruam 12: Sib tw

Tom ntej no, saib yog tias koj tuaj yeem txheeb xyuas seb cov cai hauv qab no ua li cas - thiab sim ua nws kom pom tias koj raug.

import hub, siv

thaum muaj tseeb: accel = hub.motion.accelerometer () rau Acc hauv accel: hub.display.show (str (Acc)) utime.sleep (0.8) yog hub.port. B.device.get (): so

Hint -Koj xav tau lub sensor ntawm chaw nres nkoj B.

Pom zoo: