help communicating between microcontrollers

Hi everyone,
I am using 10 different Arduino boards in my project and each of those boards uses either I2C or SPI or Serial or a combination of these to talk to different sensors. Additionally, these boards are separated from each other by 10 cm to 5 meters. i want to have a master board that talks to these 10 boards and give them instructions as to what to do but I can't figure out a way to achieve this. i was wondering if anyone has any ideas of how I can attack this problem (i prefer not to use SPI or I2C for this purpose).

thank you so much!

these boards are separated from each other by 10 cm to 5 meters

A CAN bus would be fine.

sarah20:
(i prefer not to use SPI or I2C for this purpose).

You have 10 Arduino Boards, and you want to connect them together using UART Ports. The MEGA has only 4 UART Ports + 1 more SUART Port (soft UART). So, you can not proceed with UART topology. The alternative is to use either SPI Port or I2C Bus..

ard_newbie:
these boards are separated from each other by 10 cm to 5 meters

A CAN bus would be fine.

I dont know anything about this commu protocol but ill search it up! thanks!

If it was my project I would first experiment to see if I2C would work. See this Arduino to Arduino I2C Tutorial

This sort of communication should be designed into the system from the start.

You could use Serial for the communication with all the slaves communicating directly with the master on a single Rx and Tx on the master. You need to isolate the Tx for each slave from the Rx for the master with a diode that prevents the 5v from the slave Tx getting to the master Rx. At the master Rx there needs to be a pullup resistor - 4k7 or 5k6 works. Obviously the master must control the communication so that only one slave can talk at any one time.

...R

ard_newbie:
these boards are separated from each other by 10 cm to 5 meters

A CAN bus would be fine.

A CAN bus controller is very expensive. And you can imagine that to use one CAN controller for every board. The OP has 10 boards. It will be very expensive.

I prefer SPI, but 9 other pins should be free on the master Arduino, in order to use these pins as the Slave Select pin for every slave Arduino.

.. Arnav

ArnavPawarAA:
A CAN bus controller is very expensive. And you can imagine that to use one CAN controller for every board. The OP has 10 boards. It will be very expensive.

I prefer SPI, but 9 other pins should be free on the master Arduino, in order to use these pins as the Slave Select pin for every slave Arduino.

.. Arnav

You were right about the prices. i think i might be able to change some of my sensors to free up my SPI on all the macros for this purpose. but is there any limitations on the SPI in how far the two micros can be? like I2C is less than a meter...

sarah20:
like I2C is less than a meter...

I2C should work over a much longer distance. I have had it working at 2 metres and this MegaPoints YouTube Video shows I2C working over 100m of cable. The MegaPoints boards use Atmega microprocessors.
...R

sarah20:
You were right about the prices. i think i might be able to change some of my sensors to free up my SPI on all the macros for this purpose. but is there any limitations on the SPI in how far the two micros can be? like I2C is less than a meter...

SPI and I2C are very different.

I2C is a low level communication protocol, it operates in short distances (50-75m) and it has very slow data transmission speeds. So a I2C bus can be formed, but the 10 boards should be in very strict synchronisation and if it failed, then the whole system will fail.

SPI is better than I2C, because it uses a Slave select pin which determines which slave will talk to the master. SPI is faster, efficient, and reliable. Just the master will need 9 free pins for the Slave select of the 9 slave boards.

..Arnav

ArnavPawarAA:
SPI and I2C are very different.

I2C is a low level communication protocol, it operates in short distances (50-75m) and it has very slow data transmission speeds. So a I2C bus can be formed, but the 10 boards should be in very strict synchronisation and if it failed, then the whole system will fail.

SPI is better than I2C, because it uses a Slave select pin which determines which slave will talk to the master. SPI is faster, efficient, and reliable. Just the master will need 9 free pins for the Slave select of the 9 slave boards.

..Arnav

thank you, im implementing the SPI system and my tests so far were successful. my only issue is with a few of my sensors that use spi to communicate with the Arduino boards (as spi protocol only allows one master). i guess i have to change my sensor!

sarah20:
thank you, im implementing the SPI system and my tests so far were successful. my only issue is with a few of my sensors that use spi to communicate with the Arduino boards (as spi protocol only allows one master). i guess i have to change my sensor!

No! No need to change the sensor. You can use software SPI which is like a another virtual SPI. Please don't waste money on buying new sensors. No need!

..Arnav

SoftwareSPI is going to have the same shortcoming as SoftwareSerial - a large computational burden on the Arduino.

...R

10 cm to 5 meters

why do you need separate Arduinos within 10cm? If you could reduce the Arduinos it will make your live a lot easier. For example, change some UNOs to one MEGA.

regarding the distance of up to 5m, I suggest against SPI and I2C.

CAN was already mentioned, most come with an SPI interface, and you probably can overcome the issue with other sensors on SPI if you have just one (problematic) sensor and the CAN Module on an UNO. And who ever told you CAN Bus were expensive - these modules are sold as cheap as 1.27 USD! (!!!)

RS485 is as bus, which can be used very similar with a serial connection.

ArnavPawarAA:
No! No need to change the sensor. You can use software SPI which is like a another virtual SPI. Please don't waste money on buying new sensors. No need!

..Arnav

i know about the softwareSPI but it can be problematic if i am using my interrupt pins on the Arduino.

noiasca:
why do you need separate Arduinos within 10cm? If you could reduce the Arduinos it will make your live a lot easier. For example, change some UNOs to one MEGA.

regarding the distance of up to 5m, I suggest against SPI and I2C.

CAN was already mentioned, most come with an SPI interface, and you probably can overcome the issue with other sensors on SPI if you have just one (problematic) sensor and the CAN Module on an UNO. And who ever told you CAN Bus were expensive - these modules are sold as cheap as 1.27 USD! (!!!)

RS485 is as bus, which can be used very similar with a serial connection.

i am compartmentalizing my tasks between many microcontrollers and i need to use many interrupt pins that have a high chance of being called at the exact same time which can mess up my data and the entire process! it is definitely more complicated but it is the best way of doing what i want!
i have searched for CAN bus on the Sparkfun and i found modules for $20 which is just insane when you want to implement it for that many micros. can you please tell me where you found it fo $1.27?

sarah20:
i am compartmentalizing my tasks between many microcontrollers and i need to use many interrupt pins that have a high chance of being called at the exact same time which can mess up my data and the entire process! it is definitely more complicated but it is the best way of doing what i want!
i have searched for CAN bus on the Sparkfun and i found modules for $20 which is just insane when you want to implement it for that many micros. can you please tell me where you found it fo $1.27?

I suggest you NOT to use CAN Bus. These are very expensive and also ordering these controllers is very risky in this pandemic. Use SPI, it would save money.

If you are not prepared to try I2C what about RS485? I don't think the modules are very expensive.

...R

I have searched for CAN bus on the Sparkfun and i found modules for $20 which is just insane when you want to implement it for that many micros. can you please tell me where you found it fo $1.27

these "old style MCP2515 CAN modules" can be found literally everywhere. This is just a simple search on Aliexpress: http://s.click.aliexpress.com/e/_dS0lB7Y.

Nowadays you can go even cheaper if you go for a newer microcontroller with integrated can-bus controller (e.g. an ESP32) and add an external CAN-Bus transmitter.

RS485 modules are dirt cheap. I picked up 5 of them for 6GBP on a well known auction site.

noiasca:
these "old style MCP2515 CAN modules" can be found literally everywhere. This is just a simple search on Aliexpress: http://s.click.aliexpress.com/e/_dS0lB7Y.

Nowadays you can go even cheaper if you go for a newer microcontroller with integrated can-bus controller (e.g. an ESP32) and add an external CAN-Bus transmitter.

i feel like CAN bus is the best option for me thank you. i will look for microcontroller substitutes now that have CAN BUS implemented in them, thanks!