Connecting 2 ESP8266 via serial

Hi
I am building an Enigma machine project, using ESP8266 devices to run different modules ( lightboard, keyboard, rotors, etc) and I'd like to communicate between the modules. I dont fancy having 5 or 6 of them talking via WiFi in a very small space (especially with the amount of extra coding involved). I would like them to talk to each other via serial using direct hardware TX/RX. My first attempts have not been successful : I know the sender is sending data but I'm not getting anything detected on the receiver. Can anyone direct me to some documents / examples of how this should be set up? I'd thought 2 x ESP8266 with one cable between them should be super simple... but apparently not.

Maybe:

Thanks - I saw that one but was hoping to just use standard RX/TX pins. Still if it comes to it I'll try software serial.

I think perhaps my testing issues are due to plugging in the USB to provide power. I've just read that it will intefere with the UART0, and it matches with my multiple messages about 'port busy' and nothing coming out on the serial monitor. I'll give it another bash in the morning.

If you want to communicate between the two ESPs and also Serial output to your PC over USB you have you set up two serial ports. Or are you just using one? You won't be able to connect the one connect to USB (usually Serial) to the TX and RX pins at the same time. You would have to use something like SoftwareSerial to build another serial port (like Serial1) to communicate between the two ESP boards. Just google "Software Serial ESP8266" and you'll find a whole bunch of tutorials out there.

But may I ask, why are you using multiple boards in a small area? Are you running into pin limitations? Or processing limitations? Because if you're running out of pins, there are GPIO expanders that get you additional GPIO pins that communicate over I2C which are much easier to implement than a whole other microcontroller.

Hi yes I have one ESP8266 running a 4x74HC595 shift register board to run my 'lightboard', then I have another one running 4 x OLED displays through an i2c multiplexer, then another one running a keyboard interface, and another running some multiplexed optical sensors, and some servo motors for the encoding rotors. There's also another one running the encryption code. There's some communication between all the nodes, but its pretty minimal and its not time sensitive. I could do it all in yet another all software emulator, but that is not the challenge, which is to create a device that has large amounts of hardware interaction. Based on the code complexity I'd prefer to have each hardware module have its own microcontroller, and just send the odd bit of data to a related node. I don't think I'll need a 'communication hub' node that has a load of software serial ports.

You're going to communicate between 5 boards using one serial port? How exactly are you going to accomplish this? You're going to have messages crashing into each other. That's not going to work. If you want to communicate with 4 other boards with serial you're going to need 4 serial ports on each board and keep track of which is which to communicate between them. Take the problem of sending a simple acknowledgement to a message. Board 1 sends out a message to boards 4-5. When boards 4-5 go to send a response, all the messages are going to crash into each other if you are trying to send them all on the same serial line.

The only way to do this would be to write your own management protocol for the communication which is going to take you longer than any of the feasible alternatives would be.

What you are talking about is much more complex than simply running everything off one microcontroller (like an ESP32). Short of that, it would be much easier to have one central controller board communicating to the other 5 through I2C. Something that allows for two way communication but allows for many devices to occupy the same bus because there is one master device with many slave devices. The slaves only communicate with the master when they are told to. That way messages don't crash into each other.

you have microcontrollers with onboard WiFi and you use are using serial communications?
have a look at esp-now-esp8266-nodemcu which is very simple to use and enables direct WiFi communication between multiple ESP8266 nodes

No, not 5 boards one port. There's a heirarchy of communications, which only require one or maybe 2 serial communications from any one board.

If it comes to it , I would use WiFi. But the constraints are to make it as mechanical as possible, with electronic support, rather than starting with an electronic solution. I could do 100% in software, so that is not the point. This is a leisure exercise, not an industrial project :slight_smile:

if you wish to connect multiple devices using serial consider using a RS485 bus

1 Like

If you don't use the WiFi, why not using core Arduino (nano?) and connecting with RS485 like horace say? RS485 Modbus is an industrial standard. Take ESP32 als master, then you have 2 serial ports. One for debugging/programming and one for the RS485. Pay attention RS485 is half duplex with one master and multiple slaves.

I may do that, but as mentioned elsewhere serial.swap likely gives me enough serial connectivity. As its an enigma machine its primarily a model, supported by electronics. I cant get my head around an Enigma machine transmitting WiFi :slight_smile:

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.