What would be the best way to connect an arduino mini to a Mega 2560? For revision2 of my number board, I'd like to remove 2 of the cat5 cables. I can do this by connecting the 16 switch contacts to the mini, and having 4 wires (2 signal and 2 for power) go between mini and mega. But should I use I2C or Serial?
I've not much experience with I2C, with serial I assume I would have the mega send a command that the mini is listening for, mini pings the pins for switch states (high/low), and sends two bytes back which the mega decodes to get switch states?
IE for 16 switches where every other one was a different state, would be ...?
Wire.begin(2);
Wire.onReceive(trigger);
void trigger(){
if (Wire.receive == "u"){
//digitalRead the 16 switches and assign binary 0 for low, 1 for high
Wire.beginTransmission(1);
for (int i=0;i<16;i++){
Wire.send(switch[i]);
}
Wire.endTransmission();
}
}
Do you know what I2C stands for? Do you know what it is primarily designed for? Chip-to-chip communication on the same circuit board. Have you ever seen a 3 meter circuit board? I haven't.
Serial would be my choice.
Of course, there are ways to make I2C work, and there are limitations with Serial, too.
If you said something about the amount of data to be transferred, we might be able to give better advice. How many bytes/second? Can you stand any data loss? Will the connecting wires be shielded? Will they be in a noisy (electrically-speaking) environment?
Cable will be Cat5E. There will be 3 serial lines- 1-way from Mega to 7 segment serial board, then 2-directional between mini and mega. Than 5V Vcc and ground.
I figure to have each serial line in a twisted pair with a ground and use 1 twisted pair for +5Vcc.
There may be some noise present (it's on a vehicle) but most of the system noise will get captured by the voltage regulators. Being Cat5, the cables won't be shielded, but they won't be parallel to any voltage sources, either. That said, some of the ignition components will be ~15 inches away from the datalines.
Serial2.begin(9600);
Serial2.print("u");
delay(50); //wait for mini to process
if (Serial2.available() > 0){
for (int i=0;i<16;i++){
switch[i] = Serial2.read();
}
}
And for Mini
Serial.begin(9600);
if (Serial.available() > 0){
received = Serial.available();
if (received == "u"){
//digitalRead the 16 switches and assign binary 0 for low, 1 for high
for (int i=0;i<16;i++){
Serial.print(switch[i]);
}
}
}
magnethead794:
What would be the best way to connect an arduino mini to a Mega 2560? For revision2 of my number board, I'd like to remove 2 of the cat5 cables. I can do this by connecting the 16 switch contacts to the mini, and having 4 wires (2 signal and 2 for power) go between mini and mega. But should I use I2C or Serial?
For longer runs, other things being the same, I would go for serial. Plus I would look into RS485 as the transceivers for that are designed to work with twisted pair cable as they are "balanced".