This tutorial refers to a product that has reached its end-of-life status.

Arduino Yún Yún Serial Terminal

Access the Linux Terminal through the serial monitor.

This example allows you to use the Yún's 32U4 processor or the microcontroller of the board attached to the shield as a serial terminal for the Linux processor.

Upload this to a Yún device via USB (not over WiFi) then open the serial monitor at 115200bps to see the boot process of the Linux processor. You can also use the serial monitor as a basic command line interface for Linux using this sketch.

From the serial monitor the following commands can be issued:

  • '~' followed by '0' -> Set the UART speed to 57600 baud

  • '~' followed by '1' -> Set the UART speed to 115200 baud

  • '~' followed by '2' -> Set the UART speed to 250000 baud

  • '~' followed by '3' -> Set the UART speed to 500000 baud

  • '~' followed by '~' -> Sends the bridge's shutdown command to obtain the console.

Hardware Required

  • Yún board or shield

Circuit

There is no circuit for this example.

The circuit for this tutorial.
The circuit for this tutorial.

image developed using Fritzing. For more circuit examples, see the Fritzing project page

Code

Create a variable to hold the baud rate at which the processors will communicate and a variable to determine if entering command mode or not.

1long linuxBaud = 250000;
2boolean commandMode = false;

Open the serial connection to the computer and Linux in

setup()

1void setup() {
2
3 Serial.begin(115200);
4
5 Serial1.begin(linuxBaud);
6}

In the

loop()
copy data from one serial connection to the other. If the "~" character is passed, enter command mode.

1void loop() {
2
3 // copy from virtual serial line to uart and vice versa
4
5 if (Serial.available()) { // got anything from USB-Serial?
6
7 char c = (char)Serial.read(); // read from USB-serial
8
9 if (commandMode == false) { // if we aren't in command mode...
10
11 if (c == '~') { // Tilde '~' key pressed?
12
13 commandMode = true; // enter in command mode
14
15 } else {
16
17 Serial1.write(c); // otherwise write char to Linux
18
19 }
20
21 } else { // if we are in command mode...
22
23 if (c == '0') { // '0' key pressed?
24
25 Serial1.begin(57600); // set speed to 57600
26
27 Serial.println("Speed set to 57600");
28
29 } else if (c == '1') { // '1' key pressed?
30
31 Serial1.begin(115200); // set speed to 115200
32
33 Serial.println("Speed set to 115200");
34
35 } else if (c == '2') { // '2' key pressed?
36
37 Serial1.begin(250000); // set speed to 250000
38
39 Serial.println("Speed set to 250000");
40
41 } else if (c == '3') { // '3' key pressed?
42
43 Serial1.begin(500000); // set speed to 500000
44
45 Serial.println("Speed set to 500000");
46
47 } else if (c == '~') {
48
49 Serial1.write((uint8_t *)"\xff\0\0\x05XXXXX\x0d\xaf", 11);
50
51 Serial.println("Sending bridge's shutdown command");
52
53 } else { // any other key pressed?
54
55 Serial1.write('~'); // write '~' to Linux
56
57 Serial1.write(c); // write char to Linux
58
59 }
60
61 commandMode = false; // in all cases exit from command mode
62
63 }
64
65 }
66
67 if (Serial1.available()) { // got anything from Linux?
68
69 char c = (char)Serial1.read(); // read from Linux
70
71 Serial.write(c); // write to USB-serial
72
73 }
74}

Below is the complete code:

Last revision 2016/05/25 by SM

Suggest changes

The content on docs.arduino.cc is facilitated through a public GitHub repository. If you see anything wrong, you can edit this page here.

License

The Arduino documentation is licensed under the Creative Commons Attribution-Share Alike 4.0 license.