Cov txheej txheem:

Tus Nqi Tus Kheej Tsis Zoo Nrog ESP01: 19 Cov Kauj Ruam
Tus Nqi Tus Kheej Tsis Zoo Nrog ESP01: 19 Cov Kauj Ruam

Video: Tus Nqi Tus Kheej Tsis Zoo Nrog ESP01: 19 Cov Kauj Ruam

Video: Tus Nqi Tus Kheej Tsis Zoo Nrog ESP01: 19 Cov Kauj Ruam
Video: Hlub Yus Tus Kheej | Kong Chue (Full Audio with Lyrics) New Hmong Song Nkauj Tawm Tshiab 2021 2024, Kaum ib hlis
Anonim
Image
Image
NPE 2306
NPE 2306

Hnub no, peb yuav tham txog kev siv tshuab siv ESP01 nrog 16 qhov xa tawm. Nov yog tus qauv tsim qauv pheej yig tshaj plaws uas koj tuaj yeem muab cov lej hloov pauv thiab nce mus txog 128 qhov xa tawm, vim tias nws muaj peev xwm tso tau txog yim qhov chaw nres nkoj nthuav dav hauv lub microcontroller no.

Hauv peb qhov kev sib tham, koj yuav muaj daim ntawv thov ntawm lub xov tooj smartphone uas sib txuas lus nrog ESP01. Nws yuav muaj qhov nthuav dav nrog 16 chaw nres nkoj, txhua qhov txuas nrog kev xa xov. Peb kuj muaj 3v3 qhov hloov pauv tau. Yog li peb yuav tswj hwm 16-channel kev xa xov qauv siv ESP01 los ntawm Android daim ntawv thov, uas kuv ua rau koj muaj.

Kauj ruam 1: Ntsis kom nco qab

Nws yog ib qho tseem ceeb kom nco ntsoov, kuv cov phooj ywg, tias kuv tau siv cov nti no hauv Circuit Court hu ua MCP23016. Nws tseem ceeb heev rau koj saib daim vis dis aus EXPANSOR OF IOS FOR ESP32, ESP8266 THIAB ARDUINO, qhov uas kuv sim ntaus ntawv thiab qhia tias nws ua haujlwm rau peb hom ntawm cov laug cam no.

Kauj Ruam 2: MCP23016

Ntawm no peb muaj cov duab ntawm MCP23016, uas yog cov nti nrog 28 tus pin. Nws tseem ceeb uas yuav tau hais txog tseem muaj tus qauv MCP23017, uas yog ntau dua thiab tsis xav tau tus tiv thaiv thiab lub peev xwm, vim tias nws muaj lub moos sab hauv. Qhov no ua rau nws yooj yim dua, tab sis nws tus pinning txawv ntawm qhov peb qhia hauv daim vis dis aus no.

Kauj Ruam 3: Chaw Nyob

Chaw nyob
Chaw nyob

Txhawm rau txheeb xyuas qhov chaw nyob ntawm MCP23016, peb siv tus pin A0, A1, thiab A2. Koj tuaj yeem tso lawv ntawm HIGH lossis LOW rau qhov chaw nyob hloov pauv.

Qhov chaw nyob yuav tsim raws li hauv qab no:

MCP_Address = 20 + (A2 A1 A0)

Qhov twg A2 A1 A0 tuaj yeem nqa qhov siab / qis, tus lej binary los ntawm 0 txog 7 daim ntawv.

Piv txwv li:

A2> GND, A1> GND, A0> GND (txhais tau tias 000, ces 20 + 0 = 20)

Los yog lwm yam, A2> HIGH, A1> GND, A0> HIGH (txhais tau tias 101, tom qab ntawd 20 + 5 = 25)

Kauj ruam 4: Cov lus txib

Hais kom ua
Hais kom ua

Nov yog lub rooj nrog cov lus txib rau kev sib txuas lus:

Kauj Ruam 5: Pawg

GP0 / GP1 - Cov Chaw Teev Npe Cov Ntaub Ntawv

Muaj ob daim ntawv sau npe uas nkag mus rau ob lub GPIO chaw nres nkoj.

Kev sau npe sau qhia qhov xwm txheej ntawm tus pin ntawm qhov chaw nres nkoj ntawd.

Bit = 1> HIGH Bit = 0> LOW

IODIR0 / IODIR1

Muaj ob daim ntawv sau npe uas tswj tus lej tus pin. (Tawm tswv yim lossis tso tawm)

Bit = 1> INPUT Bit = 0> OUTPUT

Kauj Ruam 6: Tus Qauv rau Kev Sib Txuas Lus

Qauv rau Kev Sib Txuas Lus
Qauv rau Kev Sib Txuas Lus

Ntawm no peb tham txog qhov chaw nyob ntawm lub nti, thiab nkag mus rau cov lus txib thiab cov ntaub ntawv, uas yog ib hom txheej txheem uas yuav tsum tau ua kom tiav los xa cov ntaub ntawv.

Kauj Ruam 7: Txoj Haujlwm

Program
Program

Peb yuav ua ib txoj haujlwm uas muaj kev sib txuas lus ESP01 nrog MCP23016 txhawm rau kom muaj GPIOs ntau dua los siv. Cov 16 GPIOs tshiab no uas peb yuav muaj yuav tswj hwm 16-channel relay module.

Cov lus txib yuav raug xa mus rau ESP01 ntawm daim ntawv thov Android.

Kauj Ruam 8: MCP23016

NPE 2306
NPE 2306

Kauj Ruam 9: ESP-01

ESP-01
ESP-01
ESP-01
ESP-01

Qhov no yog 16-pawg thawj coj saib xyuas.

Kauj ruam 10: Mounting ESP01

Mounting ESP01
Mounting ESP01

Kauj Ruam 11: Cov Tsev Qiv Ntawv thiab Cov Txiaj Ntsig

Peb yuav suav nrog cov tsev qiv ntawv lub luag haujlwm rau i2c kev sib txuas lus, thiab rau kev tsim Access Point thiab webserver. Peb txheeb xyuas qhov chaw nyob ntawm cov nti thiab cov chaw nres nkoj. Thaum kawg, peb txiav txim siab qhov txawv txav khaws cov txiaj ntsig ntawm MCP pins.

#include // responsável pela comunicação i2c. #suav nrog // responsável por criar o accesspoint eo webserver WiFiServer server (80); // webserver para acessarmos através do aplicativo // endereço I2C do MCP23016 #define MCPAddress 0x20 // ENDISEÇOS DEEG txhais GP0 0x00 // DATA PORT REGISTER 0 #define GP1 0x01 // DATA PORT REGISTER 1 #define IODIR0 0x06 // I/O DIRECTION REGISTER 0 #deine IODIR1 0x07 // I/O DIRECTION REGISTER 1 // guarda os valores dos pinos ua MCP uint8_t currentValueGP0 = 0; uint8_t currentValueGP1 = 0;

Kauj ruam 12: Teeb tsa

Peb pib ESP01 thiab teeb tsa cov chaw nres nkoj. Peb kuj teeb tsa lub Access Point thiab pib ua haujlwm rau server.

teeb tsa tsis muaj dab tsi () {Serial.begin (9600); ncua (1000); Hlau.begin (0, 2); // ESP01 Wire.setClock (200000); configurePort (IODIR0, OUTPUT); configurePort (IODIR1, OUTPUT); writeBlockData (GP0, 0x00); writeBlockData (GP1, 0x00); setupWiFi (); // configuração ua Access Point server.begin (); // inicializa o server}

Kauj ruam 13: Loop

Ntawm no kuv tshawb xyuas yog tias muaj cov neeg siv tau txuas nrog lub server. Peb kuj nyeem thawj kab ntawv thov. Peb rho cov ntaub ntawv rau kev tswj hwm, txhais lub ntsiab lus teb tsis raug, thiab xa cov lus teb no rau tus neeg siv khoom.

void loop () {WiFiClient tus neeg siv = server.available (); // Verifica se um cliente foi conectado if (! Client) {xa rov qab; } String req = client.readStringUntil ('\ r'); // Faz a leitura da primeira linha da requisição/ */MR é o header prefixo para saber se a requisição é esperada para os relés */if (req.indexOf ("/MR")! = -1) {parserData (req); // a partir da requisição extrai os dados para manipulação} else {Serial.println ("thov tsis raug"); rov qab; } client.flush (); cov. Txoj hlua s = "HTTP/1.1 200 OK / r / n"; // cabeçalho padrão de resposta client.print (s); // envia a resposta para o cliente ncua (1); } // kawg lub voj

Kauj ruam 14: ParserData

ParserData
ParserData

Los ntawm qhov kev thov, peb saib cov ntaub ntawv cuam tshuam nrog kev xa tawm. Peb xa cov ntaub ntawv mus rau MCP23016.

// a partir da requisição busca os dados referente aos relésvoid parserData (String data) {uint8_t relay = -1; uint8_t gp = -1; uint8_t tus nqi = -1; int index = data.indexOf ("/MR"); // busca o index ua prefixo MR yog (data [index+5] == '/') ///MR01/1, onde 0 = GP; 1 = RAWS; 1 = ESTADO (rau/tawm) {gp = data [index+3]-'0'; relay = cov ntaub ntawv [index+4]-'0'; tus nqi = cov ntaub ntawv [index+6]-'0'; // envia os dados para o MCP23016 // [relay-1] porque o MCP vai de 0-7 os pinos writePinData (relay-1, tus nqi, gp); }}

Kauj ruam 15: ConfigurePort

Peb teeb tsa GPIO tus pin hom (GP0 lossis GP1).

// configura o modo dos pinos GPIO (GP0 ou GP1) // como parametro passamos: // port: GP0 ou GP1 // INPUT para todos as portas do GP trabalharem como entrada // OUTPUT para todos as portas do GP trabalharem como saida // custom um valor de 0-255 indicando o modo das portas (1 = INPUT, 0 = OUTPUT) // ex: 0x01 ou B00000001 ou 1: indica que apenas o GPX.0 trabalhará como entrada, o restante como saida void configurePort (uint8_t chaw nres nkoj, uint8_t kev cai) {yog (kev cai == INPUT) {writeBlockData (chaw nres nkoj, 0xFF); } lwm tus yog (kev cai == OUTPUT) {writeBlockData (chaw nres nkoj, 0x00); } lwm {writeBlockData (chaw nres nkoj, kev cai); }}

Kauj ruam 16: WritePinData

Hauv ib feem ntawm txoj cai, peb hloov lub xeev ntawm tus pin xav tau thiab xa cov ntaub ntawv mus rau MCP.

// muda o estado de um pino desejado, passando como parametro: // pin = pino desejado; tus nqi = 0/1 (rau/tawm); gp = 0/1 (PORT do MCP) void writePinData (tus pin, tus nqi int, uint8_t gp) {uint8_t xwm txheej GP = 0; yog (gp == GP0) statusGP = currentValueGP0; lwm qhov xwm txheej GP = currentValueGP1; yog (tus nqi == 0) {statusGP & = ~ (B00000001 << (tus pin))); // muda o pino para LOW} lwm tus yog (tus nqi == 1) {statusGP | = (B00000001 << (tus pin)); // muda o pino para HIGH} yog (gp == GP0) currentValueGP0 = statusGP; lwm qhov currentValueGP1 = statusGP; // envia os dados para o MCP writeBlockData (gp, statusGP); ncua (10); }

Kauj ruam 17: SauBlockData & SetupWiFi

Ntawm no, peb xa cov ntaub ntawv mus rau MCP23016 ntawm lub npav i2c. Tom ntej no, peb teeb tsa cov khoom kom pab tau Access Point. Thaum kawg, peb teeb tsa WiFi rau Access Point hom thiab tsim AP nrog SSID thiab PASSWORD.

// envia dados para o MCP23016 através do barramento i2c // reg: REGISTRADOR // data: dados (0-255) void writeBlockData (uint8_t chaw nres nkoj, uint8_t data) {Wire.beginTransmission (MCPAddress); Wire.write (chaw nres nkoj); Wire.write (cov ntaub ntawv); Wire.endTransmission (); ncua (10); }

// configura as propriedades para habilitar o ACCESS POINTvoid setupWiFi () {WiFi.mode (WIFI_AP); WiFi.softAP ("ESP01_RELAY", "12345678"); }

Kauj ruam 18: App

App
App
App
App
App
App
App
App

Txhawm rau tsim daim ntawv thov, peb siv MIT App Inventor 2, uas tuaj yeem nkag mus tau los ntawm qhov txuas:

ai2.appinventor.mit.edu/

Daim ntawv thov muaj ob lub ntxaij vab tshaus uas muaj yim khub ntawm cov nyees khawm hauv txhua qhov, qhia qhov xwm txheej ntawm txhua qhov kev xa tawm.

Cov hauv qab no yog qee qhov ntawm cov phiaj xwm kev siv:

TSEEM CEEB: Qhov chaw nyob IP ntawm ESP, raws li Access Point yog 192.168.4.1

1. Thaum lub vijtsam pib, peb khaws tus IP hauv kev nco thiab hu rau tus txheej txheem kom rov zoo lub xeev ntawm cov nyees khawm (ON / OFF).

2. Hu rau lwm lub vijtsam

1. Thaum nyem rau ntawm ON khawm ntawm ib qho ntawm kev xa tawm, peb yuav ua qhov muag pom ntawm lub pob (ntsuab thaiv). WebViewer1. GoToUrl thov rau peb ESP01 los ntawm kev txuas MR01 / 1 cov ntaub ntawv hauv URL.

2. Thaum nias lub OFF khawm ntawm ib qho ntawm cov relays, peb yuav ua kom pom kev hloov pauv ntawm lub pob (thaiv ntsuab). WebViewer1. GoToUrl thov rau peb ESP01 los ntawm kev txuas MR01 / 0 cov ntaub ntawv hauv URL.

Cov txheej txheem no yog siv los rov qab lub xeev ntawm cov nyees khawm (txuas), vim tias thaum hloov lub vijtsam, nws rov qab mus rau qhov tsim qauv.

Cov thaiv daj rov ua dua rau txhua tus khawm khawm.

Kauj ruam 19: Rub tawm

Nov yog cov phiaj xwm phiaj xwm rau rub tawm:

MIT App Inventor 2 qhov project file - rub tawm

Daim ntawv thov APK rau nruab rau hauv - rub tawm

Rub tawm lwm cov ntaub ntawv:

PDF

INO

Pom zoo: