Cov txheej txheem:

3-Axis Accelerometer, ADXL345 Nrog Raspberry Pi Siv Python: 6 Kauj Ruam
3-Axis Accelerometer, ADXL345 Nrog Raspberry Pi Siv Python: 6 Kauj Ruam

Video: 3-Axis Accelerometer, ADXL345 Nrog Raspberry Pi Siv Python: 6 Kauj Ruam

Video: 3-Axis Accelerometer, ADXL345 Nrog Raspberry Pi Siv Python: 6 Kauj Ruam
Video: How To Track Orientation with Arduino | ADXL345 Accelerometer Tutorial 2024, Hlis ntuj nqeg
Anonim
3-Axis Accelerometer, ADXL345 Nrog Raspberry Pi Siv Python
3-Axis Accelerometer, ADXL345 Nrog Raspberry Pi Siv Python

Xav txog lub cuab yeej uas tuaj yeem tshawb xyuas lub ntsiab lus uas koj Offroader tau qaij mus rau lingered. Puas yog nws yuav yog ib qho kev lom zem nyob rau hauv qhov xwm txheej uas ib tus neeg tau hloov kho thaum muaj qhov muaj peev xwm ua kom dhau? Pom tseeb yog. Nws yuav muaj txiaj ntsig tiag rau cov tib neeg uas nyiam mus ncig roob thiab kev mus ncig ua lag luam.

Tsis muaj kev poob siab, lub sijhawm muaj txiaj ntsig zoo ntawm kev ntsuas ntsuas siab, IoT nyob ntawm peb. Raws li Gadgets thiab Programming cov neeg nyiam, peb ntseeg, Raspberry Pi, lub micro Linux PC tau kho lub peev xwm muaj tswv yim ntawm tib neeg feem ntau, nqa nrog nws tawg hauv txoj hauv kev tshiab. Yog li dab tsi yog qhov tshwm sim xav tau uas peb tuaj yeem ua dab tsi thaum peb muaj Raspberry Pi thiab 3-axis Accelerometer nyob ze? Peb yuav tsum pom! Hauv txoj haujlwm no, peb yuav nkag siab qhov nrawm ntawm 3 axes, X, Y thiab Z siv Raspberry Pi thiab ADXL345, 3-axis accelerometer. Yog li peb yuav tsum tau soj ntsuam ntawm qhov kev mus ncig no los tsim lub moj khaum los ntsuas qhov ntsuas 3-seem nrawm lossis G-Force.

Kauj Ruam 1: Cov Khoos Phis Tawj Yooj Yim Peb Xav Tau

Khoos phis tawj yooj yim Peb xav tau
Khoos phis tawj yooj yim Peb xav tau
Khoos phis tawj yooj yim Peb xav tau
Khoos phis tawj yooj yim Peb xav tau
Khoos phis tawj yooj yim Peb xav tau
Khoos phis tawj yooj yim Peb xav tau

Cov teeb meem tau tsawg dua rau peb txij li peb muaj ntau tuj ntawm cov khoom dag ib ncig los ua haujlwm los ntawm. Txawm li cas los xij, peb paub yuav ua li cas nws muaj teeb meem rau lwm tus los sib sau ua qhov yog hauv lub sijhawm zoo los ntawm qhov chaw muaj txiaj ntsig thiab qhov ntawd yog qhov ncaj ncees tsis hais txog ntawm txhua lub nyiaj npib. Yog li peb yuav pab koj hauv txhua cheeb tsam. Nyeem cov hauv qab no kom tau txais cov npe ua tiav.

1. Raspberry Pi

Thawj kauj ruam tau txais Raspberry Pi pawg thawj coj. Lub khoos phis tawj me me no, siv hluav taws xob tsawg muab qhov pheej yig thiab feem ntau yooj yim rau kev lag luam hluav taws xob, Internet ntawm Yam (IoT), Lub Nroog Ntse, Kev Kawm Hauv Tsev Kawm Ntawv.

2. I2C Shield rau Raspberry Pi

Qhov tseem ceeb ntawm Raspberry Pi yog qhov tseeb uas ploj lawm yog I²C chaw nres nkoj. Yog li ntawd, TOUTPI2 I²C txuas ua rau koj nkag siab siv Rasp Pi nrog MULTIPLE I²C cov cuab yeej. Nws nkag tau yooj yim ntawm DCUBE Store

3. 3-axis accelerometer, ADXL345

Raug tsim los ntawm Cov Khoom Siv Zoo, ADXL345, yog lub zog qis 3-axis accelerometer nrog kev daws teeb meem siab 13-ntsis ntsuas ntawm ± 16g. Peb tau txais qhov ntsuas no los ntawm DCUBE Store

4. Txuas Cable

Peb muaj I2C txuas txuas txuas tau ntawm DCUBE Store

5. Micro USB cable

Qhov tsis txaus ntseeg me me, tseem ceeb tshaj plaws raws li lub zog xav tau yog Raspberry Pi! Txoj hauv kev yooj yim tshaj plaws los txhawb lub zog Raspberry Pi yog los ntawm Micro USB cable.

6. Web Access yog Qhov Xav Tau

Kev nkag mus rau lub vev xaib tuaj yeem txhawb nqa los ntawm Ethernet (LAN) cable cuam tshuam nrog lub network hauv zej zog thiab lub vev xaib. Ntawm qhov tod tes, koj tuaj yeem koom nrog lub wireless network siv USB wireless dongle, uas yuav xav tau kev teeb tsa.

7. HDMI Cable/Kev Nkag Mus Rau Tej Chaw

Nrog HDMI cable ntawm lub nkoj, koj tuaj yeem txuas nws mus rau TV digital lossis rau Monitor. Yuav tsum khaws nyiaj ntsuab! Raspberry Pi tuaj yeem nyob deb tau txais los siv cov tswv yim sib txawv xws li-SSH thiab Nkag Mus Hauv Lub Vev Xaib. Koj tuaj yeem siv PuTTYopen qhov software.

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
Txuas Kev Kho Vajtse
Txuas Kev Kho Vajtse

Ua qhov Circuit Court raws li cov txheej txheem tshwm sim. Kos tus qauv thiab ua tom qab teeb tsa txhob txwm tshaj tawm.

Kev sib txuas ntawm Raspberry Pi thiab I2C Shield

Qhov tseem ceeb tshaj txhua qhov, coj Raspberry Pi thiab pom I2C Shield rau nws. Nias lub ntaub thaiv npog kom zoo dua GPIO pins ntawm Pi thiab peb tau ua tiav nrog qhov kev nce qib no yooj yim li ncuav qab zib (saib qhov snap).

Kev sib txuas ntawm Sensor thiab Raspberry Pi

Coj lub sensor thiab cuam tshuam nrog I2C Cable nrog nws. Txog qhov tsim nyog ua haujlwm ntawm Cov Xov Tooj no, thov nco qab I2C Cov Zis Ib Leeg nrog cov I2C Tswv Yim. Ib yam yuav tsum tau ua tom qab rau Raspberry Pi nrog I2C daim ntaub thaiv npog nws GPIO pins.

Peb sau ntawv siv I2C cable raws li nws tsis lees paub qhov yuav tsum tau ua rau kev nkag mus pinouts, soldering, thiab kev tsis zoo tshwm sim los ntawm txawm tias qhov tsawg tshaj plaws blunder. Nrog qhov yooj yim ntsaws thiab ua si cable, koj tuaj yeem qhia, hloov pauv cov cuab yeej, lossis ntxiv cov cuab yeej ntxiv rau daim ntawv thov yooj yim. Qhov no ua rau tej yam tsis yooj yim.

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

Web Network yog Qhov Tseem Ceeb

Txhawm rau kom peb txoj kev sib tw yeej, peb xav tau lub vev xaib txuas rau peb Raspberry Pi. Txog qhov no, koj muaj kev xaiv zoo li cuam tshuam Ethernet (LAN) cable nrog lub tsev. Ib qho ntxiv, raws li kev xaiv, txawm li cas los xij, txoj hauv kev muaj txiaj ntsig zoo yog siv WiFi txuas. Qee lub sijhawm rau qhov no, koj xav tau tus tsav tsheb kom nws ua haujlwm. Yog li cia siab 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. Teeb nws thiab peb zoo mus.

Kev Sib Txuas rau Screen

Peb tuaj yeem muaj HDMI cable txuas nrog lwm lub vijtsam. Qee qhov xwm txheej, koj yuav tsum tau mus rau Raspberry Pi yam tsis cuam tshuam nws mus rau lub vijtsam lossis koj yuav xav tau saib qee cov ntaub ntawv los ntawm nws los ntawm lwm qhov. Xav txog, muaj cov tswv yim tshiab thiab kev paub txog nyiaj txiag los ua li ntawd. 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

Python Code rau Raspberry Pi thiab ADXL345 Sensor tuaj yeem nkag tau rau hauv peb Github Chaw Tso Khoom.

Ua ntej yuav mus tom ntej rau txoj cai, xyuas kom koj tau nyeem cov lus qhia hauv daim ntawv Readme thiab teeb tsa koj li Raspberry Pi raws li nws. Nws yuav yooj yim ncua ib pliag los ua qhov ntawd.

Tus ntsuas hluav taws xob yog lub cuab yeej ntsuas qhov ua kom nrawm; kev ua kom nrawm tsis zoo ib yam li kev ua kom nrawm nrawm (tus nqi ntawm kev hloov pauv nrawm). Ib leeg- thiab ntau lub qauv ua qauv ntawm lub ntsuas qhov ntsuas tau nkag tau los txhawm rau txheeb xyuas qhov loj thiab kev taw qhia ntawm qhov ua kom nrawm, raws li qhov muaj nuj nqis vector, thiab tuaj yeem siv rau qhov kev nkag siab, ua kom nrawm dua, kev co, poob siab, thiab poob hauv qhov nruab nrab tiv taus.

Txoj cai tau yooj yim ua ntej koj thiab nws nyob hauv cov qauv ncaj tshaj plaws uas koj tuaj yeem pom thiab koj yuav tsum tsis muaj teeb meem.

# 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. # ADXL345 # Txoj cai no yog tsim los ua haujlwm nrog ADXL345_I2CS I2C Mini Module muaj los ntawm dcubestore.com # https://dcubestore.com/product/adxl345-3-axis-accelerometer-13-bit-i%C2%B2c-mini -qauv/

ntshuam smbus

lub sij hawm ntshuam

# Tau I2C npav

npav = smbus. SMBus (1)

# ADXL345 chaw nyob, 0x53 (83)

# Xaiv tus lej bandwidth rau npe, 0x2C (44) # 0x0A (10) Hom qub, Cov ntaub ntawv tawm tus nqi = 100 Hz bus.write_byte_data (0x53, 0x2C, 0x0A) # ADXL345 chaw nyob, 0x53 (83) # Xaiv lub zog tswj npe, 0x2D (45) # 0x08 (08) Auto Pw tsaug zog kaw bus.write_byte_data (0x53, 0x2D, 0x08) # ADXL345 chaw nyob, 0x53 (83) # Xaiv cov ntaub ntawv sau npe, 0x31 (49) # 0x08 (08) Kev ntsuas tus kheej xiam oob qhab, 4-hlau interface # Kev daws teeb meem tag nrho, Range = +/- 2g bus.write_byte_data (0x53, 0x31, 0x08)

sijhawm.s pw (0.5)

# ADXL345 chaw nyob, 0x53 (83)

# Nyeem cov ntaub ntawv rov qab los ntawm 0x32 (50), 2 bytes # X-Axis LSB, X-Axis MSB data0 = bus.read_byte_data (0x53, 0x32) data1 = bus.read_byte_data (0x53, 0x33)

# Hloov cov ntaub ntawv mus rau 10-ntsis

xAccl = ((data1 & 0x03) * 256) + data0 yog xAccl> 511: xAccl -= 1024

# ADXL345 chaw nyob, 0x53 (83)

# Nyeem cov ntaub ntawv rov qab los ntawm 0x34 (52), 2 bytes # Y-Axis LSB, Y-Axis MSB data0 = bus.read_byte_data (0x53, 0x34) data1 = bus.read_byte_data (0x53, 0x35)

# Hloov cov ntaub ntawv mus rau 10-ntsis

yAccl = ((data1 & 0x03) * 256) + data0 yog yAccl> 511: yAccl -= 1024

# ADXL345 chaw nyob, 0x53 (83)

# Nyeem cov ntaub ntawv rov qab los ntawm 0x36 (54), 2 bytes # Z-Axis LSB, Z-Axis MSB data0 = bus.read_byte_data (0x53, 0x36) data1 = bus.read_byte_data (0x53, 0x37)

# Hloov cov ntaub ntawv mus rau 10-ntsis

zAccl = ((data1 & 0x03) * 256) + data0 yog 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 Sib Sau thiab Tshaj Tawm cov cai hauv lub davhlau ya nyob twg thiab pom cov khoom tso tawm ntawm Saib. Ua raws ob peb lub sijhawm, nws yuav qhia txhua qhov ntawm qhov ntsuas. Tom qab txhawm rau kom ntseeg tau tias txhua yam ua haujlwm tau yooj yim, koj tuaj yeem coj txoj haujlwm no mus rau txoj haujlwm ntau dua.

Kauj Ruam 5: Cov ntawv thov thiab Nta

ADXL345 yog qhov me me, nyias, lub zog loj, 3-axis accelerometer nrog kev ntsuas siab (13-ntsis) ntsuas txog li g 16 g. ADXL345 yog qhov tsim nyog rau Kev Siv Xov Tooj Ntawm Tes. Nws suav qhov Static Acceleration of Gravity hauv Tilt-Detecting Applications thiab ntxiv rau Dynamic Acceleration yuav los tom ntej txog vim yog Motion lossis Shock. Lwm cov ntawv thov suav nrog kev nyiam Tes, Kev siv tshuaj kho mob, Kev Ua Si thiab Cov Khoom Taw Qhia, Kev Siv Khoom Siv, Cov Khoom Siv Tus Kheej, thiab Kev Tiv Thaiv Hard Disk (HDD).

Kauj Ruam 6: Xaus

Vam tias txoj haujlwm no txhawb nqa kev sim ntxiv. Qhov ntsuas I2C no yog qhov hloov pauv tshwj xeeb, pheej yig thiab siv tau. Txij li nws yog rau qib zoo uas tsis muaj qhov tsis zoo, muaj ntau txoj hauv kev koj tuaj yeem nthuav txoj haujlwm no thiab txhim kho nws txawm tias.

Piv txwv li, Koj tuaj yeem pib nrog lub tswv yim ntawm Inclinometer siv ADXL345 thiab Raspberry Pi. Hauv txoj haujlwm saum toj no, peb tau siv cov lej yooj yim. Koj tuaj yeem tsim kho txoj cai rau G-qhov tseem ceeb, cov ces kaum ntawm txoj kab nqes (lossis qaij), nce lossis poob siab ntawm ib yam khoom nrog kev hwm rau lub ntiajteb txawj nqus. Tom qab ntawd koj tuaj yeem tshawb xyuas cov kev xaiv ua ntej zoo li cov ces kaum tig rau yob (pem hauv ntej-rau-rov qab axis, X), suab (sab-rau-sab axis, Y) thiab yaw (ntsug ntsug, Z). Qhov ntsuas qhov ntsuas no qhia txog 3-D G-Force. Yog li koj tuaj yeem siv lub ntsuas ntsuas no hauv ntau txoj hauv kev uas koj tuaj yeem xav txog.

Rau koj txoj kev nplij siab, peb muaj cov vis dis aus txaus qhia hauv YouTube uas tuaj yeem pab tawm koj qhov kev tshawb nrhiav. Ntseeg qhov kev nqis peev no txhawb kev tshawb nrhiav ntxiv. Ua tib zoo xav! Nco ntsoov nrhiav tom qab vim tias ntau ntxiv tuaj ntxiv.

Pom zoo: