Advertisement
Vadorequest

YunSerialTerminal customized

Nov 15th, 2013
209
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 3.43 KB | None | 0 0
  1. /*
  2.   Arduino Yun USB-to-Serial
  3.  
  4.  Allows you to use the Yun's 32U4 processor as a
  5.  serial terminal for the linino processor.
  6.  
  7.  Upload this to an Arduino Yun via serial (not WiFi)
  8.  then open the serial monitor at 115200 to see the boot process
  9.  of the linino processor. You can also use the serial monitor
  10.  as a basic command line interface for the linino processor using
  11.  this sketch.
  12.  
  13.  From the serial monitor the following commands can be issued:
  14.  
  15.  '~' followed by '0' -> Set the UART speed to 57600 baud
  16.  '~' followed by '1' -> Set the UART speed to 115200 baud
  17.  '~' followed by '2' -> Set the UART speed to 250000 baud
  18.  '~' followed by '3' -> Set the UART speed to 500000 baud
  19.  '~' followeb by '~' -> Sends the bridge's shutdown command to
  20.                         obtain the console.
  21.                        
  22.  The circuit:
  23.  * Arduino Yun
  24.  
  25.  created March 2013
  26.  by Massimo Banzi
  27.  modified by Cristian Maglie
  28.  
  29.  This example code is in the public domain.
  30.  
  31.  http://arduino.cc/en/Tutorial/YunSerialTerminal
  32.  
  33.  */
  34.  
  35.  
  36. long lininoBaud = 250000;
  37. int led = 13;
  38. void setup() {
  39.   Serial.begin(115200);      // open serial connection via USB-Serial
  40.   Serial1.begin(lininoBaud); // open serial connection to Linino
  41.   pinMode(led, OUTPUT);  
  42. }
  43.  
  44. boolean commandMode = false;
  45.  
  46. void loop() {
  47.   digitalWrite(led, HIGH);
  48.   // copy from virtual serial line to uart and vice versa
  49.   if (Serial.available()) {     // got anything from USB-Serial?
  50.   digitalWrite(led, LOW);
  51.   delay(200);
  52.     char c = (char)Serial.read();     // read from USB-serial
  53.     if (commandMode == false) {       // if we aren't in command mode...
  54.       if (c == '~') {                 //    Tilde '~' key pressed?
  55.         commandMode = true;           //       enter in command mode
  56.       } else {
  57.         Serial1.write(c);             //    otherwise write char to Linino
  58.       }
  59.     } else {                          // if we are in command mode...
  60.       if (c == '0') {                 //     '0' key pressed?
  61.         Serial1.begin(57600);         //        set speed to 57600
  62.         Serial.println("Speed set to 57600");
  63.       } else if (c == '1') {          //     '1' key pressed?
  64.         Serial1.begin(115200);        //        set speed to 115200
  65.         Serial.println("Speed set to 115200");
  66.       } else if (c == '2') {          //     '2' key pressed?
  67.         Serial1.begin(250000);        //        set speed to 250000
  68.         Serial.println("Speed set to 250000");
  69.       } else if (c == '3') {          //     '3' key pressed?
  70.         Serial1.begin(500000);        //        set speed to 500000
  71.         Serial.println("Speed set to 500000");
  72.       } else if (c == '~') {
  73.         Serial1.write((uint8_t *)"\xff\0\0\x05XXXXX\x0d\xaf", 11);
  74.         Serial.println("Sending bridge's shutdown command");
  75.       } else {                        //     any other key pressed?
  76.         Serial1.write('~');           //        write '~' to Linino
  77.         Serial1.write(c);             //        write char to Linino
  78.       }
  79.       commandMode = false;            //     in all cases exit from command mode
  80.     }
  81.   }
  82.   if (Serial1.available()) {          // got anything from Linino?        
  83.     Serial.println("Linino available");
  84.     delay(1000);
  85.     char c = (char)Serial1.read();    // read from Linino  
  86.     Serial.write(c);                  // write to USB-serial
  87.   }else{
  88.     //Serial.println("Linino NOT available!");
  89.     //delay(1000);
  90.     }
  91. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement