connect two arduinos?
- This topic has 11 replies, 2 voices, and was last updated 6 years, 4 months ago by mfaerber1.
-
AuthorPosts
-
October 20, 2016 at 3:11 PM #1083mfaerber1Participant
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!
October 21, 2016 at 1:07 AM #1085soundanalogousMemberSee 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.
October 22, 2016 at 12:11 PM #1086mfaerber1ParticipantI 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;” ?
October 22, 2016 at 12:23 PM #1087mfaerber1ParticipantAnd 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 = speedAnd I’d like to have the html page tell the arduino what “x” is.
Thanks again!
October 22, 2016 at 12:37 PM #1088soundanalogousMemberIncluding 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.
October 22, 2016 at 12:41 PM #1089mfaerber1ParticipantI’m on it, thank you.
October 22, 2016 at 12:43 PM #1090soundanalogousMemberI 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.
October 28, 2016 at 1:31 AM #1091mfaerber1ParticipantThank 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.
October 28, 2016 at 2:33 AM #1092soundanalogousMemberI’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.
October 28, 2016 at 5:35 PM #1093mfaerber1ParticipantNot 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.
October 29, 2016 at 1:03 AM #1095soundanalogousMemberIn 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.
November 1, 2016 at 4:40 PM #1096mfaerber1ParticipantThank 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);”
-
AuthorPosts
- The forum ‘Forum’ is closed to new topics and replies.