Cov txheej txheem:

Kev Taw Qhia Daim Ntawv Qhia Los Ntawm Web Server: 6 Cov Kauj Ruam
Kev Taw Qhia Daim Ntawv Qhia Los Ntawm Web Server: 6 Cov Kauj Ruam

Video: Kev Taw Qhia Daim Ntawv Qhia Los Ntawm Web Server: 6 Cov Kauj Ruam

Video: Kev Taw Qhia Daim Ntawv Qhia Los Ntawm Web Server: 6 Cov Kauj Ruam
Video: Сравнение G-Shock Magma Ocean Коллекция | GPRB1000 Rangeman | GWF1035 Frogman | MT... 2024, Kaum ib hlis
Anonim
Qhia Kev Taw Qhia Los Ntawm Web Server
Qhia Kev Taw Qhia Los Ntawm Web Server

Internet ntawm Yam, (IoT) yog ib qho ntawm cov ncauj lus nrov hauv ntiaj teb tam sim no. Thiab, nws tau loj hlob sai txhua hnub nrog Internet. Internet ntawm Yam hloov pauv tsev yooj yim mus rau hauv lub tsev ntse, qhov twg txhua yam ntawm koj lub teeb mus rau koj lub xauv tuaj yeem tswj tau los ntawm koj lub xov tooj smartphone lossis desktop. Qhov no yog khoom kim heev txhua leej txhua tus xav ua tus tswv.

Peb ib txwm ua si nrog cov cuab yeej peb tau txais thiab ua haujlwm txuas ntxiv mus rau theem tom ntej ntawm peb cov kev txwv. Peb sim muab peb cov neeg siv khoom lub zeem muag ntawm cov thev naus laus zis tshiab thiab cov tswv yim. Yog li, uas koj tuaj yeem hloov koj lub tsev mus rau hauv tsev ntse thiab txaus siab rau saj ntawm cov khoom kim heev yam tsis siv dag zog ntau.

Niaj hnub no, peb xav txog kev ua haujlwm ntawm ib qho ntawm cov ncauj lus tseem ceeb tshaj plaws hauv IoT - Digital Map Orientation.

Peb yuav tsim lub web server los ntawm qhov uas peb tuaj yeem saib xyuas kev txav chaw ntawm ib lub cuab yeej lossis khoom siv (Nws nyob ntawm koj, leej twg koj xav spy;)). Koj ib txwm tuaj yeem xav txog kev txhim kho txoj haujlwm no mus rau qib tom ntej nrog qee qhov kev hloov kho thiab tsis txhob hnov qab qhia peb hauv cov lus hauv qab no.

Cia pib dua.. !!

Kauj Ruam 1: Cov Khoom Peb Xav Tau..

Cov Khoom Peb Xav Tau.. !!
Cov Khoom Peb Xav Tau.. !!
Cov Khoom Peb Xav Tau.. !!
Cov Khoom Peb Xav Tau.. !!
Cov Khoom Peb Xav Tau.. !!
Cov Khoom Peb Xav Tau.. !!
Cov Khoom Peb Xav Tau.. !!
Cov Khoom Peb Xav Tau.. !!

1. LSM9DS0 Sensor

3-in-1 sensor tsim los ntawm STMicroelectronics, LSM9DS0 yog lub kaw lus-hauv-pob uas suav nrog 3D digital linear acceleration sensor, 3D digital angular rate sensor, thiab 3D digital magnetic sensor. LSM9DS0 muaj qhov nrawm nrawm nrawm ntawm ± 2g/± 4g/± 6g/± 8g/± 16g, qhov sib nqus sib nqus puv scale 2/± 4/± 8/± 12 gauss thiab tus lej ntawm ± 245 /± 500/± 2000 dps.

2. Adafruit Huzzah ESP8266

ESP8266 tus txheej txheem los ntawm Espressif yog 80 MHz microcontroller nrog WiFi puv ntoob-kawg (ob qho tib si raws li tus neeg siv khoom thiab nkag mus rau qhov chaw) thiab TCP/IP pawg nrog DNS txhawb nqa ib yam. ESP8266 yog lub platform zoo kawg rau IoT daim ntawv thov txhim kho. ESP8266 muab kev paub tab rau kev tshuaj xyuas thiab tswj kev siv daim ntawv Arduino Wire Language thiab Arduino IDE.

3. ESP8266 USB Programmer

nws ESP8266 tus tswv tsev tau tsim tshwj xeeb los ntawm Dcube Storefor Adafruit Huzzah version ntawm ESP8266, tso cai rau I²C interface.

4. I2C Txuas Txuas Cable

5. Mini USB Cable

Lub mini USB cable Lub hwj chim muab yog qhov kev xaiv zoo tshaj rau kev txhawb nqa Adafruit Huzzah ESP8266.

Kauj Ruam 2: Kev Sib Txuas Kho Vajtse

Kho vajtse sib txuas
Kho vajtse sib txuas
Kho vajtse sib txuas
Kho vajtse sib txuas
Kho vajtse sib txuas
Kho vajtse sib txuas

Feem ntau, kev sib txuas yog qhov yooj yim tshaj plaws hauv txoj haujlwm no. Ua raws cov lus qhia thiab cov duab, thiab koj yuav tsum tsis muaj teeb meem.

Ua ntej tshaj plaws coj Adafruit Huzzah ESP8266 thiab tso USB Programmer (nrog Sab Hauv Lub ntsej muag I²C Port) rau nws. Nias tus USB Programmer maj mam thiab peb tau ua tiav nrog cov kauj ruam no yooj yim li ncuav qab zib (Saib daim duab saum toj no).

Kev Sib Txuas ntawm Sensor thiab Adafruit Huzzah ESP8266 Siv lub sensor thiab Txuas I²C Cable nrog nws. Kom ua haujlwm tau zoo ntawm cov kab no, thov nco ntsoov I²C Cov Tawm Ib Leeg txuas rau I²C Cov Tswv Yim. Tib yam yuav tsum tau ua raws rau Adafruit Huzzah ESP8266 nrog USB Programmer tau teeb tsa nws (Saib daim duab saum toj no).

Nrog kev pab los ntawm ESP8266 USB Programmer, nws yooj yim heev rau program ESP. Txhua yam koj yuav tsum ua yog ntsaws lub sensor rau hauv USB Programmer thiab koj zoo mus. Peb nyiam siv lub adapter no vim nws ua kom yooj yim dua los txuas cov khoom siv. Tsis muaj kev txhawj xeeb txog kev siv tus pin ntawm ESP rau lub sensor lossis nyeem tus lej kab kos thiab cov ntawv teev npe. Peb tuaj yeem siv thiab ua haujlwm ntawm ntau lub ntsuas hluav taws xob ib txhij, koj tsuas yog xav tau ua cov saw hlau. Yog tsis muaj cov ntsaws thiab ua si USB Programmer muaj qhov pheej hmoo ntawm kev ua txuas tsis raug. Kev xaim hluav taws xob tsis zoo tuaj yeem tua koj li Wi -nkaus thiab koj lub sensor.

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

Kev ua kom muaj zog ntawm Circuit Court

Txuas lub Mini USB cable rau hauv lub zog txuas ntawm Adafruit Huzzah ESP8266. Teeb nws thiab voila, peb zoo mus!

Kauj ruam 3: Code

Code
Code

ESP Code rau Adafruit Huzzah ESP8266 thiab LSM9DS0 Sensor muaj nyob ntawm peb qhov chaw khaws khoom github.

Ua ntej mus rau txoj cai, nco ntsoov koj tau nyeem cov lus qhia muab rau hauv Readme cov ntaub ntawv thiab teeb tsa koj li Adafruit Huzzah ESP8266 raws li nws. Nws yuav siv sijhawm tsuas yog 5 feeb los teeb tsa ESP.

Cov cai yog ntev tab sis nws nyob hauv daim ntawv yooj yim tshaj plaws uas koj tuaj yeem xav txog thiab koj yuav tsis muaj teeb meem nkag siab nws.

Txhawm rau kom yooj yim rau koj, koj tuaj yeem luam qhov ESP code ua haujlwm rau lub ntsuas no los ntawm no kuj:

// Tshaj tawm nrog daim ntawv tso cai pub 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. // LSM9DSO // Tus lej no yog tsim los ua haujlwm nrog TCS3414_I2CS I2C Mini Module muaj los ntawm dcubestore.com.

#suav nrog

#suav nrog

#suav nrog

#suav nrog

// LSM9DSO Gyro I2C chaw nyob yog 6A (106)

#define Addr_Gyro 0x6A // LSM9DSO Accl I2C chaw nyob yog 1E (30) #define Addr_Accl 0x1E

const char* ssid = "koj ssid";

const char* password = "koj tus password"; int xGyro, yGyro, zGyro, xAccl, yAccl, zAccl, xMag, yMag, zMag;

ESP8266WebServer server (80);

tsis muaj dab tsi handleroot ()

{unsigned int cov ntaub ntawv [6];

// Pib I2C Kev Kis

Wire.beginTransmission (Addr_Gyro); // Xaiv tswj npe 1 Wire.write (0x20); // Cov ntaub ntawv tus nqi = 95Hz, X, Y, Z-Axis qhib, lub zog ntawm Wire.write (0x0F); // Nres I2C Kis Kab Hlau.endTransmission ();

// Pib I2C Kev Kis

Wire.beginTransmission (Addr_Gyro); // Xaiv tswj npe 4 Wire.write (0x23); // Puv-teev 2000 dps, hloov tshiab tas li Wire.write (0x30); // Nres I2C Kis Kab Hlau.endTransmission ();

// Pib I2C Kev Kis

Wire.beginTransmission (Addr_Accl); // Xaiv tswj npe 1 Wire.write (0x20); // Cov ntaub ntawv nrawm = 100Hz, X, Y, Z-Axis qhib, lub zog ntawm Wire.write (0x67); // Nres I2C Kev Kis ntawm lub cuab yeej Wire.endTransmission ();

// Pib I2C Kev Kis

Wire.beginTransmission (Addr_Accl); // Xaiv tswj npe 2 Wire.write (0x21); // Kev ntsuas tag nrho xaiv +/- 16g Wire.write (0x20); // Nres I2C Kis Kab Hlau.endTransmission ();

// Pib I2C Kev Kis

Wire.beginTransmission (Addr_Accl); // Xaiv tswj npe 5 Wire.write (0x24); // Sib nqus siab daws teeb meem, tso tawm cov ntaub ntawv tus nqi = 50Hz Wire.write (0x70); // Nres I2C Kis Kab Hlau.endTransmission ();

// Pib I2C Kev Kis

Wire.beginTransmission (Addr_Accl); // Xaiv tswj npe 6 Wire.write (0x25); // Sib nqus puv puv +/- 12 gauss Wire.write (0x60); // Nres I2C Kis Kab Hlau.endTransmission ();

// Pib I2C Kev Kis

Wire.beginTransmission (Addr_Accl); // Xaiv tswj npe 7 Wire.write (0x26); // Hom ib txwm muaj, sib nqus hloov pauv hloov pauv Wire.write (0x00); // Nres I2C Kis Kab Hlau.endTransmission (); ncua (300);

rau (int i = 0; i <6; i ++) {// Pib I2C Kev Xa Cov Hlau.beginTransmission (Addr_Gyro); // Xaiv cov ntaub ntawv sau npe Wire.write ((40 + i)); // Nres I2C Kis Kab Hlau.endTransmission ();

// Thov 1 byte ntawm cov ntaub ntawv

Wire.requestFrom (Addr_Gyro, 1);

// Nyeem 6 bytes ntawm cov ntaub ntawv

// xGyro lsb, xGyro msb, yGyro lsb, yGyro msb, zGyro lsb, zGyro msb yog (Wire.available () == 1) {data = Wire.read (); }}

// Hloov cov ntaub ntawv

int xGyro = ((cov ntaub ntawv [1] * 256) + cov ntaub ntawv [0]); int yGyro = ((cov ntaub ntawv [3] * 256) + cov ntaub ntawv [2]); int zGyro = ((cov ntaub ntawv [5] * 256) + cov ntaub ntawv [4]);

rau (int i = 0; i <6; i ++) {// Pib I2C Kev Xa Cov Hlau.beginTransmission (Addr_Accl); // Xaiv cov ntaub ntawv sau npe Wire.write ((40 + i)); // Nres I2C Kis Kab Hlau.endTransmission ();

// Thov 1 byte ntawm cov ntaub ntawv

Wire.requestFrom (Addr_Accl, 1);

// Nyeem 6 bytes ntawm cov ntaub ntawv

// xAccl lsb, xAccl msb, yAccl lsb, yAccl msb // zAccl lsb, zAccl msb yog (Wire.available () == 1) {data = Wire.read (); }}

// Hloov cov ntaub ntawv

int xAccl = ((data [1] * 256) + data [0]); int yAccl = ((cov ntaub ntawv [3] * 256) + cov ntaub ntawv [2]); int zAccl = ((cov ntaub ntawv [5] * 256) + cov ntaub ntawv [4]);

rau (int i = 0; i <6; i ++) {// Pib I2C Kev Xa Cov Hlau.beginTransmission (Addr_Accl); // Xaiv cov ntaub ntawv sau npe Wire.write ((8 + i)); // Nres I2C Kis Kab Hlau.endTransmission ();

// Thov 1 byte ntawm cov ntaub ntawv

Wire.requestFrom (Addr_Accl, 1);

// Nyeem 6 bytes ntawm cov ntaub ntawv

// xMag lsb, xMag msb, yMag lsb, yMag msb // zMag lsb, zMag msb if (Wire.available () == 1) {data = Wire.read (); }}

// Hloov cov ntaub ntawv

int xMag = ((data [1] * 256) + data [0]); int yMag = ((data [3] * 256) + data [2]); int zMag = ((data [5] * 256) + data [4]);

// Cov ntaub ntawv tso tawm rau tus saib xyuas

Serial.print ("X-axis ntawm kev sib hloov:"); Serial.println (xGyro); Serial.print ("Y-Axis ntawm kev sib hloov:"); Serial.println (yGyro); Serial.print ("Z-Axis ntawm kev sib hloov:"); Serial.println (zGyro); Serial.print ("Ua kom nrawm hauv X-Axis:"); Serial.println (xAccl); Serial.print ("Kev nrawm hauv Y-Axis:"); Serial.println (yAccl); Serial.print ("Ua kom nrawm hauv Z-Axis:"); Serial.println (zAccl); Serial.print ("Sib nqus teb hauv X-Axis:"); Serial.println (xMag); Serial.print ("Sib nqus teb hauv Y-Axis:"); Serial.println (yMag); Serial.print ("Sib nqus xa hauv Z-Axis:"); Serial.println (zMag);

// Tso cov ntaub ntawv rau lub web server

server.sendContent ("

DCUBE khw

www.dcubestore.com

"" LSM9DS0 Sensor I2C Mini Module

);

server.sendContent ("

X-axis ntawm kev sib hloov = " + Txoj hlua (xGyro)); server.sendContent ("

Y-Axis ntawm kev sib hloov = " + Txoj hlua (yGyro)); server.sendContent ("

Z-Axis ntawm kev sib hloov = " + Txoj hlua (zGyro)); server.sendContent ("

Kev nrawm hauv X-Axis = " + String (xAccl)); server.sendContent ("

Kev nrawm hauv Y-Axis = " + String (yAccl)); server.sendContent ("

Kev nrawm hauv Z-Axis = " + String (zAccl)); server.sendContent ("

Sib nqus foob hauv X-Axis = " + String (xMag)); server.sendContent ("

Sib nqus foob hauv Y-Axis = " + String (yMag)); server.sendContent ("

Sib nqus xa hauv Z-Axis = " + String (zMag)); ncua (1000);}

void teeb tsa ()

{// Initialise I2C kev sib txuas lus li MASTER Wire.begin (2, 14); // Initialise serial communication, set baud rate = 115200 Serial.begin (115200);

// Txuas rau WiFi network

WiFi.begin (ssid, password);

// Tos rau kev txuas

thaum (WiFi.status ()! = WL_CONNECTED) {ncua (500); Serial.print ("."); } Serial.println (""); Serial.print ("Txuas nrog"); Serial.println (ssid);

// Tau txais IP chaw nyob ntawm ESP8266

Serial.print ("IP chaw nyob:"); Serial.println (WiFi.localIP ());

// Pib server

server.on ("/", tus tuav tes); server.begin (); Serial.println ("HTTP server tau pib"); }

void lub voj ()

{server.handleClient (); }

Kauj Ruam 4: Ua Haujlwm ntawm Txoj Cai

Ua haujlwm ntawm Code
Ua haujlwm ntawm Code

Tam sim no, rub tawm (lossis git rub) cov cai thiab qhib nws hauv Arduino IDE.

Sau thiab xa cov cai thiab pom cov txiaj ntsig ntawm Serial Monitor.

Nco tseg: Ua ntej rub tawm, xyuas kom tseeb tias koj nkag mus rau koj li SSID network thiab tus password hauv tus lej.

Luam tus IP chaw nyob ntawm ESP8266 los ntawm Serial Monitor thiab muab tso rau hauv koj lub vev xaib. Koj yuav pom lub vev xaib nrog lub axis ntawm kev sib hloov, ua kom nrawm dua thiab nyeem daim teb sib nqus hauv 3-axis.

Cov txiaj ntsig ntawm lub ntsuas ntawm Serial Monitor thiab Web Server tau qhia hauv daim duab saum toj no.

Kauj Ruam 5: Cov ntawv thov thiab Nta

LSM9DS0 yog lub kaw lus-hauv-pob khoom suav nrog 3D digital linear acceleration sensor, 3D digital angular rate sensor, thiab 3D digital magnetic sensor. Los ntawm kev ntsuas peb yam khoom no, koj tuaj yeem tau txais txiaj ntsig zoo ntawm kev paub txog yam khoom txav. Ntsuas lub zog thiab kev taw qhia ntawm Lub Ntiaj Teb txoj kev sib nqus nrog lub tshuab ntsuas hluav taws xob, koj tuaj yeem kwv yees koj lub ncauj lus. Lub ntsuas cua hauv koj lub xov tooj tuaj yeem ntsuas qhov kev taw qhia ntawm lub zog nqus, thiab kwv yees kev taw qhia (duab, toj roob hauv pes, tiaj tus, thiab lwm yam). Quadcopters nrog built-in gyroscopes tuaj yeem saib tawm rau qhov ntog sai lossis cov suab. Peb tuaj yeem siv qhov no hauv Global Positioning System (GPS).

Qee qhov kev thov ntau ntxiv suav nrog Kev Taw Qhia Sab Hauv, Ntse cov neeg siv cuam tshuam, Kev paub piav tes piav taw siab, Kev Ua Si thiab cov khoom siv muaj tiag tiag, thiab lwm yam.

Nrog kev pab los ntawm ESP8266, peb tuaj yeem nce nws lub peev xwm kom ntev dua. Peb tuaj yeem tswj hwm peb cov cuab yeej siv thiab saib xyuas qhov ua tau zoo ntawm peb lub desktops thiab cov khoom siv mobile. Peb tuaj yeem khaws thiab tswj cov ntaub ntawv online thiab kawm lawv txhua lub sijhawm rau kev hloov kho. Ntau daim ntawv thov suav nrog Tsev Automation, Mesh Network, Muaj Wireless Tswj, Tus Saib Xyuas Me Nyuam, Sensor Networks, Wearable Electronics, Wi-Fi Qhov Chaw-paub Devices, Wi-Fi Position System Beacons.

Kauj Ruam 6: Cov peev txheej rau Mus Ntxiv

Yog xav paub ntxiv txog LSM9DS0 thiab ESP8266, txheeb xyuas qhov txuas hauv qab no:

  • LSM9DS0 Sensor Cov Ntaub Ntawv
  • LSM9DS0 Daim Kab Xev
  • Cov Ntaub Ntawv Keeb Kwm Dav Hlau rau ESP8266 los ntawm Kev Tshawb Dav Dav Dav

Pom zoo: