connect two arduinos?

About Forums Forum connect two arduinos?

This topic contains 11 replies, has 2 voices, and was last updated by  mfaerber1 3 years ago.

Viewing 12 posts - 1 through 12 (of 12 total)
  • Author
    Posts
  • #1083

    mfaerber1
    Participant

    Hello and thank you so much for this. Two questions.

    Can I have an html page both listen to a local arduino and then send commands to a remote arduino? Also, would it be possible for the local arduino/computer to send a specific command to the remote arduino that the remote arduino will then execute? I have some fancy servos that require fancy libraries, so it would easiest if I could send a string or something that looks like ” FancyServo.move(3,400); ” from the html page to the remote arduino. I hope that makes sense.

    Any guidance or examples would be much appreciated. Thank you!

    #1085

    See this example: https://github.com/soundanalogous/breakout-experiments/blob/master/multi_client/multi_client.html

    You would do something like this, but one connection would be local and the other would have a remote IP address. You may need to setup port forwarding on the remote computer to get it to work.

    #1086

    mfaerber1
    Participant

    I got the arduinos talking to each other now, thank you for the quick response!

    Now what about passing some arduino code from the html page straight to the arduino, something like “x = 12;” ?

    #1087

    mfaerber1
    Participant

    And just to be clear, I have included my special library, not found in Firmata, in the Arduino sketch that I’ve uploaded to the board.

    So some of the code on the board looks like this:

    FancyServo.move(x,400);// x = angle, 400 = speed

    And I’d like to have the html page tell the arduino what “x” is.

    Thanks again!

    #1088

    Including the library you found is not going to work simply by including it in the sketch. You need to write a wrapper so that Firmata understands how to communicate with that library. This is not so easy. You can find examples in the custom_examples directory: https://github.com/soundanalogous/Breakout/tree/master/custom_examples. Basically look at how the RFID library wrapper works in those examples. You’d have to do something similar to get the Servo library to work.

    Likewise, you can’t pass arbitrary assignments such as “x = 12” through Firmata since Firmata doesn’t know what to do with the value. You need to extend StandardFirmata to understand such things, much like in the custom examples I linked to above.

    #1089

    mfaerber1
    Participant

    I’m on it, thank you.

    #1090

    I also recommend looking into using Johnny-Five instead of Breakout because Johnny-Five has a nice Servo animation library that is probably exactly what you need. Johnny-Five is also built in NodeJS so the networking capabilities are pretty much unlimited. You may not find Johnny-Five specific networking examples, but you can look up NodeJS networking examples, of which there are thousands.

    #1091

    mfaerber1
    Participant

    Thank you again!

    I may have come up with a funky workaround so that I can use my library. However, I need to communicate with the breakoutjs server using different arduino pins. I have a USB2Serial adapter to make this possible but I’m having trouble figuring out where in the code I can change the RX/TX pins from 0 and 1 to, say, 9 and 8.

    I expected to be able to change the arduino code from this:

    SerialFirmata serial;

    To this:

    SerialFirmata serial(9,8);

    But no such luck.

    #1092

    I’m not sure what you are attempting. SerialFirmata is used to control serial peripheral devices attached to an Arduino board. You would not need to modify that code. If your idea is to create a simple serial control protocol to communicate with another board the servos are attached to and is running the Servo library, then you can use SerialFirmata to accomplish this. See these two examples: https://github.com/soundanalogous/Breakout/tree/master/examples/serial. You can use this to read and write commands over a serial connection to another Arduino.

    #1093

    mfaerber1
    Participant

    Not quite, I want to communicate with just one Arduino using only the RX/TX lines on my separate (USB2Serial adapter). I want to leave pins 0 and 1 free for other things.

    #1095

    In StandardFirmata or StandardFirmataPlus, change these lines:

    Firmata.begin(57600);
    while (!Serial) {
      ; // wait for serial port to connect. Needed for ATmega32u4-based boards and Arduino 101
    }

    to:

    Serial1.begin(57600);
    Firmata.begin(Serial1);

    And connect to the TX1 and RX1 pins on your board. You need to use an Arduino board what has these pins. An Uno doesn’t for example but a Leonardo, Due or Mega does. Due and Mega also have TX2 & RX2 which you’d use Serial2 instead of Serial1. TX3 & RX3 use Serial3, etc.

    #1096

    mfaerber1
    Participant

    Thank you again!

    I have a Due but it does not work with my servos (dynamixels), or at least I and many others have had a lot of trouble making it work without additional hardware.

    That aside, I’ve come up with a pretty lame solution that works very well and allows for the use of any library with your code:

    In short, use two Arduinos. On the html page I used the PWM code to send a pulse to Arduino #1 at, say, pin ~11. Then I connected pin 11 to a simple PWM to analog voltage circuit and connected that to an analog pin on Arduino #2. Arduino #2 reads the voltage and does whatever it wants with it; it is the board that contains all of the libraries I need.

    So a command on the html page of say, “led.value = 0.25;” goes through all of this ridiculousness and is ultimately translated to something like: “dynamixel.move(1, 400);”

Viewing 12 posts - 1 through 12 (of 12 total)

The forum ‘Forum’ is closed to new topics and replies.