Cov txheej txheem:

Realtime MPU-6050/A0 Cov Ntaub Ntawv Teev Nrog Arduino thiab Android: 7 Cov Kauj Ruam (nrog Duab)
Realtime MPU-6050/A0 Cov Ntaub Ntawv Teev Nrog Arduino thiab Android: 7 Cov Kauj Ruam (nrog Duab)

Video: Realtime MPU-6050/A0 Cov Ntaub Ntawv Teev Nrog Arduino thiab Android: 7 Cov Kauj Ruam (nrog Duab)

Video: Realtime MPU-6050/A0 Cov Ntaub Ntawv Teev Nrog Arduino thiab Android: 7 Cov Kauj Ruam (nrog Duab)
Video: MPU6050 Gyro Motion Tracking Application 2024, Kaum ib hlis
Anonim
Realtime MPU-6050/A0 Cov Ntaub Ntawv Teev Nrog Arduino thiab Android
Realtime MPU-6050/A0 Cov Ntaub Ntawv Teev Nrog Arduino thiab Android

Kuv tau txaus siab siv Arduino rau kev kawm tshuab. Ua thawj kauj ruam, Kuv xav tsim lub sijhawm tiag tiag (lossis zoo nkauj nyob ze rau nws) cov ntaub ntawv tso tawm thiab logger nrog lub cuab yeej Android. Kuv xav khaws cov ntaub ntawv ntsuas lub nrawm los ntawm MPU-6050 yog li kuv tsim qauv tsim los siv HC-05 ntawm 115200 baud. Nrog qhov teeb tsa no 4 txoj hauv kev ntawm cov ntaub ntawv tuaj yeem sib kis tau ntawm 250 qhov kev kuaj ib pliag.

Kev tsim muaj ob peb kauj ruam:

  • Ua daim ntaub thaiv los yog daim txiag ntoo
  • Program Arduino
  • Rub lub Android app los ntawm Google Ua Si lossis ceg GitHub thiab suav nws tus kheej
  • Txuas MPU-6050 mus rau qee yam uas ntxim nyiam uas vibrates (Kuv siv lub tsheb R/C)
  • Siv Android ntaus ntawv los txuas rau Arduino
  • Npaj cov ntaub ntawv, txuag yog xav paub
  • Ntshuam rau hauv Python (lossis lwm lub platform) rau kev siv ntxiv

Cia peb pib!

Kauj Ruam 1: Tsim Shield/breadboard

Tsim Shield/breadboard
Tsim Shield/breadboard
Tsim Shield/breadboard
Tsim Shield/breadboard

Nov yog daim duab kab hluav taws xob rau Arduino, HC-05, thiab MPU-6050. Ntxiv rau MPU-6050 Kuv muaj cov tswv yim analog A0 txuas mus rau lub teeb pom kev los qhia tias ADC ua haujlwm. Ib qho 0-5 volt teeb liab tuaj yeem coj mus rau hauv A0 ADC. Nov yog cov khoom kuv siv rau kev tsim:

  • Arduino Ib
  • HC-05 (HC-06 yuav tsum ua haujlwm ib yam, tab sis kuv tsim tau nrog HC-05)
  • NPE-6050
  • Sparkfun photoresistor
  • 10kOhm resistor (xim av-dub-txiv kab ntxwv)

Feem ntau HC-05 Bluetooth modules default rau 9600 baud. Rau cov ntaub ntawv xa mus tau zoo koj yuav tsum tau rov sau dua nws rau 115200 baud tus nqi. Muaj qhov zoo HC-05/HC-06 AT Cov Lus Qhia Qhia uas piav qhia yuav ua li cas.

Kauj ruam 2: Program Arduino

Program Arduino
Program Arduino
Program Arduino
Program Arduino

Kuv siv Arduino IDE tso tawm 1.6.7 rau program Arduino. Txoj cai tuaj yeem rub tawm los ntawm cov kab ntawv txuas hauv qib no lossis los ntawm GitHub repo. Kuv tau suav nrog peb yam: Firmware125.ino yog 125 hertz version, Firmware250.ino yog 250 hertz version, thiab Firmware500.ino yog 500 hertz version. Txhawm rau kom Arduino hloov pauv ntawm 500 hertz, A0 ADC tsis tau sau.

Lub khoos phis tawj suav nrog lub moos tawm ntawm Tus Pin 9 uas kuv siv los tshuaj xyuas lub sijhawm. Kab ntawv qhia pom lub sijhawm voj voog yog 4 ms (sib npaug rau 1/250 hertz). Kuv tau pom tias yog tias muaj teeb meem txuas txuas lub sijhawm yuav tsis sib xws.

Tus lej Arduino siv qhov ntsej muag me ntsis ntxiv tus lej xov tooj rau txhua pob ntawv vim tias qee zaum qee zaum poob qis dua Bluetooth. Kuv siv peb qhov khoom tseem ceeb tshaj plaws los khaws tus lej channel. Rau kos npe integers qhov tseem ceeb tshaj plaws me ntsis (MSB) tau tshwj tseg rau lub cim. Txij li thaum kuv xav siv MSB rau kuv qhov chaw nyob, ntau dua li kos npe ntawm tus lej lej, Kuv yuav tsum hloov pauv txhua qhov kos npe ntsuas qhov ntsuas mus rau qhov tsis suav nrog. Kuv ua qhov no los ntawm kev ntxiv 32768 rau txhua tus nqi (MPU cov ntsuas kev ntsuas ADC suav yog +32768 txog -32768) thiab pov raws li cov cim tsis tau kos npe:

(unsigned int) ((ntev) iAccelData+32767);

Tus lej xov tooj zoo ib yam rau txhua qhov ntsuas cua thiab A0 chaw nres nkoj kom cov pob ntawv poob tuaj yeem kuaj pom yog tias cov lej hauv channel tsis ua tiav. Txog pob ntawv los ntawm Bluetooth ntawm Arduino, tus qauv binary yog (cov cim yog qhov hloov pauv me ntsis):

(xacc 3 chaw nyob me me = 0x00, 13bit tsis kos npe) (yacc 3 chaw nyob khoom = 0x01, 13 ntsis tsis kos npe) (zacc 3 chaw nyob khoom = 0x02, 13 ntsis tsis kos npe) (3 chaw nyob khoom = 0x03, iadc13bit tsis kos npe)

(xacc 3 address bits = 0x00, 13bit unsigned) (yacc 3 address bits = 0x01, 13bit unsigned) (zacc 3 address bits = 0x02, 13bit unsigned) (3 address bits = 0x03, iadc13bit unsigned) (xacc 3 address bits = 0x00, 13bit tsis kos npe) (yacc 3 chaw nyob khoom = 0x01, 13 ntsis tsis kos npe) (zacc 3 chaw nyob = = 0x02, 13 ntsis tsis kos npe) (3 chaw nyob khoom = 0x03, iadc13bit tsis kos npe) …

Yog tias siv lwm yam uas tsis yog Accel Plot Android app los nyeem cov ntaub ntawv Bluetooth, ntawm no yog cov kauj ruam rau rho tawm qhov chaw nyob (Kuv siv cov npe sib txawv los ntawm Accel Plot Bluetooth.java cov ntaub ntawv los ntawm GitHub repo):

- Nyeem hauv 16 qhov tsis tau kos npe

- Tshem tawm qhov siab byte thiab txuag nws mus rau btHigh.

- Tshem tawm cov byte qis thiab txuag nws rau btLow.

- Muab qhov chaw nyob los ntawm btHigh siv: (btHigh >> 5) & 0x07. Cov lus no hloov btHigh 5 cov khoom mus rau sab xis txav peb qhov chaw nyob mus rau qhov qis tshaj peb npe. Qhov & kos npe yog qhov laj thawj THIAB uas yuam cov khoom 4 thiab siab dua kom xoom thiab peb lub xeem kawg kom phim qhov chaw nyob. Qhov tshwm sim ntawm nqe lus no yog koj qhov chaw nyob.

Koj tsis tas yuav txhawj xeeb txog qhov chaw rho tawm yog tias koj siv Accel Plot.

Kauj Ruam 3: Thauj lub Android App Los ntawm Google Ua Si lossis ceg GitHub

Thauj lub Android App Los ntawm Google Ua Si lossis ceg GitHub
Thauj lub Android App Los ntawm Google Ua Si lossis ceg GitHub

Koj muaj ob peb txoj kev xaiv rau thauj khoom Android app ntawm koj lub cuab yeej. Yog tias koj xav kom zam kev sau tus lej, koj tuaj yeem tshawb rau "Accel Plot" thiab lub app yuav tsum tuaj hauv Google Play store. Ua raws li cov lus qhia hauv khw rau kev teeb tsa.

Kuv lub siab xav nrog Cov Lus Qhia no yog tiag txhawb kom lwm tus los tsim cov phiaj xwm yog li kuv kuj tau tshaj tawm cov cai hauv GitHub repo. Koj yuav tsum muaj peev xwm tuaj ceg no, tsim nws, thiab hloov kho nws raws li koj pom zoo. Kuv luam tawm cov cai hauv qab daim ntawv tso cai MIT yog li muaj kev lom zem!

Kauj Ruam 4: Txuas mus rau Arduino rau qee Yam Txaus Siab (Kuv Siv R/C Tsheb)

Txuas mus rau Arduino mus rau Ib Yam Ntxim Saib Ntxim Ua (Kuv Siv R/C Tsheb)
Txuas mus rau Arduino mus rau Ib Yam Ntxim Saib Ntxim Ua (Kuv Siv R/C Tsheb)

Kuv xav kom siv lub cuab yeej txhawm rau txhawm rau nrhiav txoj hauv kev yog li kuv xav tias lub tsheb me me tswj (R/C) lub tsheb yuav tsim nyog. Kuv xav tias nws pab tau hauv cov kauj ruam tom ntej yog tias qhov ua tau zoo tuaj yeem ua rau qee yam uas txav lossis ua rau co.

Kauj Ruam 5: Siv Android Device Txuas rau Arduino

Siv Android Device Txuas rau Arduino
Siv Android Device Txuas rau Arduino
Siv Android Device Txuas rau Arduino
Siv Android Device Txuas rau Arduino
Siv Android Device Txuas rau Arduino
Siv Android Device Txuas rau Arduino

Yog tias koj tsis tau ua li ntawd, koj yuav tsum xub ua khub HC-05 rau koj lub cuab yeej Android. Kuv ntseeg tias ntawm cov cuab yeej feem ntau koj tuaj yeem ua qhov no los ntawm kev mus rau chaw teeb tsa. Tus pin tus lej rau feem ntau HC-05 cov cuab yeej yuav yog 1234 lossis 1111.

Qhib AccelPlot app ntawm Android ntaus ntawv. Thaum lub app qhib, thiab ua ntej koj txuas rau HC-05, koj tuaj yeem hloov pauv tus nqi piv txwv (qhov no tau teeb tsa hauv Arduino code), ntsuas kev ntsuas (tseem teev hauv Arduino code), thiab tus naj npawb ntawm cov qauv yuav raug cawm.

Thaum cov kev teeb tsa no ua tiav nyem rau ntawm "Txuas" khawm. Nws yuav tsum nqa cov cuab yeej Bluetooth thiab koj lub cuab yeej yuav tsum tau teev. Xaiv nws thiab ib zaug cov cai tsim kev sib txuas koj yuav pom "Txuas" toast pop up.

Siv lub khawm rov qab rov qab los rau Accel Plot. Coj mus rhaub khawm "Pib Kwj" los tso saib cov ntaub ntawv los ntawm HC-05 ntaus ntawv. Koj yuav tsum tseem muaj cov nyees khawm kom txuag tau cov ntaub ntawv lossis ua si cov ntsiab lus hloov pauv los ntawm lub suab nkaus.

Kauj Ruam 6: Tau thiab Npaj Cov Ntaub Ntawv

Image
Image
Ntshuam rau hauv Python (lossis Lwm Lub Platform) rau Kev Siv Ntxiv
Ntshuam rau hauv Python (lossis Lwm Lub Platform) rau Kev Siv Ntxiv

Lub pob "Pib Kwj" yuav tsum tau qhib. Coj mus rhaub nws kom pib tso cov ntaub ntawv rau ntawm qhov screen.

Lub pob "Txuag Cov Ntaub Ntawv" tseem yuav raug qhib, coj mus rhaub nws kom khaws cov ntaub ntawv.

Accel Plot kuj suav nrog qhov kev xaiv tso tawm lub teeb liab hloov pauv ntawm lub suab. Ob txoj hauv kev hauv Accel Plot app xa mus rau sab laug thiab sab xis ntawm lub suab tawm jack ntawm Android ntaus ntawv. Qhov no muaj txiaj ntsig yog tias koj xav nqa MPU-6050 cov ntaub ntawv mus rau hauv ib qho cais cov ntaub ntawv kaw lus kaw lus, zoo li Cov Khoom Siv Hauv Tebchaws.

Cov vis dis aus qhia piv txwv ntawm cov kab ke khaws cov ntaub ntawv ntawm R/C tsheb.

Kauj Ruam 7: Ntshuam Rau Hauv Python (lossis Lwm Lub Platform) rau Kev Siv Ntxiv

Ntshuam rau hauv Python (lossis Lwm Lub Platform) rau Kev Siv Ntxiv
Ntshuam rau hauv Python (lossis Lwm Lub Platform) rau Kev Siv Ntxiv

Cov ntaub ntawv raug cawm mus rau Android ntaus ntawv. Cov ntaub ntawv yuav raug khaws cia hauv qab "AccelPlot" cov npe rau Android API 18 thiab laus dua. Txoj cai tso cov ntaub ntawv.dat hauv "\ Tablet / Documents / AccelPlot" nplaub tshev rau API 19 (KitKat 4.4) thiab siab dua. Kuv tau muaj teeb meem nrog qee cov khoom siv hauv Android qhia cov ntaub ntawv thaum txuas nrog ntawm USB. Hauv qee kis kuv yuav tsum tau rov pib dua lub cuab yeej Android kom lawv tuaj yeem tshwm sim. Tsis paub meej vim li cas qhov no yog, tab sis yuav tsum muaj plaub daim ntawv, ib qho rau txhua tus channel. Lawv tuaj yeem raug theej rau hauv phau ntawv teev npe hauv zos rau kev ua haujlwm ntxiv.

Kuv siv Anaconda/Python 2.7 qhib cov ntaub ntawv thiab tso saib cov ntaub ntawv. Cov ntawv "ExploratoryAnalysis.ipynb" muaj IPython Notebook file uas yuav qhib tag nrho cov ntaub ntawv cov ntaub ntawv thiab npaj cov qauv piv txwv. Cov ntaub ntawv piv txwv suav nrog hauv GitHub repo. Cov ntaub ntawv raug khaws tseg raws li loj-endian 4 byte ntab ('> f') yog li txhua qhov kev tshuaj xyuas yuav tsum tuaj yeem qhib lawv.

Kuv kuj tseem suav nrog cov ntawv yooj yim hu ua "ReadDataFiles.ipynb" uas qhia pom yuav nyeem li cas hauv ib daim ntawv los ntawm lub npe.

Pom zoo: