Cov txheej txheem:

I2C Relay ntsib Arduino IDE: 5 Cov Kauj Ruam
I2C Relay ntsib Arduino IDE: 5 Cov Kauj Ruam

Video: I2C Relay ntsib Arduino IDE: 5 Cov Kauj Ruam

Video: I2C Relay ntsib Arduino IDE: 5 Cov Kauj Ruam
Video: I2C with Arduino and Raspberry Pi - Two Methods 2024, Hlis ntuj nqeg
Anonim
I2C Relay ntsib Arduino IDE
I2C Relay ntsib Arduino IDE

Kuv xaj cov ntawv xa xov zoo tab sis tsis muaj kev qhia ArduinoIDE, tsuas yog Raspberry Pi e.o. Kuv pom yuav siv nws nrog Arduino thiab xav qhia nws kom koj tuaj yeem txuag lub sijhawm ntawd.

Thawj RaspberryPi piv txwv:

wiki.52pi.com/index.php/DockerPi_4_Channel_Relay_SKU:_EP-0099

Qhov zoo yog tias koj tuaj yeem sib sau tau txog 4 daim txiag. Yog li koj tuaj yeem siv max. 4 x 4 = 16 tus xa tawm ntawm ib lub tsheb npav I2C.

Tseem muaj qee qhov tsis zoo:

  • terminas me me, tsis haum 1 mm2 xaim
  • koj tsis tuaj yeem hloov txoj hlua ntawm cov txuas hauv qab thaum lawv tau teeb ua ke

Tab sis tseem siv tau cov board.

Kauj ruam 1: Wirering

Hlau
Hlau
Hlau
Hlau
Hlau
Hlau

Hauv cov duab koj tuaj yeem pom cov xov hlau.

52Pi xav tau ob qho tib si 5V (rau relay's) en 3.3V (I2C chip).

Yog li 5 xaim xav tau:

  • GND to CSY
  • 5v rau 5v
  • 3.3 V rau 3.3 V
  • SLA to SWV
  • SCL to CSY

Yog tias koj siv Arduino UNO lossis lwm 5 V yog cov khoom siv ntawm qhov siab tshaj 3, 6 V los ntawm I2C maub los! Siv cov tshuaj tiv thaiv lossis lwm yam kom txo 5 V tawm ntawm Arduino PIN's!

Kauj Ruam 2: Piv Cai Yooj Yim:

/* Arduino IDE (ESP) piv txwv rau I2C relaisboard.

* Los ntawm Laurens Korste www.boktorrobotica.nl * siv dawb. */ #include // rau I2C kev sib txuas lus tsis muaj teeb meem () {// txoj cai no tsis yog rau UNO lossis cov laug cam uas mob siab rau I2C pins Wire.begin (D1, D2); // koom nrog i2c npav nrog SDA = D1 thiab SCL = D2 rau NodeMCU} void loop () {Wire.beginTransmission (0x10);/ * pib kis mus rau I2C chaw nyob 10 (kom hloov mus rau 11, 12 lossis 13) */ Hlau.write (0x01); / * xaiv relais 1 (tawm ntawm 4) ntawm board 10 (tseem 0x02, 0x03, 0x04) */ Wire.write (0xFF); /* teeb tsa relais 1 ntawm board 10 rau ON. txhua tus lej> 0 yuav ua li ntawd */ Wire.endTransmission (); / * nres kev xa xov */ ncua (3000); Wire.beginTransmission (0x10); / * */ Wire.write (0x01); Hlau.write (0x00); / * teeb tsa relais 1 ntawm board 10 rau OFF */ Wire.endTransmission (); / * nres kev xa xov */ ncua (3000); }

Kauj Ruam 3: Plaub Relay Test Code

/* kos duab los ntawm Laurens Korste rau Arduino (ESP / NodeMCU)

* Tab sis lwm cov laug cam tseem yuav ua tau * www.boktorrobotica.nl * Hauv qhov no skeych al 4 relay's yuav tau qhib ua kom tsis ua haujlwm */ #include // rau I2C kev sib txuas lus tsis muaj teeb tsa () {Serial.begin (115200); // pib serial rau debug (9600 rau UNO) Wire.begin (D1, D2); // koom nrog i2c tsheb npav nrog SDA = D1 thiab SCL = D2 ntawm NodeMCU tsis xav tau UNO} void loop () {rau (int i = 1; i <= 4; i ++) {Wire.beginTransmission (0x10); // pib nrog ntaus ntawv chaw nyob Wire.write (i); // xaiv qhov relais Wire.write (0xFF); // xa tus lej "ntawm" code FF (txhua qhov suav los ntawm 01 rau FF yuav ua) Wire.endTransmission (); // nres kis Serial.write (i); Serial.println ("aan"); ncua (1000); Wire.beginTransmission (0x10); // pib nrog ntaus ntawv chaw nyob Wire.write (i); Hlau.write (0x00); // Xa qhov "tawm" code Wire.endTransmission (); // nres kis Serial.write (i); Serial.println ("ua"); ncua (1000); }}

Kauj ruam 4: Kuv Qhov Project

Kuv Qhov Project
Kuv Qhov Project
Kuv Qhov Project
Kuv Qhov Project

Kuv tau sau ib txoj cai los ua haujlwm kuv 3 lub qhov rooj qhov no tuaj yeem ua tiav nrog cov hloov pauv tab sis kuj tseem nrog BLYNK app, Saib duab.

  • Ib qho xovxwm luv luv yuav pib txav ib lub shutter (lossis nres nws thaum nws txav mus).
  • Ib lub xovxwm ntev thiab tag nrho peb lub qhov rooj qhib (lossis kaw lossis nres).
  • Ob chav siab: lub qhov rooj mus rau qhov "qhov" txoj haujlwm.

Raws li tuaj yeem pom hauv daim duab, Kuv kuj suav nrog ntsuas kub thiab lub teeb pom kev zoo.

Tam sim no txhua yam ntawm lub hauv paus PCB zoo thiab ua kom zoo nyob hauv ib lub thawv.

Kauj Ruam 5: Hu Xov Tooj Relay Nrog Ib Qhov Lus txib

Nws muaj txiaj ntsig yog tias koj tsuas yog xav tau ib lo lus txib kom qhib lossis ua kom tsis txhob rov ua haujlwm dua. Hauv qab no yog lub luag haujlwm uas tuaj yeem ua qhov no (nrog lowbyte thiab highbyte).

/ * kos duab los ntawm Laurens Korste rau Arduino (ESP/NodeMCU) nrog I2C relaysboard * Tab sis lwm cov laug cam tseem yuav ua * href = https://www.boktorrobotica.nl; www.boktorrobotica.nl * https://wiki.52pi.com/index.php/DockerPi_4_Channel_Relay_SKU: _EP-0099; www.boktorrobotica.nl * Hauv daim duab qhia no, kev xa xov yuav raug qhib los ntawm ib qho hu; * // #include // rau I2C kev sib txuas lus // Tshaj tawm tshaj tawm. 4 PCB's Per PCB 4 qhov hloov pauv tau. Hauv qhov kos duab no tsuas yog ob lub PCB // PCB thiab kev xa tawm tau koom ua ke kom lawv tuaj yeem hu nrog ib qho lus txib const byte PutOn = 0xFF; // hais kom hloov ntawm const byte PutOff = 0x00; // comand kom hloov tawm const lo lus Relay1bord1 = 0x1001; // koj tuaj yeem muaj lub npe los ntawm qhov piv txwv Relay1 const lo lus Relay2bord1 = 0x1002; // koj tuaj yeem muaj sijhawm los ntawm cov npe piv txwv Relay2 const lo lus Relay3bord1 = 0x1003; // koj tuaj yeem muaj sijhawm los ntawm cov npe piv txwv Relay3 const lo lus Relay4bord1 = 0x1004; // koj tuaj yeem muaj lub npe los ntawm qhov piv txwv Relay4 const lo lus Relay1bord2 = 0x1101; // koj tuaj yeem muaj sijhawm los ntawm cov npe piv txwv Relay5 const w ord Relay2bord2 = 0x1102; // koj tuaj yeem muaj sijhawm los ntawm cov npe piv txwv Relay6 const lo lus Relay3bord2 = 0x1103; // koj tuaj yeem muaj sijhawm los ntawm cov npe piv txwv Relay7 const lo lus Relay4bord2 = 0x1104; // koj tuaj yeem muaj sijhawm los ntawm cov npe piv txwv Relay8 const lo lus Relay1bord3 = 0x1201; // koj tuaj yeem muaj sijhawm los ntawm cov npe piv txwv Relay9 const lo lus Relay2bord4 = 0x1302; // koj tuaj yeem muaj sijhawm los ntawm cov npe piv txwv Relay14 tsis muaj teeb meem teeb tsa () {Serial.begin (115200); // pib serial rau debug (9600 rau UNO) Wire.begin (D1, D2); // koom nrog i2c npav nrog SDA = D1 thiab SCL = D2 ntawm NodeMCU tsis xav tau UNO} void loop () {// los hloov relay 4 ntawm PCB 2 ntawm RelayActie (Relay4bord2, PutOn); ncua (1000); // txhawm rau hloov relay 4 ntawm PCB 2 tawm RelayActie (Relay4bord2, PutOff); ncua (1000); } void RelayActie (lo lus Relay, byte OnOrOff) {Wire.beginTransmission (highByte (Relay)); Wire.write (lowByte (Relay)); Wire.write (OnOrOff); Wire.endTransmission (); }

Pom zoo: