Cov txheej txheem:

Arduino & MPU6050 Raws Li Cov Ntsuj Plig Qib Qib: 3 Kauj Ruam
Arduino & MPU6050 Raws Li Cov Ntsuj Plig Qib Qib: 3 Kauj Ruam

Video: Arduino & MPU6050 Raws Li Cov Ntsuj Plig Qib Qib: 3 Kauj Ruam

Video: Arduino & MPU6050 Raws Li Cov Ntsuj Plig Qib Qib: 3 Kauj Ruam
Video: МАСТЕР-КЛАСС по Arduino | Полный семинар по программированию за 90 минут! 2024, Kaum ib hlis
Anonim
Image
Image
Qhov Circuit
Qhov Circuit

Txais tos rau kuv thawj zaug puas tau qhia! Kuv vam tias koj pom nws cov ntaub ntawv. Thov koj xav tawm tswv yim seb puas zoo lossis tsis zoo.

Txoj haujlwm no yog ua kom muaj arduino & MPU6050 raws qib qib siab. Whilst qhov kev tsim tiav thiab cov cai yog kuv li, lub tswv yim qub thiab ntau ntawm cov cai kuv tau ua haujlwm los ntawm tsis yog. Kuv tsis yog kev dag neeg, yog li kuv zoo siab tshaj muab credit rau cov neeg uas lub tswv yim kuv tau tsim los. 2 tus neeg tseem ceeb uas kuv xav ua kom nrov nrov yog YouTuber's Paul McWhorter thiab DroneBot Rhiav. Kuv suav nrog cov txuas rau lawv hauv kuv li youtube muaj txiaj ntsig txuas PDF. Ua tsaug rau EEEnthusiast rau nws cov ntaub ntawv xov xwm ntawm kev siv MPU6050 suav nrog teeb tsa thiab nyeem ntawv los ntawm tus qauv yam tsis muaj lub tsev qiv ntawv sab nraud (nws qhov txuas yog tib yam PDF).

Txoj haujlwm kuv tau tsim, ua haujlwm 'raws li yog' thiab yog qhov tseeb zoo, yeej txog 45% hauv ob qho tib si. Koj tuaj yeem siv nws raws nraim qhov kuv tau tsim nws, lossis koj tuaj yeem txiav nws raws li koj tus kheej nyiam. Qhov ntse tshaj ntawm koj yuav pom tias kuv qhov haujlwm zoo li yuav luag zoo ib yam los ntawm DroneBot Rhiav, tab sis so kom ntseeg tau, muaj qhov sib txawv tseem ceeb, tshwj xeeb tshaj yog thaum nws los txog rau txoj cai rau xam cov ces kaum, ntxiv rau lub chaw khaws cov ntsuas qhov ntsuas hauv Eeprom!

Qee qhov tshwj xeeb los txhawb koj txoj kev qab los:

Suab thiab cov ces kaum muaj nyob rau hauv 0.1 ntawm qib kawm.

Pib pom ntawm kev taw qhia ntawm chav gyro (kab rov tav lossis ntsug)

Kev ntsuas ntsuas tag nrho nrog cov txiaj ntsig cia cia rau eeprom

LED qhia los ntawm -2 txog +2 degrees (hloov pauv hauv txoj cai)

Kev qhia ntxiv rau lub suab (tuaj yeem qhib rau/tawm ntawm ya ya)

Kev cog lus me me xav tau cov khoom me me

Cia peb pib.

Khoom siv

Txoj haujlwm no (raws li yog) siv cov khoom hauv qab no:

1 x Arduino nano (kuv yog clone)

1 x MPU6050 gyro/accelerometer module

1 x LCD - 16 x 2 + I2C kev txuas

1 x Laub kom hloov

1 x Piezo buzzer

1 x Ntsuab LED

2 x LED daj

2 x Red LEDs

5 x 220 ohm resistors

Ntau yam jumper cables

Cov qhob cij

Fais fab mov (kuv siv 5v USB lub txhab nyiaj fais fab, thaum tsis txuas nrog kuv lub PC, tab sis koj tuaj yeem siv lub roj teeb kom tsim nyog txuas nrog)

Kauj ruam 1: Circuit Court

Qhov Circuit
Qhov Circuit
Qhov Circuit
Qhov Circuit

Piv txwv tias koj muaj tag nrho cov khoom siv, koj yuav tsum tsim koj daim ntawv qhia zaub mov.

Kuv qhia kuv teeb tsa raws li phau ntawv qhia, tab sis kev sib txuas yog raws li hauv qab no:

Arduino tus pin D2 txuas rau 1 sab ntawm qhov hloov mus. Lwm sab ntawm lub laub hloov txuas rau hauv av

Arduino tus pin D3 txuas rau 1 sab ntawm 220 ohm resistor. Lwm sab ntawm tus tiv thaiv txuas rau lub cim ntawm Red LED. Cathode ntawm Liab LED mus rau hauv av.

Arduino tus pin D4 txuas rau 1 sab ntawm 220 ohm resistor. Lwm sab ntawm tus tiv thaiv txuas rau qhov cim tseg ntawm LED daj. Cathode ntawm LED daj mus rau hauv av.

Arduino tus pin D5 txuas rau 1 sab ntawm 220 ohm resistor. Lwm sab ntawm tus tiv thaiv txuas mus rau qhov cim tseg ntawm Green LED. Cathode ntawm Green LED mus rau hauv av.

Arduino tus pin D6 txuas rau 1 sab ntawm 220 ohm resistor. Lwm sab ntawm tus tiv thaiv txuas rau qhov cim tseg ntawm LED daj. Cathode ntawm LED daj mus rau hauv av.

Arduino tus pin D7 txuas rau 1 sab ntawm 220 ohm resistor. Lwm sab ntawm tus tiv thaiv txuas rau lub cim ntawm Red LED. Cathode ntawm Liab LED mus rau hauv av.

Arduino tus pin D8 txuas rau ib sab ntawm Piezo buzzer. Lwm sab ntawm buzzer txuas rau hauv av.

Arduino tus pin A4 txuas rau SDA pins ntawm MPU6050 THIAB LCD.

Arduino tus pin A5 txuas rau SCL pins ntawm MPU6050 THIAB LCD

5v zog thiab Gnd rau MPU6050 thiab LCD los ntawm Arduino Nano 5v thiab GND pins feem.

Thaum ua tiav, nws yuav tsum zoo ib yam li kuv teeb tsa. Kuv tso blu tak hauv qab MPU6050 kom nws tsis txav mus thiab tseem nyob ntawm LCD kom nws nyob ntawm ntug ntawm lub khob cij.

Kauj ruam 2: Txoj Cai

Cov cai txuas nrog yog tus lej kuv tau siv rau txoj haujlwm no. Tsuas yog lub tsev qiv ntawv koj yuav muaj teeb meem nrog yog

LiquidCrystal_I2C.h lub tsev qiv ntawv raws li kuv tau import qhov no thaum kuv xub pib ua haujlwm nrog LCD's. Hmoov tsis zoo, muaj ob peb lub tsev qiv ntawv uas siv tib nqe lus #suav nrog, tab sis txawv me ntsis. Yog tias koj muaj teeb meem nrog koj li, nrhiav lwm tus lej LCD uas ua haujlwm rau koj thiab hloov txoj cai raws li. Nws tsuas yog yuav yog qhov teeb tsa uas sib txawv. Txhua qhov 'luam tawm' cov lus txib yuav tsum ua haujlwm ib yam.

Txhua txoj cai tau tawm tswv yim thiab xav tias kuv tau ua nws raug, tseem yuav muaj daim vis dis aus piav qhia txhua yam, tab sis ntawm no yog ob peb lub ntsiab lus yuav tsum nco ntsoov:

LiquidCrystal_I2C lcd (0x27, 16, 2);

Cov cai saum toj no yog teeb tsa rau kuv lub LCD. Yog tias koj lub tsev qiv ntawv sib txawv, koj yuav xav hloov tsis yog koj lub tsev qiv ntawv nkaus xwb, tab sis kuj yog kab ntawv no.

{lcd.setCursor (0, 1); lcd.print ("Kab rov tav!"); kev taw qhia = HORIZONTAL; // Nyeem cov ntaub ntawv raw thiab gyro los ntawm MPU-6050 1000 zaug rau (int cal_int = 0; cal_int <1000; cal_int ++) {read_mpu_6050_data (); // Ntxiv cov gyro x offset rau gyro_x_cal sib txawv gyro_x_cal += gyro_x; // Ntxiv cov gyro y offset rau gyro_y_cal sib txawv gyro_y_cal += gyro_y; // Ntxiv cov gyro z offset rau gyro_z_cal sib txawv gyro_z_cal += gyro_z; // Ntxiv qhov acc x offset rau acc_x_cal kuj sib txawv acc_x_cal += acc_x; // Ntxiv rau acc y offset rau acc_y_cal kuj sib txawv acc_y_cal += acc_y; } // Sib faib txhua qhov txiaj ntsig los ntawm 1000 kom tau txais qhov nruab nrab nruab nrab gyro_x_cal /= 1000.0; gyro_y_cal /= 1000.0; gyro_z_cal /= 1000.0; acc_x_cal /= 1000.0; acc_y_cal /= 1000.0; horizonalCalibration = 255; eeprom_address = 0; EEPROM.put (eeprom_address, ntsuas kab rov tav); eeprom_address += sizeof (int); EEPROM.put (eeprom_address, gyro_x_cal); eeprom_address += sizeof (ntab); EEPROM.put (eeprom_address, gyro_y_cal); eeprom_address += sizeof (ntab); EEPROM.put (eeprom_address, gyro_z_cal); eeprom_address += sizeof (ntab); EEPROM.put (eeprom_address, acc_x_cal); eeprom_address += sizeof (ntab); EEPROM.put (eeprom_address, acc_y_cal); eeprom_address += sizeof (ntab); // Nco tseg tias peb tsis khaws cia cov nyiaj them rau acc_z, vim yog lub ntiajteb txawj nqus! ncua (500); }

Cov thaiv kab lus saum toj no ua rau kev ntsuas ntsuas ib txwm muaj. Txoj cai no yog rau kev ntsuas kab rov tav. Muaj ze ze tus lej zoo ib yam rau kev ntsuas ntsuas ntsug (nco ntsoov, tus lej paub seb koj li MPU6050 tau teeb tsa kab rov tav lossis ntsug!). MPU6050, yog nyeem 1000 zaug. cov txiaj ntsig tsim nyog tau suav nrog ntxiv tom qab ntawd faib los ntawm 1000 kom muab qhov nruab nrab 'offset' tus nqi. Cov txiaj ntsig no tau muab khaws cia rau Nano eeprom. Txhua qhov kev ntsuas ntsuas kab rov tav tau muab khaws cia pib ntawm eeprom chaw nyob 0. Txhua qhov txiaj ntsig ntsug tau khaws cia pib ntawm eeprom chaw nyob 24. Kev ntsuas yuav tsum tau ua tiav ntawm qib saum npoo, txwv tsis pub lawv tsis txhais tau tias tsis muaj dab tsi.

/ * * Ob peb kab tom ntej txheej txheem cov ntaub ntawv nyoos los hloov nws mus rau hauv cov ces kaum uas tuaj yeem tsim tawm rau LCD thiab LED's. * Tus nqi ntawm 4096, uas cov ntaub ntawv nrawm tau muab faib los ntawm cov ntaub ntawv los ntawm MPU6050 thiab yog raws tus qauv piv txwv. * Tus nqi ntawm 9.8 yog lub ntiajteb txawj nqus * Lub luag haujlwm atan2 yog los ntawm kev ua lej thiab siv los laij cov ces kaum los ntawm cov ntaub ntawv muab */thetaM = -atan2 ((acc_x/4096.0)/9.8, (acc_z/4096.0) /9.8) /2/3.141592656 * 360; // Cov ntaub ntawv nyoos phiM = -atan2 ((acc_y/4096.0) /9.8, (acc_z/4096.0) /9.8) /2/3.141592656 * 360; // Cov ntaub ntawv nyoos dt = (millis ()-millisOld)/1000; millisOld = millis (); / * * Nqe lus no siv cov ntaub ntawv gyro los ua kom lub kaw lus muaj txiaj ntsig ntau dua * tus nqi ntawm 65.5, uas cov ntaub ntawv gyro tau muab faib los ntawm kev coj los ntawm MPU6050 cov ntawv teev tseg thiab yog ua raws tus qauv piv */ theta = (theta+(gyro_y/ 65.5)*dt)*. 96 + thetaM*.04; // Tsawg dhau lim phi = (phi + (gyro_x/65.5)*dt)*. 96 + phiM*.04; // Tsawg dhau lim

Cov cai saum toj no yog cov khoom uas suav cov ces kaum. Vam tias cov lus muab kev nkag siab me ntsis rau nws ua haujlwm li cas, tab sis rau kev piav qhia tob, txheeb xyuas Paul McWhorters cov vis dis aus txuas rau hauv PDF txuas. Qhov kuv yuav hais txawm yog tias koj tuaj yeem hloov tus qauv piv rau gyro thiab Accelerometer (uas tau ua tiav hauv teeb tsa MPU6050 subroutine hauv qab ntawm kuv tus lej). Yog tias koj hloov tus nqi piv txwv, koj kuj yuav tsum tau hloov pauv ntau npaum li cas cov ntaub ntawv nyoos raug faib los ntawm. Rau cov ntaub ntawv ntsuas tus ntsuas, tus nqi tam sim no yog 4096. Rau lub gyro, tus nqi tam sim no yog 65.5.

Xa mus rau cov ntaub ntawv txuas nrog thiab cov vis dis aus los ntawm EEEntusiast (txuas hauv PDF txuas) kom paub ntau ntxiv txog cov ntaub ntawv ntxaws ntxaws ntawm kev ntsuas thiab ntsuas qhov ntsuas pom li cas.

Kauj Ruam 3: Cov Kauj Ruam Tom ntej

Los ntawm qhov no yuav cia siab tau ua txoj haujlwm no, tab sis tam sim no yog dab tsi?

Ua ntej tshaj plaws, vim li cas ho tsis tsim nws mus rau qib siab uas koj tuaj yeem siv tau. Koj tuaj yeem yuav qib tus nqi pheej yig (xyuas kom tseeb tias nws yog lub thawv ntawv) uas koj tuaj yeem hloov kho, lossis yog tias koj muaj cov khoom siv, luam koj tus kheej qib/lub thawv.

Tej zaum yuav muaj kev ua si ib puag ncig nrog lub gyro thiab tus qauv ntsuas tus ntsuas kom pom tias lawv ua haujlwm tau zoo dua ntawm tus nqi dua lwm qhov.

Sim ua kom zoo dua cov cai ntxiv. Piv txwv li, tam sim no, tshaj li 45 degrees, lub kaum sab xis tau hais ntxaws los hais qhov tsawg tshaj plaws. Puas muaj ib txoj kev nyob ib puag ncig nws?

Yog tias koj muaj lus nug, tsis hais lawv yuav yooj yim npaum li cas, thov nug. Yog kuv pab tau, kuv yuav.

Yog tias koj nyiam cov lus qhia no, thov muab nws nyiam, kom kuv paub.

Yog tias koj ua qhov no, thov qhia kuv (tshwj xeeb tshaj yog tias nws nyob hauv rooj plaub ua haujlwm).

UA TSAUG

Pom zoo: