Go Down

Topic: Communication Between Arduino Megas (Read 658 times) previous topic - next topic

robertwlyle

Hey guys,

So I have a potentiometer connected to arduino number 1, and it saves a value to a variable called "val1". So, how do I transmit "val1" to a second arduino? I would imagine I use the SDA/SCL pins and the wire library, but can someone help me with the script for it?

This is what I have so far:


#include <Wire.h>

void setup

Wire.begin();

void loop

Wire.write(val1)




Also, how do I get the slave arduino to use this information and control a knob style servomotor, as I move the potentiometer on one arduino how would I use this info on the second arduino?

manor_royal

If this was a Civil Engineering forum would there be posts like "I need to build a bridge. Someone send me drawings."

sterretje

#2
Jan 18, 2017, 02:21 pm Last Edit: Jan 18, 2017, 02:21 pm by sterretje
master writer / slave receiver

And here is basically everything you need: wire reference; it's also where the above link comes from.

On a Mega, you can also use one of the additional serial ports; might be slightly easier ;)
If you understand an example, use it.
If you don't understand an example, don't use it.

Electronics engineer by trade, software engineer by profession. Trying to get back into electronics after 15 years absence.

manor_royal

#3
Jan 18, 2017, 03:49 pm Last Edit: Jan 19, 2017, 04:39 am by manor_royal
After I responded to this post, I decided to do such an exercise. I did it the other way, using Master Reader / Slave Sender though. So in my case, I simply modified the sample Master Reader sketch to ask for 1 byte, and then modded Slave Sender to send only 1 byte, which happened to be the value of the pot, map()'d down to 255. Easy as pie.

(Just for kicks I further modded the slave to map only as high as 180 then used that value back at the master to position a servo. So I have an 12c version of Servo Knob I guess, with the servo and the pot on different Arduinoes.)

If this was a Civil Engineering forum would there be posts like "I need to build a bridge. Someone send me drawings."

Go Up