This blog explains how to set up wired serial communication between two Arduino boards.
This tutorial is meant for those with some knowledge of Arduino and IoT.
The purpose of building this blog is to write down the detailed operation history and my memo for learning the Arduino.
If you are also interested and want to get hands dirty, just follow these steps below and have fun!~
Tools will be used:
- Two Arduino boards (e.g., mines are yún and 101)
- Jump wires (Two are enough)
Prerequisites
- Boards are firmly connected via USB to computers
- Boards drivers are properly installed
- Ports are identified by the computers
- Jump wires connect one's TX with another's RX, and one's RX with another's TX
Getting Started
Code for the master board (Arduino 101):
Send integer data to slave board
void setup() {
// Begin the Serial at 9600 Baud
Serial.begin(9600);
Serial1.begin(9600);
}
int thisByte = 33;
void loop() {
Serial1.write(thisByte); //Write the serial data
if (thisByte == 126) { // you could also use if (thisByte == '~') {
//This loop loops forever and does nothing
// holds
while (true) {
continue;
}
//thisByte = 32;
}
// go on to the next character
thisByte ++;
//delay(1000);
}
Code for slave board (Arduino yún)
Receive data from the master board, and print the data to console
int incomingByte = 0;
void setup() {
// Begin the Serial at 9600 Baud
Serial1.begin(9600);
Serial.begin(9600);
}
void loop() {
// send data only when you receive data:
if (Serial1.available() > 0) {
// read the incoming byte:
incomingByte = Serial1.read();
// say what you got:
Serial.print("Received: ");
Serial.write(incomingByte);
Serial.print(" DEC: ");
Serial.print(incomingByte, DEC);
Serial.print(" HEX: ");
Serial.print(incomingByte, HEX);
Serial.print(" OCT: ");
Serial.print(incomingByte, OCT);
Serial.print(" BIN: ");
Serial.print(incomingByte, BIN);
Serial.println(" ");
}
}
Part of the Results
Trouble Shooting
References
https://docs.arduino.cc/software/ide-v1/tutorials/Linux
https://www.circuitbasics.com/how-to-set-up-uart-communication-for-arduino/
Top comments (0)