Wiring Arduino Uno's together for same COM Resources?

Introduction:
So I bought a motor controller shield for an Arduino Uno that has H-Bridges for 2 motors. (Pololu Dual VNH5019 Motor Driver Shield for Arduino Pololu Dual VNH5019 Motor Driver Shield for Arduino (ash02a) ]). Works great and easy enough to code for some large motors I am working with. I would live to incorporate another motor controller, this time an adafruit motor shield that can handle 4 motors and 2 servos (Overview | Adafruit Motor Shield | Adafruit Learning System). I have used these in the past and with great success.

Question:
My question is, since I cannot use both shields stacked on top of each other, and since I have a few Uno's laying around; Is there a way that I can wire the 2 Arduino Uno's together so that I can connect to the USB port on one of them and talk to them both through the same serial program (Putty)? (or say, 2 Arduino Uno's on Com3)

Would be awesome,
Thanks,
Ec7 :%

EnigmaCypher7:
Question:
My question is, since I cannot use both shields stacked on top of each other, and since I have a few Uno's laying around; Is there a way that I can wire the 2 Arduino Uno's together so that I can connect to the USB port on one of them and talk to them both through the same serial program (Putty)? (or say, 2 Arduino Uno's on Com3)

I can't see how what you describe would work. How would your serial program differenciate between the two Unos if they are connected to the same Com? What you can do is have your two Unos talking to each other and using one of them to connect to the serial program on Com3. Program that one (the master) to forward some instructions to the other (the slave). Send your serial instructions prefaced by either M or S. The master will be programmed to act on any M instructions and to pass any S instructions to the slave, without acting on them.

Your answer is exactly what I was asking. I never meant that I would like to split the USB input from the PC, but just be able to use only one input to drive several motor shields with possibly several Arduinos. So could I have one Master and two slaves?

Is there a tutorial on the following?

Send your serial instructions prefaced by either M or S. The master will be programmed to act on any M instructions and to pass any S instructions to the slave, without acting on them.

Awesome answer if I can get this going,

Thanks :.

You can use more than one serial if you use the softwareSerial library.
If your first step is to get a master to send to a slave,
look at http://www.instructables.com/id/Test-arduino-to-arduino-serial-using-softwareSeri/#intro, Test: arduino to arduino serial using softwareSerial librar

EnigmaCypher7:
My question is, since I cannot use both shields stacked on top of each other, and since I have a few Uno's laying around; Is there a way that I can wire the 2 Arduino Uno's together so that I can connect to the USB port on one of them and talk to them both through the same serial program (Putty)? (or say, 2 Arduino Uno's on Com3)

Well, if you connect the ground, 5V and Rx lines from the first Arduino to the second Arduino them the second Arduino ought to receive everything that was received by the first Arduino. If you messaging protocol has some way to address the two Arduinos and each Arduino knows which one it is then you ought to be able to run them like this in parallel without explicitly creating a SoftwareSerial output from the first Arduino and forwarding commands over it. This approach gives you no way to get serial output from the first Arduino, though. If you want that then I think you need to establish a separate serial connection between the two Arduinos and have the first one relay messages to and from the second one.

This approach gives you no way to get serial output from the first Arduino, though.

Another approach might be to use code that also will echo back to the pc what was sent to the arduino. Then connect the arduino grounds together and the tx of the master arduino to the rx of the slave arduino.

I looked at the http://www.instructables.com/id/Test-arduino-to-arduino-serial-using-softwareSeri/#intro example. I see that the code is being generated on the Master Arduino and then sent to the Slave Arduino. I have seen similar examples where one Arduino can sent to another back and fourth as in one being used as a remote. So I wonder how I could put a motor different motor controller on 2 different Arduino Uno's and have one pick up commands for the "Master" and one for the "Slave" when being communicated through the USB serial interface on the "Master".

I really liked the Prefix (M,S) idea where you could prefix a command and that prefix could be picked up by the correct controller.

Is this possible and can anybody show me a working example?

Thank you.

I2C

I have been scouring the internet on this topic and came across;

This:

&
This:
http://digitalcave.ca/resources/avr/arduino-i2c.jsp

So I will give I2C a shot tonight. I especially love the idea of a Multi-master / Multi-Slave configuration (found in the 2nd link).
Hopefully I can finagle the code to do what I need.

I really liked the Prefix (M,S) idea where you could prefix a command and that prefix could be picked up by the correct controller. Is this possible and can anybody show me a working example?

The below code might be of interest. In particular, the command sent to this arduino is echoed back to the serial monitor, and other connected arduinos if desired. Also the desired servo to receive the command is designated by a letter contained in the command, which could be on any connected arduino.

//zoomkat 11-22-12 simple delimited ',' string parse 
//from serial port input (via serial monitor)
//and print result out serial port
//multi servos added 

String readString;
#include <Servo.h> 
Servo myservoa, myservob, myservoc, myservod;  // create servo object to control a servo 

void setup() {
  Serial.begin(9600);

  //myservoa.writeMicroseconds(1500); //set initial servo position if desired

  myservoa.attach(6);  //the pin for the servoa control
  myservob.attach(7);  //the pin for the servob control
  myservoc.attach(8);  //the pin for the servoc control
  myservod.attach(9);  //the pin for the servod control 
  Serial.println("multi-servo-delimit-test-dual-input-11-22-12"); // so I can keep track of what is loaded
}

void loop() {

  //expect single strings like 700a, or 1500c, or 2000d,
  //or like 30c, or 90a, or 180d,
  //or combined like 30c,180b,70a,120d,

  if (Serial.available())  {
    char c = Serial.read();  //gets one byte from serial buffer
    if (c == ',') {
      if (readString.length() >1) {
        Serial.println(readString); //prints string to serial port out

        int n = readString.toInt();  //convert readString into a number

        // auto select appropriate value, copied from someone elses code.
        if(n >= 500)
        {
          Serial.print("writing Microseconds: ");
          Serial.println(n);
          if(readString.indexOf('a') >0) myservoa.writeMicroseconds(n);
          if(readString.indexOf('b') >0) myservob.writeMicroseconds(n);
          if(readString.indexOf('c') >0) myservoc.writeMicroseconds(n);
          if(readString.indexOf('d') >0) myservod.writeMicroseconds(n);
        }
        else
        {   
          Serial.print("writing Angle: ");
          Serial.println(n);
          if(readString.indexOf('a') >0) myservoa.write(n);
          if(readString.indexOf('b') >0) myservob.write(n);
          if(readString.indexOf('c') >0) myservoc.write(n);
          if(readString.indexOf('d') >0) myservod.write(n);
        }
         readString=""; //clears variable for new input
      }
    }  
    else {     
      readString += c; //makes the string readString
    }
  }
}

Okay, this cannot be this hard to accomplish. I have been working with various codes that I have found all over Google for the past 5 hours. :~

There has to be a way to wire 2-3 Arduino Uno's to each other and code them so they meet the following requirements:

  • USB serial connection is plugged from a PC to the 1st Arduino (Master)

  • The master will listen for a command through the USB serial such as a keyboard button press (or act as a pass-through):

if (Serial.available() > 0) {
    int inByte = Serial.read();
    switch (inByte) {

    \\ Light up a Led as a Test

    case 'q':    
      digitalWrite(2, HIGH);
          Serial.println("LED On");
      break;
    case 'w':    
      digitalWrite(2, LOW);
          Serial.println("LED Off");
      break;
  • A light on pin No.2 on another Arduino Uno (Slave 1) will light up and go off when "q" and "w" are pressed from the the previous code. (defined on (Slave 1).

  • The Serial.println("LED On"); and Serial.println("LED Off"); will be able to show up through the USB serial back on the Pc. (I use Putty)


Do the same as above for a 3rd Slave Adruino Uno but a different pin and other keyboard buttons.

This seems pretty straight forward, but I cannot make it work. I think if I can get this test to run successfully I should be knowledgeable (limited) enough to substitute the LED for my motor controllers, which I have written working code for when on one standalone Arduion Uno.

Thanks =)

EnigmaCypher7:

I'll assume that the code above is on the master.
I know it's inellegant, but this is the way I'd do it to test the idea.
Connect pins 2 on the master to pins 6 (set as input) on the slave, through a 1K resistor.
Connect pins 3 on the master to pins 7 (set as input) on the slave, through a 1K resistor.
(to avoid confusion I've used different pins, but you could use any available)
code for the slave

if (digitalRead(pin6)==HIGH){  //look to see what level master pin 2 is at
    digitalWrite(LEDpin,HIGH);  //turn on LED
    digitalWrite(pin7, HIGH);  //signal back to master pin 3 that job done.
}
else{
    digitalWrite(LEDpin,LOW);  //turn off LED
    digitalWrite(pin7, LOW);  //signal back to master pin 3 that job done.
}

For master

 switch (inByte) {
    \\ Light up a Led on slave as a Test
    case 'q':    
      digitalWrite(2, HIGH);
      delay (1); //Give time for the slave to reply
      if(digital read(3)==HIGH){  //Look at slave's pin 7 to see if job done
         Serial.println("Slave's LED On");
      }
      break;
    case 'w':    
      digitalWrite(2, LOW);
      delay (1); //Give time for the slave to reply
      if(digital read(3)==LOW){  //Look at slave's pin 7 to see if job done 
          Serial.println("Slave's LED Off");
      }
      break;

Very simple serial LED control test code. If you connect the master tx pin to the slave rx pin and connect the grounds between the two boards, then you should be able to turn both board's LEDs on/off by sending on and off from the serial monitor to the master.

// zoomkat 8-6-10 serial I/O string test
// type a string in serial monitor. then send or enter
// for IDE 0019 and later

int ledPin = 13;
String readString;

void setup() {
  Serial.begin(9600);
  pinMode(ledPin, OUTPUT); 
  Serial.println("serial on/off test 0021"); // so I can keep track
}

void loop() {

  while (Serial.available()) {
    delay(3);  
    char c = Serial.read();
    readString += c; 
  }

  if (readString.length() >0) {
    Serial.println(readString);

    if(readString.indexOf("on") >=0)
    {
      digitalWrite(ledPin, HIGH);
    }

    if(readString.indexOf("off") >=0)
    {
      digitalWrite(ledPin, LOW);
    }

    readString="";
  } 
}

I kind of got the 2 Arduinos to talk between each other with less than desirable results. I am wondering if I am going about the idea of this project all wrong? Perhaps there is a better way to keep both of these motor controllers on one Adruino Uno? This could come down to a design / wiring problem.

I have the following:

Adafruit Motor/Stepper/Servo Shield for Arduino kit - v1.2

Pin Configuration:

The following pins are in use only if the DC/Stepper noted is in use:
Digital pin 11: DC Motor #1 / Stepper #1 (activation/speed control)
Digital pin 3: DC Motor #2 / Stepper #1 (activation/speed control)
Digital pin 5: DC Motor #3 / Stepper #2 (activation/speed control)
Digital pin 6: DC Motor #4 / Stepper #2 (activation/speed control)

The following pins are in use if any DC/steppers are used
Digital pin 4, 7, 8 and 12 are used to drive the DC/Stepper motors via the 74HC595 serial-to-parallel latch

The following pins are used only if that particular servo is in use:
Digitals pin 9: Servo #1 control
Digital pin 10: Servo #2 control

Pololu Dual VNH5019 Motor Driver Shield for Arduino

Pin Configuration:

2 - [Motor 1] Direction Input (A)
4 - [Motor 1] Direction input (B)
6 - [Motor 1] Enable
7 - [Motor 2] Direction input (A)
8 - [Motor 2] Direction input (B)
9 - [Motor 1] Speed input (PWM)
10 -[Motor 2] Speed input (PWM)
12 -[Motor 2] Enable

A0 -[Motor 1] Sensor output
A1 -[Motor 2] Sensor output

(Both controllers work great on their own)

Is there a way to run both off of one Arduino Uno? I am willing to go with a bigger Arduino if necessary too, I just don't know a whole lot about these devices, their capabilities, remapping pins and things of that nature.

Thanks

Perhaps rather than using shields, you'd be better of using motor driver boards. These would need to be connected by wires, which is less convenient but gives you total control over the pin assignments.

:grin: I just found my answer; Processing.

Seems you can use processing to talk to 2 or more serial devices without having to go in and manually switch COM #'s.

 //initialize serials 
  firstArduinoPort = new Serial(this, Serial.list()[0], 38400); //port 4
  firstArduinoPort.bufferUntil(' ');
  secondArduinoPort = new Serial(this, Serial.list()[1], 9600); //port 6
  secondArduinoPort.bufferUntil(' ');
......etc

This should be the perfect intermediary for my project.

EnigmaCypher7:
Seems you can use processing to talk to 2 or more serial devices by giving them different Baud rates:

Of course you can connect multiple Arduinos to a computer at the same time and talk to them independently since they each present a separate serial port. That has nothing whatsoever to do with using different baud rates though, and if you have read something that says you need to use different baud rates either you have misunderstood it, or it is wrong.

You started off by stating that you wanted to connect multiple Arduinos to the same serial port, which is why all the discussions have centered around that.

That has nothing whatsoever to do with using different baud rates though, and if you have read something that says you need to use different baud rates either you have misunderstood it, or it is wrong.

Agreed. I thought about this after I read it, you wouldn't be able to have both resources with the same COM #, not sure what they were talking about on the other site that I was reading.

Anyways,
The reason the processing idea works and still fits these parameters is that for this project I am going to assign ACII characters to different ranges in a joystick and need to be able to have 2 different motor controllers pick it up without having to go in and manually switch the active COM device. With processing it does look like I will be able to assign part of the keyboard to one Arduino and part of the keyboard to another, both can be active on 2 different COM #'s while the program knows which to send the ACII characters.

This did get a bit off topic, but it seems my initial question was flawed in the reasoning behind what I was out to accomplish.

Thanks for the help and I will edit out the baud rate comment above in case somebody stumbles upon this, as it's obviously wrong.

The link above is still the correct example though, if anybody needs it. =)