Here's a post which explained the communication standard.
I need to establish communication between multiple Arduino nano board. I have used SPI bus on one of the Arduino board for wireless communication and I2C bus for another device. It appeared that both I2C bus and SPI bus support multiple device. However, since I have used both I2C and SPI for different purpose, establish parallel communication with RX TX pins seemed to be the preferable choice.
Question 1: This post provided a nice set up for I2C bus as master and slave. However, can one adjust the code in step 2 of master device with
Wire.begin(n);
and change all the Arduino boards as master&slave devices, thus achieve parallel communication?
Question 2: I read this post where people mentioned RS 485. However, can one achieve parallel communication with RX and TX pin like the one used in Question 1, without using RS 485?
1 Answer 1
parallel communication is possible using arduino you need to use the ports for example port A and then a rx tx pins.
#include <Wire.h>
#include <Arduino.h>
byte i = 0;
int intpin = 44;
int rcv_ready = 45;
void setup() {
DDRA = B11111111; // Output
DDRC = B11111111; // Output
pinMode(intpin, OUTPUT);
pinMode(rcv_ready, INPUT);
}
void loop() {
transmit();
}
void transmit() {
PORTA = i++
PORTC = i;
digitalWrite(intpin, HIGH);
while (rcv_ready == LOW) {}
digitalWrite(intpin, LOW);
delay(299);
}
Here we set up the two ports DDRA and DDRC to be output ports by using the mask B11111111; We set the interrupt pin to port 44 and set it is an output and we set the receive pin to be 45 and an input. Then we call transmit in the loop. Where we then set port A and port C to equal i++ and i respectively. And then toggle the signal to say we have transmitted a new message. This will get picked up by the Slave-input.
Slave input
#include <Arduino.h>
byte x = 0;
byte y = 0;
int rcv_ready = 45;
void setup() {
DDRA = B00000000; // Input
DDRC = B00000000; // Input
Serial.begin(19200);
attachInterrupt(5, blink, RISING);
pinMode(rcv_ready, OUTPUT);
digitalWrite(rcv_ready, LOW);
}
void loop() {}
void blink() {
x = PINA;
y = PINC;
delay(100);
digitalWrite(rcv_ready, HIGH);
delay(100);
digitalWrite(rcv_ready, LOW);
Serial.print(x);
Serial.print(" , ");
Serial.println(y);
}
Here we set up the two ports DDRA and DDRC to be input ports by using the mask B00000000; We then set the baud rate as 19200 which matches the rate set by the master
Here we set the interrupt to be 5 which is pin 18 and tell it to call blink on an interrupt. We then read the values from PORTA and PORTC and then we output it to the serial monitor screen. We also send back the acknowledgement of receipt to the master using pin 45
-
1Please post your code in text format.VE7JRO– VE7JRO2020年02月13日 15:29:07 +00:00Commented Feb 13, 2020 at 15:29
parallel communication
arduino cluster
andarduino node network