How to connect 2 Arduino together?

Hi everyone,

This year, I must to realise a project with my school but there is a problem with it.
The problem is that I have to control 3 motors with 2 Arduino Mega and 2 motor shields but the motors have to react to the same sensors.
First of all, I tried to split the cables but someone said me it isn't possible.
That's why I try to find a way to connect the 2 Arduino Mega together.
I read that it is possible with the I2C but I already have a MPU6050 on the pins 20 and 21 (SDA and SCL).
So, my question is the following: Do you know a way of solving this problem, knowing that all the sensors (2 contact sensors, 2 switches, 1 MPU6050, 1 Joystick and 2 ultrasound sensors) and the first 2 motors are connected to the first Mega (master) with the first motor shield and that the 2nd Mega has to receive the informations from the first one to control the last motor with the 2nd motor shield.

Thank you very much for your answers.

It is a common beginners mistake to think you need two Arduinos when the problem is just that they do not understand software or hardware. You are swapping something simple to learn into something that is a lot more complicated but still needs learning.

So tell me why you can't just use one Arduino.

Thank you for answering me

I use 3 motors but each motor shield can only control 2 motors. That's why I bought 2 Mega and 2 shields (the 2nd shield control the 3rd motor). Do you know something to use only 1 motor shield?

Thank you

You don't have to use motor shields. There are other motor drivers that do not cover up all the Arduino pins so that you would not be limited to 2 motors.

I presume the shield you have is sized to fit an Uno so that many of the Mega pins are uncovered?

If so I suggest you look at (for example) the motor drivers that are on the Pololu website - many of them could be connected into some of the vacant Mega pins. Other suppliers have similar products.

If you really want to connect your two Megas together then the simplest way is to connect them using Serial1 on each board. Connect Rx1 to Tx1 on the other board and Tx1 to Rx1. Also make a GND connection between the boards. For receiving data have a look at the examples in Serial Input Basics - simple reliable ways to receive data. It will need a minor change to work with Serial1.

...R

So why do you not use two motor shields on one Arduino. Or even better build your own interface to drive your motors.

In one project I made I controlled 25 motors with an Arduino Uno. I used the SN754410 chips, each one can control two motors so you would only need two of those chips.

It looked like this:-

OK! So I don't need to have 2 shields.
Good to know and thank you very much.

Indeed, I bought the shields on Pololu website and these shields cover up all the Arduino pins (not all but most of them).

So I have one more question: if the pins used are currently the following:
-22 and 23 for the switches
-25 and 26 for the contact sensors
-A2 and A3 for the joystick
-43 to 46 for the ultrasound sensors
-20, 21 and 2 for the MPU
( -A0, A1, 3 (2 normally but I remapped it), 4, 6, 7, 8, 9, 10, 12 for the fisrt motor shield ) -> replaced by the new one.

do you think I will have enought pins to connect 1 shields able to control 3 motors taking into account the fact that sensors are also connected to the Mega?

Oh ok. I didn't know you could connect 2 (or more than 2) shields one 1 Arduino. Do you have to change something in the code to use the SN754410 (I suppose so)?

Do you have to change something in the code to use the SN754410

Yes, but it is just a matter of doing a few digitalWrite calls to the appropriate pins.

Get the data sheet for the SN754410, it shows you what pins do what.

these shields cover up all the Arduino pins (not all but most of them).

You don't have to fit a shield over the pins, you can just wire up the appropriate pins.

Grumpy_Mike:
It looked like this:-

Impressive! The only projects that I tried to take past the breadboard state were a plate of spaghetti. Wires everywhere.

Ok, thank you so much!

I saw it is 4,5V -36V and 1A. Our motors are powered in 12V but it's more than 1A. Is there something to fix it?
(If you need the code I can copy it here).

Actually, the first code I made used 2 L293D but I had the same problem: we needed more than 11A and 12V but it delivered only 600mA.

Our motors are powered in 12V but it's more than 1A.

What is more than 1A. A motor designed to run off 12V will take the current it is designed to work off, you can't give it more current.

we needed more than 11A and 12V

That is a big motor, what is it doing? The SN754410 will not be able to power such a big motor.

The motors are used to control a wheelchair for disabled people (the wheelchair must be able to clim stairs).
I think I found the solution: I’m going to use 3 “Pololu High-Power Motor Driver 36v15 (FDS5672)”. But I don’t know how to programme them (there is nothing written on the website).

By the way, do you know the difference between DC motor and DC brushed motor? If a shield control a DC brushed motor, do you know if it is also going to work with a DC motor?

Thank you

Burn3rII:
The motors are used to control a wheelchair for disabled people (the wheelchair must be able to clim stairs).

Unless I am mistaken the motors for a wheelchair are likely to draw 30 or 50 amps and may have a stall current of 100 amps or more. And if so a motor shield would be completely unsuitable.

...R

But I don't know how to programme them

Look at the signals you get with the motor control, wire them to the Arduino and simply set these signals high or low depending on what you want the motor to do.

(the wheelchair must be able to clim stairs).

Sounds like another over ambitious beginners project, given that you don’t even know how to turn a motor on.