====== NodeMCU I²C kommunikáció ======
A NodeMCU a legegyszerűbben a serial porton kommunikál, de ezesetben lefoglalja a serialt, így a serial monitor sem használható ezzel egy időben. Egyszerű megoldást kínál az I²C alkalmazása, így a serial továbbra is használható marad.
További, hasonló témakörök az oldalon:
* [[hu:arduino:start#arduino_i2c|Arduino I²C összefoglalás]]
* [[hu:arduino:comm_example#arduino_i_c_kommunikacio|Arduino I²C megoldások]]
* [[hu:comm:bus_i2c|I²C általános leírása]] \\
===== NodeMCU I²C kommunikáció Arduino-val =====
{{:hu:esp:nodemcu_i2c_wiring.png?400|nodeMCU I²C kommunikáció Arduino-val}}
==== NodeMCU I²C kommunikáció Arduino-val, kódok ====
NodeMCU oldal: \\
#include
void setup() {
Serial.begin(9600); /* begin serial for debug */
Wire.begin(1, 2); /* join i2c bus with SDA=D1 and SCL=D2 of NodeMCU */
}
void loop() {
Wire.beginTransmission(8); /* begin with device address 8 */
Wire.write("Hello Arduino"); /* sends hello string */
Wire.endTransmission(); /* stop transmitting */
Wire.requestFrom(8, 13); /* request & read data of size 13 from slave */
while(Wire.available()){
char c = Wire.read();
Serial.print(c);
}
Serial.println();
delay(1000);
}
Arduino oldal: \\
#include
void setup() {
Wire.begin(8); /* join i2c bus with address 8 */
Wire.onReceive(receiveEvent); /* register receive event */
Wire.onRequest(requestEvent); /* register request event */
Serial.begin(9600); /* start serial for debug */
}
void loop() {
delay(100);
}
// function that executes whenever data is received from master
void receiveEvent(int howMany) {
while (0