Cov txheej txheem:

Tswj Kev Siv MPU6050 Ntawm Arduino thiab ESP8266 Nrog HC-12: 6 Cov Kauj Ruam
Tswj Kev Siv MPU6050 Ntawm Arduino thiab ESP8266 Nrog HC-12: 6 Cov Kauj Ruam

Video: Tswj Kev Siv MPU6050 Ntawm Arduino thiab ESP8266 Nrog HC-12: 6 Cov Kauj Ruam

Video: Tswj Kev Siv MPU6050 Ntawm Arduino thiab ESP8266 Nrog HC-12: 6 Cov Kauj Ruam
Video: Nom Tswv txoj cai kev tswj kev siv nyiaj (Breaking news) 2024, Kaum ib hlis
Anonim
Tswj Kev Siv MPU6050 Ntawm Arduino thiab ESP8266 Nrog HC-12
Tswj Kev Siv MPU6050 Ntawm Arduino thiab ESP8266 Nrog HC-12

Hauv txoj haujlwm no, peb tab tom tswj txoj haujlwm ntawm servo motor siv mpu6050 thiab HC-12 rau kev sib txuas lus ntawm Arduino UNO thiab ESP8266 NodeMCU.

Kauj Ruam 1: HAIS TIAS YUAV UA LI CAS

Nws yog lwm qhov haujlwm IoT raws HC-12 RF-module. Ntawm no, cov ntaub ntawv imu (mpu6050) los ntawm arduino tau siv los tswj lub cav servo (txuas nrog Nodemcu). Ntawm no, cov ntaub ntawv pom tau kuj tau ua ntawm sab arduino qhov twg mpu6050 suab cov ntaub ntawv (kev sib hloov txog x-axis) yog pom nrog ua cov duab kos (tham tom qab). Yeej qhov haujlwm no tsuas yog sov me ntsis kom nco txog qhov sib txawv ntawm Imu & Servo tswj nrog Arduino thiab ESP8266 nodemcu.

OBJECTIVE

Lub hom phiaj ntawm qhov no zoo nkauj heev, Peb tab tom tswj txoj haujlwm ntawm Servo lub cev siv lub suab nrov ntawm IMU. Thiab txhua qhov ua ke lub suab thiab synchronized txoj haujlwm lub cev tau pom nrog Ua.

Kauj ruam 2: Yuav tsum kho vajtse

NodeMCU ESP8266 12E Wifi module

Solderless breadboard

Jumper hlau

MPU6050 accelo+gyro

HC-12 RF modules (khub)

SG90 Servo tsav

Kauj Ruam 3: Circuit & Kev Sib Txuas

Circuit & Kev Sib Txuas
Circuit & Kev Sib Txuas
Circuit & Kev Sib Txuas
Circuit & Kev Sib Txuas

Kev sib txuas yog ncaj nraim rau pem hauv ntej. Koj tuaj yeem ua lub zog pabcuam nrog 3.3V ntawm koj li Nodemcu. Koj kuj tseem tuaj yeem siv Vin los ua haujlwm pabcuam yog tias koj lub nodemcu muaj qhov hluav taws xob ntau ntawm tus pin ntawd. Tab sis feem ntau Lolin cov laug cam tsis muaj 5V ntawm Vin (nyob ntawm tus tsim khoom).

Cov duab kab hluav taws xob no tau siv EasyADA.

Kauj ruam 4: Ua haujlwm

Ua haujlwm
Ua haujlwm

Sai li sai tau cov duab kos pib, nws yuav xa lub suab (uas yog los ntawm -45 txog 45) mus rau hc12 tus txais ntawm Nodemcu uas tau teeb tsa nrog 0 txog 180 degree Servo txoj haujlwm. Ntawm no peb siv lub kaum sab xis ntawm -45 txog +45 degree yog li peb tuaj yeem yooj yim daim ntawv qhia ntawd mus rau txoj haujlwm Servo.

Tam sim no, koj tab tom xav tias yog vim li cas peb thiaj siv tau daim ntawv qhia kev yooj yim raws li hauv qab no:-

int pos = daim ntawv qhia (val, -45, 45, 0, 180);

Vim tias lub kaum tsis zoo xa los ntawm hc12 tus xa tawm tau txais raws li:

Ib nrab: (T) 0 txog 45 => 0 txog 45 (R)

Ib nrab thib ob: (T) -45 rau -1 => 255 txog 210 (R)

Yog li koj yuav tsum qhia nws rau 0 txog 180 li

yog (val> = 0 && val <= 45) pos = (val*2) +90; lwm tus pos = (tus nqi-210)*2;

Kuv tabtom zam txoj kev qhia hauv daim ntawv qhia vim qee qhov tsis raug uas tsis raug. Koj tuaj yeem sim qhov ntawd thiab tawm tswv yim nws ua haujlwm nrog koj

if (val> = 0 && val <= 45) pos = map (val, 0, 45, 90, 180); lwm pos = daim ntawv qhia (tus nqi, 255, 210, 0, 90); // Kev sib cav zaum thib 4 tuaj yeem yog 2 (koj tuaj yeem tshawb xyuas)

MPU6050 Pitch Angle Calculation

Kuv siv MPU6050_tockn lub tsev qiv ntawv uas yog raws li muab cov ntaub ntawv nyoos los ntawm IMU.

int pitchAngle = mpu6050.getAngleX ()

Qhov no yuav tau txais peb lub kaum sab xis ntawm kev sib hloov hais txog x-axis. Raws li koj pom hauv daim duab, kuv imu tau muab tso rau ntawm lub khob cij kom tsis txhob cuam tshuam nrog lub suab thiab yob. Qhov tseeb koj yuav tsum ib txwm pom lub axis luam tawm ntawm pawg thawj coj tawg.

Los ntawm lub tsev qiv ntawv no, koj tsis tas yuav thab plaub txog cov khoom siv hluav taws xob sab hauv ntawm kev nyeem ntawv tshwj xeeb rau kev ua haujlwm tshwj xeeb. koj tsuas yog qhia txoj haujlwm thiab koj ua tiav!

Btw yog tias koj xav xam lub kaum sab xis ntawm koj tus kheej. Koj tuaj yeem yooj yim ua nws raws li hauv qab no:

#suav nrog

const int MPU6050_addr = 0x68; int16_t AcX, AcY, AcZ, Temp, GyroX, GyroY, GyroZ; teeb tsa tsis muaj dabtsis () {Wire.begin (); Wire.beginTransmission (MPU6050_addr); Hlau.write (0x6B); Hlau.write (0); Wire.endTransmission (muaj tseeb); Serial.begin (9600); } void loop () {Wire.beginTransmission (MPU6050_addr); Hlau.write (0x3B); Wire.endTransmission (tsis tseeb); Wire.requestFrom (MPU6050_addr, 14, muaj tseeb); AcX = Wire.read () << 8 | Wire.read (); AcY = Wire.read () << 8 | Wire.read (); AcZ = Wire.read () << 8 | Wire.read (); Temp = Wire.read () << 8 | Hlau.read (); GyroX = Wire.read () << 8 | Wire.read (); GyroY = Wire.read () << 8 | Wire.read (); GyroZ = Wire.read () << 8 | Wire.read ();

int xAng = daim ntawv qhia (AcX, minVal, maxVal, -90, 90); int yAng = daim ntawv qhia (AcY, minVal, maxVal, -90, 90); int zAng = daim ntawv qhia (AcZ, minVal, maxVal, -90, 90); x = RAD_TO_DEG * (atan2 (-yAng, -zAng)+PI); y = RAD_TO_DEG * (atan2 (-xAng, -zAng)+PI); z = RAD_TO_DEG * (atan2 (-yAng, -xAng)+PI); Serial.print ("AngleX ="); // Suab Serial.println (x); Serial.print ("AngleY ="); // Yob Serial.println (y); Serial.print ("AngleZ ="); // Yaw Serial.println (z); }

Tab sis, nws tsis tsim nyog koj yuav sau qhov chaws no kom tau lub kaum ntse ntse. Koj yuav tsum paub qhov tseeb tom qab qhov xwm txheej tab sis siv tsev qiv ntawv ntawm lwm tus neeg muaj txiaj ntsig zoo hauv ntau txoj haujlwm. Koj tuaj yeem nyeem txog qhov no imu thiab lwm yam kev pom zoo kom tau txais cov ntaub ntawv lim dej ntau ntxiv los ntawm qhov txuas hauv qab no: Tshawb-mpu6050.

Kuv tus lej arduino ntawm qhov kawg kis tsuas muaj 30 kab nrog kev pab ntawm MPU6050_tockn lub tsev qiv ntawv yog li siv lub tsev qiv ntawv zoo yog tias koj tsis xav tau qee qhov kev hloov pauv tseem ceeb rau kev ua haujlwm ntawm IMU. Lub tsev qiv ntawv hu ua I2Cdev los ntawm Jeff Rowberg yog qhov muaj txiaj ntsig zoo yog tias koj xav tau qee cov ntaub ntawv lim dej siv DMP (Digital motion processor) ntawm IMU.

Kev koom ua ke nrog Kev Ua

Ntawm no Kev Ua Haujlwm yog siv rau kev pom cov ntaub ntawv hloov pauv ntawm x-axis ntawm IMU raws li suav los ntawm cov ntaub ntawv nyoos los ntawm MPU6050. Peb tau txais cov ntaub ntawv raw khoom tuaj hauv SerialEvent raws li hauv qab no:

tsis muaj dab tsi serialEvent (Serial myPort) {

inString = myPort.readString (); sim {// Parse cov ntaub ntawv // println (inString); Txoj hlua dataStrings = cais (inString, ':'); if (dataStrings.length == 2) {if (dataStrings [0].equals ("RAW")) {for (int i = 0; i <dataStrings.length - 1; i ++) {raw = ntab (dataStrings [kuv+1]); }} lwm tus {println (inString); }}} ntes (Kev zam e) {println ("Catch Exception"); }}

Ntawm no koj tuaj yeem pom kev pom kev hauv daim duab txuas hauv cov kauj ruam no. Cov ntaub ntawv txoj haujlwm tau txais ntawm qhov nodemcu kawg kuj tseem pom ntawm tus saib xyuas raws li qhia hauv daim duab.

Kauj ruam 5: CODE

Kuv tau txuas lub github chaw cia khoom. Koj tuaj yeem clone & nkhaus nws siv rau hauv koj cov phiaj xwm.

kuv_code

Cov repo suav nrog 2 daim duab kos rau kev xa tawm (arduino+IMU) & tus txais (Nodemcu+Servo).

Thiab ib qho kev kos duab. Lub hnub qub repo yog tias qhov no pab tau hauv koj qhov project.

Hauv phau ntawv qhia no, R- Txais & T- Tus Kws Tshaj Lij

Kauj Ruam 6: VIDEO DEMONSTRATION

Kuv yuav muab daim vis dis aus tag kis. Ua raws kuv kom tau txais kev ceeb toom.

Ua tsaug txhua tus!

Pom zoo: