Enable Javascript

Last Arduino/ESP8266 project (click to open)

User Rating: 4 / 5

Star ActiveStar ActiveStar ActiveStar ActiveStar Inactive

Article Index

ESP8266 as Master
Arduino #1, Arduino #2, Arduino #n all as Multi Masters (for ESP8266 all only as Slave)

(click thumbnail)
Demo setup I²C bus: ESP8266 Master with two Arduinos Multi Masters

 Amica NodeMCU V2 DEVKIT with ESP8266-12E and the ESP8266-01
(Less pins as Arduino but with the I2C bus you can mount a whole series of Arduino's ;-)

ESP8266 and Arduino(s) - I²C versus Serial:
ESP8266 Communications with one Arduino? You can use HardwareSerial or SoftwareSerial, but upload and debug is a bit tricky.
ESP8266 Communications with one, or more than one, Arduino? You can use I²C or other standard I/O. With I²C you can connect multiple devices with only two pins/wires, and... with I²C you can use it in Multi Masters mode ;-) However, Arduino-ESP8266 I²C Slave mode is NOT yet implemented :-(
The I²C buffer is in comparison with Serial smal, but if necessary you can increase it.
File ESP8266: <drive>:\Users\<user>\AppData\Roaming\Arduino15\packages\esp8266\hardware\esp8266\<version>\libraries\Wire\Wire.h
#define BUFFER_LENGTH 32
File Arduino: <drive>:\<pathToArduino>\Arduino\hardware\arduino\avr\libraries\Wire\Wire.h
#define BUFFER_LENGTH 32
So with I²C: Every device can easily communicate with each other device using only two bidirectional lines.

I²C bus 3.3V ↔ 5V:
5V Arduino? Use a 3.3V↔5V 'Bi-Directional Level Converter' to save your ESP8266.
(NOT: TXI→TXO - RXO←RXI     BUT:  HV1↔HV2 - LV1↔LV2)

Pull-up resistors:
Use on each I²C signal line one pull-up resistor!
If using a 'Bi-Directional Level Converter' then on both sides one set resistors.

Multi Masters:
Master to Slave is simple: The Master ask and the Slave obeyed. But the slave can not independently send a message and have to wait for a call from Master.
Master to Master is also simple (provided that Multi Masters is implemented): The called Master is then Slave. The Multi Masters can communicate with each other on the same level.

Slave to ESP8266:
Unfortunately, Multi Masters is not yet implemented but in the ESP8266 loop() function you can test all Slaves if there is data ready.

Demo sketches on the next three pages.