Cov txheej txheem:

Saib Xyuas Kev Hloov Pauv Hloov pauv Nrog Raspberry Pi thiab MMA7455 Siv Python: 6 Cov Kauj Ruam
Saib Xyuas Kev Hloov Pauv Hloov pauv Nrog Raspberry Pi thiab MMA7455 Siv Python: 6 Cov Kauj Ruam

Video: Saib Xyuas Kev Hloov Pauv Hloov pauv Nrog Raspberry Pi thiab MMA7455 Siv Python: 6 Cov Kauj Ruam

Video: Saib Xyuas Kev Hloov Pauv Hloov pauv Nrog Raspberry Pi thiab MMA7455 Siv Python: 6 Cov Kauj Ruam
Video: Saib Mis paub Poj niam (hluas nkauj) tus yam ntxwv lub siab 2024, Kaum ib hlis
Anonim
Image
Image

Kuv tsis tau mus txawv tebchaws, Kuv tab tom ntsuas lub ntiajteb txawj nqus. Nws tseem ua haujlwm…

Ib tus sawv cev ntawm qhov chaw nrawm nrawm qhia meej tias lub moos nyob rau ntawm qhov chaw siab tshaj ntawm lub dav hlau yuav tuaj nrawm dua ib qho ntawm lub hauv paus vim yog lub sijhawm nthuav dav. Qee qhov kev sib cav hais tias kev nrawm ntawm lub nkoj yuav zoo ib yam rau ob lub moos, yog li lawv yuav tsum zuam ntawm tus nqi tib yam. Muab qee qhov kev xav rau nws.

Kev xav, kev txhawb siab, thiab txawm tias cov lus qhia tuaj yeem pib los ntawm txhua qhov chaw-txawm li cas los xij thaum koj mob siab rau kev hloov pauv tshiab, nws tau txais txiaj ntsig los ntawm cov tib neeg uas mob siab rau lub ntsiab lus ntawd. Raspberry Pi, lub mini, ib lub rooj tsavxwm Linux PC, muaj cov haujlwm tshwj xeeb thiab cov tswv yim tswv yim ntawm kev npaj, phiaj xwm, thiab kev lag luam hluav taws xob. Kaw los ntawm kev ua Raspberry Pi thiab cov cuab yeej qhia kev ua haujlwm, peb tau ncaws tawm ntawm txoj hauv kev rau qhov program thiab tinker thiab ua qhov xav tsis thoob nrog Computer Science thiab Electronics squash. Peb txog thaum kawg tau muaj kev zoo siab ntawm kev txhaj tshuaj ntawm lub luag haujlwm siv lub ntsuas ntsuas thiab cov kev xav tom qab koj tuaj yeem ua dab tsi nrog lub cuab yeej no yog qhov txias heev. Yog li hauv txoj haujlwm no, peb yuav suav nrog MMA7455, 3-axis Digital accelerometer sensor, txhawm rau ntsuas kev nrawm hauv 3 qhov ntev, X, Y, thiab Z, nrog Raspberry Pi siv Python. Let's saib yog nws them tawm.

Kauj Ruam 1: Khoos Phis Tawj Peb Xav Tau

Kho vajtse Peb Xav Tau
Kho vajtse Peb Xav Tau
Kho vajtse Peb Xav Tau
Kho vajtse Peb Xav Tau

Peb paub nyuaj npaum li cas nws tuaj yeem sim thiab ua tom qab yam tsis paub tias yuav tau qhov twg, yuav npaj los ntawm qhov twg, thiab ntau npaum li cas txhua yam yuav raug nqi ua ntej. Yog li peb tau ua txhua txoj haujlwm ntawd rau koj. Thaum koj muaj cov ntu tag nrho plaub fab tseg nws yuav tsum yog lub luag haujlwm los ua txoj haujlwm no. Ua tom qab mus nrog kom tau txais cov npe ua tiav.

1. Raspberry Pi

Thawj kauj ruam tau txais Raspberry Pi board. Raspberry Pi yog pawg thawj coj saib xyuas Linux raws PC. Lub PC me me no tau ntim rau hauv kev sau npe lub zog, siv ua ib qho ntawm cov khoom siv hluav taws xob, thiab PC ua haujlwm zoo li daim ntawv nthuav dav, ua cov lus, web surfing thiab email, thiab ua si. Koj tuaj yeem yuav ib qho ntawm txhua lub tshuab hluav taws xob lossis khw nyiam ua haujlwm.

2. I2C Shield rau Raspberry Pi

Thawj qhov kev txhawj xeeb Raspberry Pi yog qhov tsis tuaj tiag yog I2C chaw nres nkoj. Yog li ntawd, TOUTPI2 I2C txuas ua rau koj nkag siab siv Raspberry Pi nrog ib qho ntawm I2C li. Nws muaj nyob ntawm DCUBE Store

3. 3-Axis accelerometer, MMA7455

Ua los ntawm Freescale Semiconductor, Inc., MMA7455 3-Axis Digital Accelerometer yog lub zog qis, qhov ntsuas me me ua lub tshuab ntsuas kom haum rau ntsuas nrawm nrog nws X, Y, thiab Z-axis. Peb tau txais qhov ntsuas no los ntawm DCUBE Store

4. Txuas Cable

Peb tau txais I2C Txuas txuas los ntawm DCUBE Store

5. Micro USB cable

Qhov me ntsis cuam tshuam, txawm li cas los xij, nruj tshaj plaws txog lub zog xav tau yog Raspberry Pi! Qhov tau teev tseg ntau tshaj thiab xav tau tsawg tshaj plaws txhawm rau tswj hwm lub tswv yim yog los ntawm kev siv Micro USB cable. Txoj hauv kev ntau dua thiab tshwj xeeb yog muab lub zog tshwj xeeb los ntawm GPIO lossis USB chaw nres nkoj.

6. Kev Txhawb Networking

Tau txais koj li Raspberry Pi cuam tshuam nrog Ethernet (LAN) cable thiab cuam tshuam nws rau koj lub network hauv tsev. Ntawm qhov tod tes, luam theej duab rau WiFi txuas thiab siv ib qho ntawm USB chaw nres nkoj kom tau mus rau lub network deb. Nws yog qhov kev txiav txim siab ntse, qhov tseem ceeb, me me thiab yooj yim!

7. HDMI Cable/Kev Nkag Mus Rau Tej Chaw

Raspberry Pi muaj qhov chaw nres nkoj HDMI uas koj tuaj yeem cuam tshuam tshwj xeeb rau lub Vijtsam lossis TV nrog HDMI cable. Xaiv, koj tuaj yeem siv SSH los tsim nrog koj li Raspberry Pi los ntawm Linux PC lossis Mac los ntawm lub davhlau ya nyob twg. Ib yam nkaus, PuTTY, pub dawb thiab qhib-qhov davhlau ya nyob twg emulator suab zoo li kev xav ntse.

Kauj Ruam 2: Txuas Cov Khoom Kho Vajtse

Txuas Kev Kho Vajtse
Txuas Kev Kho Vajtse
Txuas Kev Kho Vajtse
Txuas Kev Kho Vajtse
Txuas Kev Kho Vajtse
Txuas Kev Kho Vajtse

Ua kom lub Circuit Court raws li qhia los ntawm schematic tau tshwm sim. Hauv qhov txheej txheem, koj yuav pom kev sib txuas ntawm ntau yam khoom siv hluav taws xob, txuas xov hlau, txuas hluav taws xob, thiab I2C sensor.

Raspberry Pi thiab I2C Shield Txuas

Raws li qhov teeb meem ntawm thawj qhov tseem ceeb coj tus Raspberry Pi thiab pom I2C Shield rau nws. Nias lub Shield zoo hla GPIO pins ntawm Pi thiab peb tau ua tiav nrog qhov kev nce qib no yooj yim li ncuav qab zib (saib qhov snap).

Raspberry Pi thiab Kev Sib Txuas Sensor

Coj lub sensor thiab cuam tshuam nrog I2C cable nrog nws. Txog qhov tsim nyog ua haujlwm ntawm cov kab no, thov tshuaj xyuas I2C Cov Zais Tawm Ib txwm siv nrog I2C Kev Tawm Tswv Yim. Ib yam yuav tsum tau ua tom qab rau Raspberry Pi nrog I2C daim ntaub thaiv npog hla GPIO pins.

Peb pom zoo kom siv I2C cable raws li nws tsis lees paub qhov yuav tsum tau txhawm rau txhawm rau txhawm rau pinouts, nyab xeeb, thiab thawb ua tiav los ntawm txawm tias lub ntsej muag qias neeg tshaj plaws. Nrog qhov kev koom tes tseem ceeb thiab ua si cable, koj tuaj yeem nthuav qhia, pauv qhov tsis sib haum, lossis ntxiv ntau yam khoom siv rau hauv daim ntawv thov uas tsim nyog. Qhov no txhawb nqa qhov hnyav ua haujlwm mus txog qib siab.

Nco tseg: Cov xaim xim av yuav tsum ntseeg tau tom qab hauv av (GND) kev sib txuas ntawm cov khoom siv ntawm ib lub cuab yeej thiab cov tswv yim ntawm lwm lub cuab yeej

Kev siv Internet yog qhov tseem ceeb

Txhawm rau ua kom peb qhov kev sib tw yeej, peb xav tau Internet txuas rau peb Raspberry Pi. Txog qhov no, koj muaj lwm txoj hauv kev xws li cuam tshuam Ethernet (LAN) koom nrog hauv tsev network. Tsis tas li, ua lwm txoj hauv kev, chav kawm txaus siab yog siv WiFi USB txuas. Los ntawm thiab loj sawv cev rau qhov no, koj xav tau tus tsav tsheb kom nws ua haujlwm. Yog li yoog mus rau ib qho nrog Linux hauv kev piav qhia.

Hwj chim Mov

Txuas lub Micro USB cable rau hauv lub hwj chim nkaus ntawm Raspberry Pi. Xuas nrig thiab peb npaj txhij.

Kev Sib Txuas rau Screen

Peb tuaj yeem txuas HDMI cable txuas rau lwm Tus Saib Xyuas/TV. Qee zaum, koj yuav tsum tau mus rau Raspberry Pi yam tsis cuam tshuam nws mus rau lub vijtsam lossis koj yuav xav tau saib cov ntaub ntawv los ntawm nws los ntawm lwm qhov. Muaj peev xwm, muaj tswv yim thiab fiscally txoj hauv kev los daws nrog ua txhua yam uas tau txiav txim siab. Ib ntawm lawv yog siv - SSH (cov chaw taws teeb hais kom ua kab nkag). Koj kuj tseem tuaj yeem siv PuTTY software rau qhov ntawd.

Kauj Ruam 3: Python Coding rau Raspberry Pi

Python Coding rau Raspberry Pi
Python Coding rau Raspberry Pi

Koj tuaj yeem pom Python Code rau Raspberry Pi thiab MMA7455 Sensor hauv peb GithubRepository.

Ua ntej txuas ntxiv mus rau txoj cai, lav koj nyeem cov qauv uas tau muab hauv Readme chronicle thiab teeb tsa koj li Raspberry Pi raws li qhia los ntawm nws. Nws yuav yooj yim nyem rau ib pliag kom ua raws qhov xwm txheej tam sim no.

Tus ntsuas hluav taws xob yog lub tshuab hluav taws xob siv hluav taws xob uas yuav ntsuas lub zog nrawm. Cov hwj huam no tej zaum yuav zoo li qub, zoo ib yam li lub zog nqus ntawm koj ob txhais taw, lossis lawv tuaj yeem hloov pauv tau - coj los ntawm kev txav lossis ua kom lub nrawm nrawm.

Kev mus nrog yog tus nab npawb nab npawb thiab koj tuaj yeem clone thiab hloov cov cai hauv txhua txoj hauv kev uas koj nkag mus.

# Faib nrog daim ntawv tso cai yuav dawb.# Siv nws txhua txoj hauv kev koj xav tau, muaj txiaj ntsig lossis pub dawb, muab nws haum rau hauv daim ntawv tso cai ntawm nws cov haujlwm ua haujlwm. # MMA7455L # Tus lej no yog tsim los ua haujlwm nrog MMA7455L_I2CS I2C Mini Module muaj los ntawm dcubestore.com # https://dcubestore.com/product/mma7455l-3-axis-low-g-digital-output-accelerometer-i%C2 %B2c-mini-module/

ntshuam smbus

lub sij hawm ntshuam

# Tau I2C npav

npav = smbus. SMBus (1)

# MMA7455L chaw nyob, 0x1D (16)

# Xaiv hom tswj kev sau npe, 0x16 (22) # 0x01 (01) Hom Kev Ntsuas, +/- 8g bus.write_byte_data (0x1D, 0x16, 0x01)

sijhawm.s pw (0.5)

# MMA7455L chaw nyob, 0x1D (16)

# Nyeem cov ntaub ntawv rov qab los ntawm 0x00 (00), 6 bytes # X-Axis LSB, X-Axis MSB, Y-Axis LSB, Y-Axis MSB, Z-Axis LSB, Z-Axis MSB data = bus.read_i2c_block_data (0x1D, 0x00, 6)

# Hloov cov ntaub ntawv mus rau 10-ntsis

xAccl = (data [1] & 0x03) * 256 + data [0] if xAccl> 511: xAccl -= 1024 yAccl = (data [3] & 0x03) * 256 + data [2] if yAccl> 511: yAccl - = 1024 zAccl = (data [5] & 0x03) * 256 + data [4] if zAccl> 511: zAccl -= 1024

# Cov ntaub ntawv tso tawm rau lub vijtsam

luam "Ua kom nrawm hauv X-Axis: %d" %xAccl luam "Ua kom nrawm hauv Y-Axis: %d" %yAccl luam "Ua kom nrawm hauv Z-Axis: %d" %zAccl

Kauj Ruam 4: Txoj Cai Siv Txoj Cai

Kev Xyaum Ua ntawm Txoj Cai
Kev Xyaum Ua ntawm Txoj Cai

Rub tawm (lossis git rub) cov cai los ntawm Github thiab qhib nws hauv Raspberry Pi.

Khiav cov lus txib kom sau thiab xa cov cai hauv lub davhlau ya nyob twg thiab pom cov txiaj ntsig ntawm Screen. Noj tom qab ob peb feeb, nws yuav tso tawm ib qho ntawm qhov ntsuas. Tom qab ua kom ntseeg tau tias txhua yam ua haujlwm tau yooj yim, koj tuaj yeem siv qhov kev taug kev no txhua hnub lossis ua kom qhov kev mus ncig me ntsis ib feem ntawm txoj haujlwm tseem ceeb dua. Xijpeem koj xav tau koj tam sim no muaj ib qho kev txwv ntau ntxiv hauv koj kev sib sau ua ke.

Kauj Ruam 5: Cov ntawv thov thiab Nta

MMA7455, tsim los ntawm Freescale Semiconductor, lub zog qis ua haujlwm tau zoo 3-axis digital accelerometer tuaj yeem siv rau Sensor Cov Ntaub Ntawv Hloov pauv, Kev Taw Qhia Khoom, thiab Kev Tshawb Fawb Ntiag Tug. Nws yog qhov zoo tshaj plaws rau kev siv xws li Xov Tooj Ntawm Tes/PMP/PDA: Kev Tshawb Pom Kev Taw Qhia (Portrait/Toj roob hauv pes), Kev Ruaj Ntseg Duab, Ntawv Nyeem Ntawv, Mloog Dialing, Coj mus Mute, Laptop PC: Anti-Theft, Gaming: Motion Detection, Auto-Wake/ Pw Tsaug Rau Kev Siv Hluav Taws Xob Tsawg thiab Cov Tseem Tseem Lub Koob Yees Duab: Duab Ruaj Khov.

Kauj Ruam 6: Xaus

Yog tias koj tau xav txog txhawm rau tshawb xyuas lub ntiaj teb ntawm Raspberry Pi thiab I2C cov cim, tom qab ntawd koj tuaj yeem ua rau koj tus kheej poob siab los ntawm kev siv cov cuab yeej siv khoos phis tawj, coding, npaj, muaj ntawv tso cai, thiab lwm yam. Thaum koj tab tom sim ua kom muaj tswv yim zoo hauv koj li kev nqis peev me me, nws yeej tsis puas ntsoog mus rau lwm qhov chaw. Hauv txoj hauv kev no, tej zaum yuav muaj ob peb txoj haujlwm uas tuaj yeem ua ncaj, thaum qee leej yuav sim koj, txav koj mus. Hauv txhua qhov xwm txheej, koj tuaj yeem ua txoj hauv kev thiab tsis muaj qhov tsis zoo los ntawm kev hloov pauv thiab tsim kev tsim ntawm koj li.

Piv txwv li, Koj tuaj yeem pib nrog kev xav ntawm Gravimeter Prototype los ntsuas thaj tsam Gravitational Field ntawm Lub Ntiaj Teb nrog MMA7455 thiab Raspberry Pi siv Python. Hauv qhov kev nqis peev saum toj no, peb tau siv cov kev suav tseem ceeb. Lub hauv paus ntsiab lus ntawm kev tsim qauv yog txhawm rau ntsuas qhov hloov pauv me me hauv ntiaj teb lub ntiajteb txawj nqus ntawm 1 g. Yog li koj tuaj yeem siv lub ntsuas ntsuas no hauv ntau txoj hauv kev uas koj tuaj yeem xav txog. Lub algorithm yog txhawm rau ntsuas tus nqi ntawm kev hloov pauv ntawm lub ntiajteb txawj nqus sib nqus vector nyob rau hauv tag nrho peb qhov kev qhia ua ntu zus muab nce mus rau lub ntiajteb txawj nqus gradient tensor. Nws tuaj yeem txiav tawm los ntawm kev sib txawv tus nqi ntawm lub ntiajteb txawj nqus ntawm ob lub ntsiab lus sib cais los ntawm txoj kab ntsug me me, l, thiab faib los ntawm qhov deb no. Peb yuav sim ua qhov kev ua haujlwm ntawm cov qauv no sai dua li tom qab, kev teeb tsa, cov cai, thiab cov qauv ua haujlwm rau cov qauv ua suab nrov thiab kev ntsuas kev co. Peb ntseeg tias koj txhua tus nyiam nws!

Txog koj qhov kev nplij siab, peb muaj cov vis dis aus ntxim nyiam hauv YouTube uas tuaj yeem pab koj qhov kev xeem. Ntseeg txoj hauv kev no txoj kev tshawb nrhiav ntxiv. Yog tias lub sijhawm tsis khob, tsim lub qhov rooj.

Pom zoo: