Hello
My project consists of
Arduino mega 2650
Esp32
Ethernet module (w5500)
...
Esp32 will be responsible for receiving 30 feedback (using shift register)
..
Arduino mega will be responsible for communicating with server through Ethernet module and sending commands to sensors
..
Arduino mega and Ethernet module
Will be communicating using SPI
...
What is the best protocol to use between Arduino mega and Esp32
And i will use Mega as the Master is there is any advice or problem i will face ?
I anticipate some questions later regarding your major design decisions and some requests for further clarification of what you are doing.
However, directly to your question:
If the ESP32 and Arduino Mega are directly wired together (that is not communicating over the network you seem to have - WiFi/Ethernet) then bear in mind that there will be some restriction on the length of wires that can be used and there will be the problem of matching 3.3v/5.0v devices with some sort of level shifting. Maybe a simple serial connection (2 wires plus shared ground) could be an option.
Can you explain this in more detail:
First thanks for replying
..
- Yes ESP32 and Arduino Mega are directly wired together
- i know that for SPI i have 20cm limit but it's not a problem they are next to each other
- Esp32 pins are 3.3V and arduino are 5V i read few project some of them used voltage divider other don't
does it depend on the Communcation protocol to use voltage divider ?
Communication between Ethernet module and Arduino has to be SPI
i have two options First to use SPI again between Arduino and ESP32 that will make
ESP32 and Ethernet module slaves (Arduino can't communicate with both of them at the same moment )
Second i can use UART or I2C between Arduino and ESP32 but i have no experience in doing that so i don't know if both protocols will work at the same time fine
and wether i will need to use voltage divider or not
ESP32 will be responsible for recieving date from 30 sensort (digital input ON/Off )
and when one of sensors state changes it sends data to Arduino
i will use shift register to minimize number of pins i need from ESP32
i was just wondering if that will affect the communication protocol
Why are you using an esp32 if not for the WiFi or Bluetooth? The Mega should be able to handle everything by itself.
Both the ESP32 and the Mega/w5500 could, I suppose, use IP to to talk to each other. Or are you not using the WLAN functionality of the ESP32 ?
Anyway, if you want to use Serial/UART, both the Mega and the ESP32 have multiple hardware serial ports over which they could exchange data. It is quite simple and you could start with this tutorial: Serial Input Basics - updated
The TX pin of the Mega should have a voltage divider to present a maximum of 3.3 volts to the RX pin of the ESP32. The other direction is not so critical but you should also consider a proper 3.3v/5v level shifter.
- ESP32 wifi doesn't have perfect WiFi signal i will use it's WiFi as backup to set configurations of network when the system can't access netwok through ethernet
- second i have so many outputs and inputs i will need both of them .
- ESP32 has multithreading so it will be good for handling feedback .
- i need them to be connected directly without network so any problems in network can't affect them
- UART have slow speed compared to I2C or SPI
so if i use one of them (i2C or SPI ) how i'm suppose to connect voltage divider ?
OK. If your speed requirements rule out Serial/UART then look at I2C or SPI. Use a level converter like the one illustrated: https://www.ebay.com/itm/402082660820

This is how you can go between Mega nd ESP32 using I2C Bus.

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