Cov txheej txheem:

Motion Control With Raspberry Pi thiab LIS3DHTR, 3-Axis Accelerometer, Siv Python: 6 Kauj Ruam
Motion Control With Raspberry Pi thiab LIS3DHTR, 3-Axis Accelerometer, Siv Python: 6 Kauj Ruam

Video: Motion Control With Raspberry Pi thiab LIS3DHTR, 3-Axis Accelerometer, Siv Python: 6 Kauj Ruam

Video: Motion Control With Raspberry Pi thiab LIS3DHTR, 3-Axis Accelerometer, Siv Python: 6 Kauj Ruam
Video: Decoding Garage Door Remote Controls 2024, Hlis ntuj nqeg
Anonim
Image
Image
Khoos phis tawj yooj yim Peb xav tau
Khoos phis tawj yooj yim Peb xav tau

Kev zoo nkauj nyob ib puag ncig peb, tab sis feem ntau, peb yuav tsum taug kev hauv lub vaj kom paub nws. - Rumi

Raws li pab pawg neeg paub zoo uas peb zoo li, peb nqis peev feem ntau ntawm peb lub zog ua haujlwm ua ntej peb lub PCs thiab xov tooj ntawm tes. Yog li ntawd, peb nquag tso peb txoj kev noj qab haus huv nyob hauv chav zaum thib ob, yeej tsis muaj sijhawm tiag tiag rau lub sijhawm mus rau chav dhia ua si lossis chav kawm qoj ib ce thiab raws li txoj cai xaiv cov zaub mov nrawm dua qhov muaj txiaj ntsig ntau dua. Cov xov xwm txhawb nqa yog seb txhua yam koj xav tau yog qee qhov kev pab nrog khaws cov ntaub ntawv lossis saib xyuas koj qhov kev nce qib, koj tuaj yeem siv cov kev hloov pauv niaj hnub no los tsim qee yam khoom siv los pab koj tus kheej.

Tshuab tab tom txhim kho sai. Zoo ib yam, peb ntes cua ntawm qee qhov kev hloov pauv tshiab uas yuav hloov lub ntiaj teb thiab txoj kev peb kawm hauv nws. Thaum koj nkag mus rau hauv PCs, coding, thiab neeg hlau lossis tsuas yog nyiam tinker, muaj cov txuj ci foom koob hmoov tawm muaj. Raspberry Pi, lub micro, ib lub rooj tsavxwm Linux lub computer, tau mob siab rau txhim kho txoj hauv kev koj kawm nrog cov thev naus laus zis tshiab tab sis tseem yog tus yuam sij rau kev txhim kho kev kawm thoob ntiaj teb. Yog li cov txiaj ntsig tau tuaj yeem ua dab tsi uas peb tuaj yeem ua yog tias peb muaj Raspberry Pi thiab 3-axis Accelerometer nyob ze? Yuav ua li cas peb thiaj pom qhov no! Hauv txoj haujlwm no, peb yuav tshuaj xyuas qhov nrawm ntawm 3 txoj kab sib dhos, X, Y thiab Z siv Raspberry Pi thiab LIS3DHTR, 3-axis accelerometer. Yog li peb yuav tsum pom ntawm txoj kev taug no los tsim cov kab ke txhawm rau txheeb xyuas 3-dimensional acceleration nce 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

Cov teeb meem tau tsawg dua rau peb vim tias peb muaj cov khoom loj nyob ib puag ncig los ua haujlwm los ntawm. Txawm li cas los xij, peb paub tias nws nyuaj rau lwm tus li cas los sau qhov yog hauv lub sijhawm tsis huv los ntawm qhov chaw muaj txiaj ntsig thiab qhov ntawd tiv thaiv them nyiaj mloog me ntsis rau txhua txhua penny. Yog li peb yuav pab koj. Ua raws cov ntawv txuas nrog kom tau txais cov npe ua tiav.

1. Raspberry Pi

Thawj kauj ruam tau txais Raspberry Pi board. Raspberry Pi yog ib leeg-board Linux raws PC. Lub PC me me no tau ntim rau hauv kev suav lub zog, siv los ua ib feem ntawm cov khoom siv ua haujlwm, thiab kev ua haujlwm yooj yim xws li daim ntawv nthuav qhia, kev npaj lo lus, kev tshuaj xyuas lub vev xaib thiab email, thiab kev ua si.

2. I2C Shield rau Raspberry Pi

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

3. 3-axis accelerometer, LIS3DHTR

LIS3DH yog qhov ua tau zoo tshaj plaws uas tsis muaj zog ua haujlwm tau zoo peb txoj kab ua haujlwm linear accelerometer uas yog tsev neeg "nano", nrog digital I2C/SPI cov qauv txheej txheem cuam tshuam. 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 tsawg tshaj plaws ua rau xav tsis thoob, tseem nruj tshaj qhov xav tau lub zog yog Raspberry Pi! Txoj hauv kev yooj yim tshaj plaws yog los ntawm kev siv Micro USB cable.

6. Web Access yog Qhov Xav Tau

INTERNET menyuam tsis txhob pw

Tau txais koj li Raspberry Pi cuam tshuam nrog Ethernet (LAN) cable thiab txuas nws rau koj lub network router. Xaiv, tshawb rau WiFi txuas thiab siv ib qho ntawm USB chaw nres nkoj kom tau mus rau qhov chaw nyob deb. Nws yog qhov kev txiav txim siab zoo, yooj yim, me me thiab tsis zoo!

7. HDMI Cable/Kev Nkag Mus Rau Tej Chaw

Raspberry Pi muaj qhov chaw nres nkoj HDMI uas koj tuaj yeem txuas tshwj xeeb rau lub vijtsam lossis TV nrog HDMI cable. Xaiv, koj tuaj yeem siv SSH koom nrog koj li Raspberry Pi los ntawm Linux PC lossis Macintosh los ntawm lub davhlau ya nyob twg. Ib yam nkaus, PuTTY, pub dawb thiab qhib-qhov davhlau ya nyob twg emulator suab zoo li lwm txoj hauv kev.

Kauj Ruam 2: Txuas Cov Khoom Kho Vajtse

Txuas Cov Khoom Kho Vajtse
Txuas Cov Khoom 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 ib daim duab thiab ua tom qab tus qauv qhia meej.

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 pom zoo siv I2C cable vim nws tsis lees paub qhov tsim nyog rau kev tshuaj xyuas pinouts, nrawm, thiab tsis xis nyob los ntawm txawm tias qhov ntsia hlau me me tshaj plaws. Nrog rau qhov txuas txuas tseem ceeb thiab ua si cable, koj tuaj yeem nthuav qhia, pauv cov khoom siv, lossis ntxiv ntau yam khoom siv rau hauv daim ntawv thov kom zoo. Qhov no pab txhawb qhov hnyav ua haujlwm mus txog qib tseem ceeb.

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 qhov kev sib tw yeej, peb xav tau kev sib koom Internet rau peb Raspberry Pi. Txog qhov no, koj muaj kev xaiv zoo li cuam tshuam Ethernet (LAN) cable koom nrog hauv tsev network. Tsis tas li ntawd, raws li lwm txoj hauv kev, ua raws li nws tuaj yeem ua tau, chav kawm haum yog siv WiFi USB txuas. Raws li txoj cai 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 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. Cov no yog rau cov neeg siv qib siab. Yog li cov ntsiab lus tsis suav nrog ntawm no.

Kauj Ruam 3: Python Coding rau Raspberry Pi

Python Coding rau Raspberry Pi
Python Coding rau Raspberry Pi

Python Code rau Raspberry Pi thiab LIS3DHTR Sensor tuaj yeem nkag tau hauv peb GithubRepository.

Ua ntej txuas mus rau txoj cai, xyuas kom koj nyeem cov cai tau muab hauv Readme cov ntawv khaws tseg thiab teeb tsa koj li Raspberry Pi raws li nws. Nws yuav cia li so rau ib pliag kom ua txhua yam xav tau.

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.

Cov ntawv txuas nrog yog tus nab npawb nab npawb thiab koj tuaj yeem clone thiab kho 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. # LIS3DHTR # Tus lej no yog tsim los ua haujlwm nrog LIS3DHTR_I2CS I2C Mini Module muaj los ntawm dcubestore.com # https://dcubestore.com/product/lis3dhtr-3-axis-accelerometer-digital-output-motion-sensor-i%C2 %B2c-mini-module/

ntshuam smbus

lub sij hawm ntshuam

# Tau I2C npav

npav = smbus. SMBus (1)

# LIS3DHTR chaw nyob, 0x18 (24)

# Xaiv tswj kev sau npe 1, 0x20 (32) # 0x27 (39) Hwj chim ON hom, Cov ntaub ntawv xaiv tus nqi = 10 Hz # X, Y, Z-Axis qhib bus.write_byte_data (0x18, 0x20, 0x27) # LIS3DHTR chaw nyob, 0x18 (24)) # Xaiv tswj kev sau npe 4, 0x23 (35) # 0x00 (00) Hloov tshiab tas li, Kev xaiv tag nrho = +/- 2G npav.write_byte_data (0x18, 0x23, 0x00)

sijhawm.s pw (0.5)

# LIS3DHTR chaw nyob, 0x18 (24)

# Nyeem cov ntaub ntawv rov qab los ntawm 0x28 (40), 2 bytes # X-Axis LSB, X-Axis MSB data0 = bus.read_byte_data (0x18, 0x28) data1 = bus.read_byte_data (0x18, 0x29)

# Hloov cov ntaub ntawv

xAccl = data1 * 256 + data0 yog xAccl> 32767: xAccl -= 65536

# LIS3DHTR chaw nyob, 0x18 (24)

# Nyeem cov ntaub ntawv rov qab los ntawm 0x2A (42), 2 bytes # Y-Axis LSB, Y-Axis MSB data0 = bus.read_byte_data (0x18, 0x2A) data1 = bus.read_byte_data (0x18, 0x2B)

# Hloov cov ntaub ntawv

yAccl = data1 * 256 + data0 yog yAccl> 32767: yAccl -= 65536

# LIS3DHTR chaw nyob, 0x18 (24)

# Nyeem cov ntaub ntawv rov qab los ntawm 0x2C (44), 2 bytes # Z-Axis LSB, Z-Axis MSB data0 = bus.read_byte_data (0x18, 0x2C) data1 = bus.read_byte_data (0x18, 0x2D)

# Hloov cov ntaub ntawv

zAccl = data1 * 256 + data0 yog zAccl> 32767: zAccl -= 65536

# 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: Qhov Ua Tau Zoo ntawm Txoj Cai

Kev Ua Haujlwm Ntawm Txoj Cai
Kev Ua Haujlwm 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 qhia txhua tus ntawm qhov ntsuas. Tom qab lav paub tias txhua yam ua haujlwm tau yooj yim, koj tuaj yeem coj qhov kev twv no mus rau qhov ua tau zoo dua.

Kauj Ruam 5: Cov ntawv thov thiab Nta

Kev tsim khoom los ntawm STMicroelectronics, LIS3DHTR muaj cov neeg siv tau xaiv cov nplai ntawm g 2g/± 4g/± 8g/± 16g thiab nws muaj peev xwm ntsuas kev nrawm nrog cov ntaub ntawv tso tawm tus nqi los ntawm 1Hz txog 5kHz. LIS3DHTR tsim nyog rau Motion activated functions thiab Free-Fall Detection. 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 daim ntawv thov suav nrog qhov Nyiam/Nyem Nyem Ob Leeg Paub, Kev Txawj Ntse Lub Hwj Chim Rau Cov Cuab Yeej Siv Tes, Pedometer, Cov Lus Taw Qhia, Kev Ua Si Thiab Kev Ua Si Virtual Kev Muaj Peev Xwm, Cov Kev Pom Zoo thiab Kev Nkag Mus Thiab Kev Ruaj Ntseg Saib Xyuas thiab Them Nyiaj.

Kauj Ruam 6: Xaus

Ntseeg qhov kev lees paub no ua rau muaj kev sim ntxiv. Qhov ntsuas I2C no yog qhov hloov pauv tau zoo, coj tus yam ntxwv thiab muaj. Txij li nws yog rau qib kev txaus ntshai tsis xwm txheej, 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 Pedometer siv LIS3DHTR thiab Raspberry Pi. Hauv txoj haujlwm saum toj no, peb tau siv cov lej suav sau. Kev nrawm tuaj yeem yog qhov ntsuas tseem ceeb los txheeb xyuas qhov kev txiav txim siab taug kev. Koj tuaj yeem txheeb xyuas peb yam ntawm cov lus tsa suab rau tus kheej uas tau txav mus tom ntej (yob, X), sab (suab, Y) thiab ntsug (yaw axis, Z). Ib tus qauv raug ntawm tag nrho 3 qag raug kaw. Yam tsawg kawg 1 axis yuav muaj qhov txheeb ze loj zuj zus nrawm nrawm. Yog li qhov taw qhia siab tshaj plaws thiab ib qho algorithm yog qhov tseem ceeb. Ua tus lej ntawm cov txheej txheem Parameter (Cov Lim Digital, Tshawb Pom Peak, Lub Sijhawm Qhov Ncauj, thiab lwm yam) ntawm cov txheej txheem no, koj tuaj yeem lees paub thiab suav cov kauj ruam, ntxiv rau ntsuas qhov nrug, nrawm, thiab-rau qhov qis-calories hlawv. Yog li koj tuaj yeem siv lub ntsuas ntsuas no hauv ntau txoj hauv kev uas koj tuaj yeem xav txog. Peb ntseeg koj txhua tus nyiam nws! Peb yuav sim ua kom ua haujlwm tau zoo ntawm lub ntsuas ntsuas no sai dua tom qab, teeb tsa, cov cai, ib feem suav nrog txhais tau tias cais kev taug kev thiab khiav thiab Calories hlawv.

Txog rau koj kev nplij siab, peb muaj cov vis dis aus txaus ntshai hauv YouTube uas tuaj yeem pab koj qhov kev xeem. Ntseeg qhov kev nqis peev no txhawb kev tshawb nrhiav ntxiv. Txuas ntxiv mus ntxiv! Nco ntsoov saib tom qab vim tias muaj ntau ntxiv tuaj.

Pom zoo: