1
0
mirror of https://github.com/arduino/Arduino.git synced 2025-02-26 20:54:22 +01:00

Updated some Bridge examples

This commit is contained in:
Cristian Maglie 2013-06-05 14:51:15 +02:00
parent 4c0f864f90
commit fca5f46165
3 changed files with 79 additions and 22 deletions

View File

@ -1,25 +1,61 @@
/*
Running process using Process class.
This sketch demonstrate how to run linux processes
using an Arduino Yún.
created 5 Jun 2013
by Cristian Maglie
*/
#include <Process.h> #include <Process.h>
void setup() { void setup() {
pinMode(13,OUTPUT); // Setup Bridge (needed every time we communicate with the Arduino Yún)
digitalWrite(13,LOW);
Serial.begin(9600);
Bridge.begin(); Bridge.begin();
// Setup Console
Console.begin();
Console.buffer(64);
// Wait until a Network Monitor is connected.
while (!Console);
digitalWrite(13,HIGH); // run various example processes
delay(2000); runCurl();
runCpuInfo();
}
void loop() {
// Do nothing here.
}
void runCurl() {
// Launch "curl" command and get Arduino asciilogo from the network
Process p; Process p;
p.begin("curl"); p.begin("curl");
p.addParameter("http://arduino.cc/asciilogo.txt"); p.addParameter("http://arduino.cc/asciilogo.txt");
p.run(); p.run();
// Print arduino logo over the console
while (p.available()>0) { while (p.available()>0) {
char c = p.read(); char c = p.read();
Serial.print(c); Console.print(c);
} }
Console.flush();
} }
void loop() { void runCpuInfo() {
// Launch "cat /proc/cpuinfo" command (shows info on Atheros CPU)
Process p;
p.begin("cat");
p.addParameter("/proc/cpuinfo");
p.run();
// Print command output on the Console
while (p.available()>0) {
char c = p.read();
Console.print(c);
}
Console.flush();
} }

View File

@ -38,7 +38,7 @@ void setup() {
while(!Console); // wait for Network Console to open while(!Console); // wait for Network Console to open
Console.println("Xively client"); Console.println("Xively client");
// Do a first update immediatly // Do a first update immediately
updateData(); updateData();
sendData(); sendData();
lastRequest = millis(); lastRequest = millis();
@ -80,7 +80,7 @@ void sendData() {
// Send the HTTP PUT request // Send the HTTP PUT request
// Is better to declare the Process here, so when the // Is better to declare the Process here, so when the
// sendData function finishes the resources are immediatly // sendData function finishes the resources are immediately
// released. Declaring it global works too, BTW. // released. Declaring it global works too, BTW.
Process xively; Process xively;
Console.print("\n\nSending data... "); Console.print("\n\nSending data... ");

View File

@ -1,9 +1,8 @@
/* /*
Arduino Yun USB-to-Serial Arduino Yun USB-to-Serial
Allows you to use the Yun's 32U4 processor as a Allows you to use the Yun's 32U4 processor as a
serial terminal for the linino processor serial terminal for the linino processor.
Upload this to an Arduino Yun via serial (not WiFi) Upload this to an Arduino Yun via serial (not WiFi)
then open the serial monitor at 115200 to see the boot process then open the serial monitor at 115200 to see the boot process
@ -11,28 +10,31 @@
as a basic command line interface for the linino processor using as a basic command line interface for the linino processor using
this sketch. 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
The circuit: The circuit:
* Arduino Yun * Arduino Yun
created March 2013 created March 2013
by Massimo Banzi by Massimo Banzi
modified by Cristian Maglie
This example code is in the public domain. This example code is in the public domain.
*/ */
long baud = 115200; long lininoBaud = 57600;
// Pin 13 has an LED connected on most Arduino boards. // Pin 13 has an LED connected on most Arduino boards.
// give it a name:
int led = 13; int led = 13;
int ledState = HIGH; // whether the LED is high or low int ledState = HIGH; // whether the LED is high or low
void setup() { void setup() {
Serial.begin(baud); // open serial connection to Linino Serial.begin(115200); // open serial connection via USB-Serial
Serial1.begin(baud); // open serial connection via USB-Serial Serial1.begin(lininoBaud); // open serial connection to Linino
Serial.println("Prova"); // Hello USB
Serial1.println("Prova1"); // Hello Linino
// initialize the digital pin as an output. // initialize the digital pin as an output.
pinMode(led, OUTPUT); pinMode(led, OUTPUT);
@ -40,12 +42,31 @@ void setup() {
} }
void loop() { boolean commandMode = false;
void loop() {
// copy from virtual serial line to uart and vice versa // copy from virtual serial line to uart and vice versa
if (Serial.available()) { // got anything from USB-Serial? if (Serial.available()) { // got anything from USB-Serial?
char c = (char)Serial.read(); // read from USB-serial char c = (char)Serial.read(); // read from USB-serial
Serial1.write(c); // write to Linino if (commandMode == false) { // if we aren't in command mode...
if (c == '~') { // Tilde '~' key pressed?
commandMode = true; // enter in command mode
} else {
Serial1.write(c); // otherwise write char to Linino
}
} else { // if we are in command mode...
if (c == '0') { // '0' key pressed?
Serial1.begin(57600); // set speed to 57600
Serial.println("Speed set to 57600");
} else if (c == '1') { // '1' key pressed?
Serial1.begin(115200); // set speed to 115200
Serial.println("Speed set to 115200");
} else { // any other key pressed?
Serial1.write('~'); // write '~' to Linino
Serial1.write(c); // write char to Linino
}
commandMode = false; // in all cases exit from command mode
}
ledState=!ledState; // invert LED state ledState=!ledState; // invert LED state
digitalWrite(led, ledState); // toggle the LED digitalWrite(led, ledState); // toggle the LED
} }