diff options
Diffstat (limited to 'libraries/Bridge/examples')
5 files changed, 42 insertions, 190 deletions
diff --git a/libraries/Bridge/examples/Datalogger/Datalogger.ino b/libraries/Bridge/examples/Datalogger/Datalogger.ino index dfd269f..5878e05 100644 --- a/libraries/Bridge/examples/Datalogger/Datalogger.ino +++ b/libraries/Bridge/examples/Datalogger/Datalogger.ino @@ -2,45 +2,46 @@ SD card datalogger This example shows how to log data from three analog sensors - to an SD card mounted on the Linux using the Bridge library. + to an SD card mounted on the Arduino Yun using the Bridge library. The circuit: * analog sensors on analog ins 0, 1, and 2 * SD card attached to SD card slot of the Arduino Yun You can remove the SD card while the Linux and the - sketch are running but becareful to don't remove it while - the system is writing on it. + sketch are running but be careful not to remove it while + the system is writing to it. created 24 Nov 2010 modified 9 Apr 2012 by Tom Igoe adapted to the Yun Bridge library 20 Jun 2013 by Federico Vanzati + modified 21 Jun 2013 + by Tom Igoe This example code is in the public domain. */ #include <FileIO.h> -#include <Console.h> +#include <Serial.h> void setup() { - // Initialize the Bridge and the Console + // Initialize the Bridge and the Serial Bridge.begin(); - Console.begin(); + Serial.begin(9600); FileSystem.begin(); - while(!Console){ - ; // wait for Console port to connect. - } + while(!Serial); // wait for Serial port to connect. + Serial.println("Filesystem datalogger"); } void loop () { // make a string that start with a timestamp for assembling the data to log: String dataString = ""; - addTimeStamp(dataString); + dataString += addTimeStamp(); dataString += " = "; // read three sensors and append to the string: @@ -62,11 +63,11 @@ void loop () { dataFile.println(dataString); dataFile.close(); // print to the serial port too: - Console.println(dataString); + Serial.println(dataString); } // if the file isn't open, pop up an error: else { - Console.println("error opening datalog.txt"); + Serial.println("error opening datalog.txt"); } delay(15000); @@ -74,7 +75,8 @@ void loop () { } // This function append a time stamp to the string passed as argument -void addTimeStamp(String &string) { +String addTimeStamp() { + String result; Process time; time.begin("date"); time.addParameter("+%D-%T"); @@ -83,6 +85,6 @@ void addTimeStamp(String &string) { while(time.available()>0) { char c = time.read(); if(c != '\n') - string += c; + result += c; } } diff --git a/libraries/Bridge/examples/OLDWiFiCheck/OLDWiFiCheck.ino b/libraries/Bridge/examples/OLDWiFiCheck/OLDWiFiCheck.ino deleted file mode 100644 index 1cb9f03..0000000 --- a/libraries/Bridge/examples/OLDWiFiCheck/OLDWiFiCheck.ino +++ /dev/null @@ -1,53 +0,0 @@ -/* - Arduino Yun Wireless Config Check - - Checks the wireless state of Arduino Yun by calling - the linux command iwconfig. - - Upload this to an Arduino Yun via serial (not WiFi) - then open the serial monitor to see the status of - your Yun's WiFi connection. If it's connected to - a wireless network, the ESSID (name) of that network - and the signal strength will appear. - - The circuit: - * Arduino Yun - - created 22 May 2013 - by Tom Igoe - - This example code is in the public domain. - */ - -#include <Process.h> - -void setup() { - Serial.begin(9600); // initialize serial communication - while(!Serial); // do nothing until the serial monitor is opened - - pinMode(13,OUTPUT); - digitalWrite(13, LOW); - Bridge.begin(); // make contact with the linux processor - digitalWrite(13, HIGH); - - delay(2000); // wait 2 seconds - - Process wifiCheck; // initialize a new process - - - wifiCheck.begin("iwconfig"); // command you want to run - wifiCheck.addParameter("wlan0"); // parameter of the command - wifiCheck.run(); // run the command - - // while there's any characters coming back from the - // process, print them to the serial monitor: - while (wifiCheck.available() > 0) { - char thisChar = wifiCheck.read(); - Serial.print(thisChar); - } -} - -void loop() { - // nothing to do here. -} - diff --git a/libraries/Bridge/examples/OLDWifiSignalStrengthIndicator/OLDWifiSignalStrengthIndicator.ino b/libraries/Bridge/examples/OLDWifiSignalStrengthIndicator/OLDWifiSignalStrengthIndicator.ino deleted file mode 100644 index e0b2d1f..0000000 --- a/libraries/Bridge/examples/OLDWifiSignalStrengthIndicator/OLDWifiSignalStrengthIndicator.ino +++ /dev/null @@ -1,112 +0,0 @@ -/* - Wifi Signal Strength Indicator - - This example demonstrates the use of the bridge and process libraries - to communicate between the Arduino side and the linux side of the Arduino Yun. - - The Linux script returns the strength of the wifi signal. - - The Arduino sketch uses LEDs to indicate whether the current value of - the signal strength is above, below, or the same as the last value - - The circuit: - * LEDs on pins 8, 9, and 10 - * Built-in LED on pin 13 - - The script: - The following one line script must exist in the /root directory of the - linux file system, in a file named "wifiStrength.sh", and it must be executable: - - tail -1 /proc/net/wireless | cut -c22-23 - - created 06 June 2013 - by Michael Shiloh - modified 08 June 2013 - by Tom Igoe - - This example code is in the public domain - - */ - - -#include <Process.h> - -// global variable to store the last value of the signal strength -int lastValue; - -void setup() { - // set up LED pins as outputs: - pinMode(8, OUTPUT); - pinMode(9, OUTPUT); - pinMode(10, OUTPUT); - pinMode(13,OUTPUT); - - // Indicate that you're ready by flashing pin 13 LED twice - for (int flash = 0; flash < 3; flash++) { - digitalWrite(13,HIGH); - delay(200); - digitalWrite(13,LOW); - delay(800); - } - // initialize Serial and Bridge: - Serial.begin(9600); - Bridge.begin(); - - // Indicate that setup is finished - digitalWrite(13,HIGH); -} - -void loop() { - int value = 0; // the signal strength as an integer - String result; // the result of the process as a String - Process wifiCheck; // the process itself - - - // Run the script on the linux side. Note that any word - //or text separated by a tab or space is considered - //an additional parameter: - wifiCheck.begin("ash"); - wifiCheck.addParameter("/root/wifiStrength.sh"); - wifiCheck.run(); - - // If the process has sent any characters: - while (wifiCheck.available()>0) { - result = wifiCheck.readString(); // read the result into a string - value = result.toInt(); // parse the string as an int - } - - // for debugging - Serial.print("previous strength:"); - Serial.print(lastValue); - Serial.print("\tcurrent strength:"); - Serial.println(value); - - // indicate the relative string by lighting the appropriate LED - allOff(); // turn off all the LEDS - - if (value > lastValue) { // if the signal's getting stronger - digitalWrite(10, HIGH); - } - else if (value < lastValue){ // if the signal's getting weaker - digitalWrite(8, HIGH); - } - else { // if the signal's stayed steady - digitalWrite(9, HIGH); - } - - lastValue = value; // record this value for next time - delay(10); // small delay before next time through the loop -} - - -void allOff() { - digitalWrite(8, LOW); - digitalWrite(9, LOW); - digitalWrite(10, LOW); -} - - - - - - diff --git a/libraries/Bridge/examples/ShellCommands/ShellCommands.ino b/libraries/Bridge/examples/ShellCommands/ShellCommands.ino index 4fd7384..47579f8 100644 --- a/libraries/Bridge/examples/ShellCommands/ShellCommands.ino +++ b/libraries/Bridge/examples/ShellCommands/ShellCommands.ino @@ -1,26 +1,41 @@ -/* Demonstrate shell commands */ +/* + Running shell coommands using Process class. + + This sketch demonstrate how to run linux shell commands + using an Arduino Yún. + + The circuit: + * Arduino Yun + + created 12 Jun 2013 + by Cristian Maglie + modified 21 June 2013 + by Tom Igoe + + This example code is in the public domain. + + */ #include <Process.h> void setup() { + // initialize the Bridge and Serial connections: Bridge.begin(); - Console.begin(); - Console.buffer(64); + Serial.begin(9600); } void loop() { Process p; - // This command line prints the name of the wireless that the board is connected to or that the board has created + // This command line prints the name of the wireless network + // that the board is connected to, or the network which the board has created: p.runShellCommand(F("lua /usr/lib/lua/pretty_wifi_info.lua | grep SSID")); // Read command output while (p.available()) { char c = p.read(); - Console.print(c); - } - Console.flush(); - - delay(5000); + Serial.print(c); + } + while (true); // do nothing more } diff --git a/libraries/Bridge/examples/TimeCheck/TimeCheck.ino b/libraries/Bridge/examples/TimeCheck/TimeCheck.ino index 54fd131..2673dea 100644 --- a/libraries/Bridge/examples/TimeCheck/TimeCheck.ino +++ b/libraries/Bridge/examples/TimeCheck/TimeCheck.ino @@ -7,6 +7,7 @@ using an Arduino Yun. created 27 May 2013 + modified 21 June 2013 By Tom Igoe */ @@ -20,8 +21,7 @@ int lastSecond = -1; // need an impossible value for comparison void setup() { Serial.begin(9600); // initialize serial Bridge.begin(); // initialize Bridge - delay(2000); // wait 2 seconds - + while(!Serial); // wait for Serial Monitor to open Serial.println("Time Check"); // Title of sketch |