To achieve a serial communication between two microcontrollers, we need to take care of the following:
In order to achieve serial communication between the boards, SDA and SCL pins have to be connected with each other while the GND is shared between the two boards. This is important to ensure serial communication!
With respect to the code, different codes will be used for each of the microcontrollers. One of the codes will make the first microcontroller act as a Sender of the data. So the board can be gathering data from a certain sensor and sending them to the other microcontroller using the serial terminal. On the other hand, the other board will carry the code that Recieves the data from the serial. In that case, the receiver could be using this data to control a certain output like an LED or a motor. In our case, we were simply reading these data to the serial monitor.
For the group assignment the boards of Wael and Ghassan used for the input and output week were used. The boards were connected using in our case digital pins that were set as software serial. So the test was gathering data from the ultrasonic sensor on the first board (sender), and sending this data to the other board(receiver), were we read the data from the serial monitor.
The following video represents how the distance was collected from the sender board, and sent to the receiver board, where we can see all details on the serial monitor.
Below, the Arduino codes of the sender and the receiver boards are illustrated: