Pages: [1] 2   Go Down
Author Topic: Wiring Arduino Uno's together for same COM Resources?  (Read 1637 times)
0 Members and 1 Guest are viewing this topic.
Virginia, US
Offline Offline
Jr. Member
**
Karma: 0
Posts: 76
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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  http://www.pololu.com/catalog/product/2502 ]). 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 (http://learn.adafruit.com/adafruit-motor-shield/overview). 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  smiley-draw
Logged

He who dares, Wins.

London
Offline Offline
Edison Member
*
Karma: 48
Posts: 1468
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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.
Logged

Virginia, US
Offline Offline
Jr. Member
**
Karma: 0
Posts: 76
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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?

Quote
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  smiley-small
Logged

He who dares, Wins.

Texas
Offline Offline
Edison Member
*
Karma: 25
Posts: 1298
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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
Logged

Good luck, Jack

UK
Offline Offline
Shannon Member
****
Karma: 223
Posts: 12630
-
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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.
Logged

I only provide help via the forum - please do not contact me for private consultancy.

0
Offline Offline
Tesla Member
***
Karma: 145
Posts: 9675
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
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.
Logged

Consider the daffodil. And while you're doing that, I'll be over here, looking through your stuff.   smiley-cool

Virginia, US
Offline Offline
Jr. Member
**
Karma: 0
Posts: 76
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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.
Logged

He who dares, Wins.

Virginia, US
Offline Offline
Jr. Member
**
Karma: 0
Posts: 76
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I2C

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

This:
http://arduino.cc/en/Tutorial/MasterReader
&
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.
Logged

He who dares, Wins.

0
Offline Offline
Tesla Member
***
Karma: 145
Posts: 9675
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
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.

Code:
//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
    }
  }
}

Logged

Consider the daffodil. And while you're doing that, I'll be over here, looking through your stuff.   smiley-cool

Virginia, US
Offline Offline
Jr. Member
**
Karma: 0
Posts: 76
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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.  smiley-confuse

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):
Code:
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 =)
« Last Edit: August 25, 2013, 08:29:08 pm by EnigmaCypher7 » Logged

He who dares, Wins.

London
Offline Offline
Edison Member
*
Karma: 48
Posts: 1468
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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
Code:
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
Code:
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;
Logged

0
Offline Offline
Tesla Member
***
Karma: 145
Posts: 9675
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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.

Code:
// 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="";
  }
}

Logged

Consider the daffodil. And while you're doing that, I'll be over here, looking through your stuff.   smiley-cool

Virginia, US
Offline Offline
Jr. Member
**
Karma: 0
Posts: 76
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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
http://www.adafruit.com/products/81

Pin Configuration:
Quote
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
http://www.pololu.com/catalog/product/2502

Pin Configuration:
Quote
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
« Last Edit: August 28, 2013, 11:18:27 am by EnigmaCypher7 » Logged

He who dares, Wins.

UK
Offline Offline
Shannon Member
****
Karma: 223
Posts: 12630
-
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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.
Logged

I only provide help via the forum - please do not contact me for private consultancy.

Virginia, US
Offline Offline
Jr. Member
**
Karma: 0
Posts: 76
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

 smiley-mr-green 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.

http://forum.processing.org/topic/multiple-arduinos

Code:
//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.
« Last Edit: August 29, 2013, 08:04:19 am by EnigmaCypher7 » Logged

He who dares, Wins.

Pages: [1] 2   Go Up
Jump to: