Multiple Arduinos vs 1 Ardunio Mega

Hi!

I'm working a project, kind of a line follower car on steroids. I need to following things:
Communication: RFM95W (SPI + 2 pins)
Sensors: 3 infra sensors (3 pins), 5 ultrasound sensors (10 pins)
Movement: 2 digital potentiometers (SPI + 2 pins), two brake switches (2 pins), a speed sensor (1 pin), 2 direction selector cables (2 pins).
Others: 4 simple buttons (4 pins), 2 programmable LED strips (2 pins)

This means at least 26 pins, so I would need a Mega for all of these to work. But I got the idea of using multiple smaller Arduinos, one for each job to handle. One for communication, one for the sensors, and the master Arduino for driving the motors, handling the buttons and LED strips. These Arduinos would communicate through I2C.

There are chances that later I will want to replace the master Arduino with a Raspberry Pi, for computer vision purposes. Using separate Arduinos would make this much easier, since the Raspberry has fewer pins than needed, and they are on 3.3V tolerant, and I could just connect it to system with I2C.

I'm not really sure which one is the better solution, so I would like to get your opinions on the subject.

  • 1 Microcontroller - 1 problem --> the sketch
  • 2 Microcontroller - 2 problems --> the sketch and the communication
  • 3 Microcontroller - 3 problems --> the sketch, the communication to the second controller, the communication to the third controller.
  • 4 Microcontroller - ... make a guess ...

You might also want to consider the processing required and what your reaction time needs to be. A mega might be a bit slow depending on the calculations required.

If all you need is more digital GPIO pins, port expanders like the MCP23008 (I2C 8bit), MCP23S08 (SPI 8 bit), MCP23017 (I2C 16bit), MCP23S17 (SPI 16bit) or shift regisgters like the CD74595 (SPI 8bit) would be easier, I think, than programming multiple processors and also more portable if switching to Pi.

Mega may be called for if several serial ports are required. Mega has 4 in total.

Consider several Arduino's as they would be great with the I/O and preprocessing. Use the Pi for the main computer but I would not consider using it for direct control as the OS (Operating System) will cause unexpected delays because of interrupts. Do communications with CAN module such as the MCP2515, this can run at one meg baud. It has internal filters and buffers that will cut the processor overheat. I know it is another system to learn but if you check Cory Fowler wrote a great library that should work for you first time. You will need two as when a message is sent it must be acknowledged by another node. It is a very robust system used in cars for that reason.

1 Like

n! :slight_smile:

I know that managing multiple sketches can be a hassle, but on the other hand if I have to modify the sensors, sketch for example, the communication sketch won't be touched which makes debugging easier in my opinion.
I also used I2C between two Arduinos in a previous project, and it was quite easy and reliable. Is it much more difficult to make three of them work together?

imho this is a question about how you structure the code. If each component gets its own functions you will get clean code. You even can use separate tabs in the IDE to make the code even better readable for the eyes. I just don't see the need to split the code into several sketches and add a communication protocol just to make the code leaner.

The problem is that I don't know whether I only need more GPIO pins, or separate processors. The aim of my question was to find out if it's better to use separate processors for different "jobs", or use just one Arduino (with or without port expanders) to handle everything.
I know it depends on a lot of factors, but I'd like a get a general idea.

Either you use FreeRTOS or you design you own µKernel to operate different tasks in the sketch.

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