![Dragino PAB2 Скачать руководство пользователя страница 21](http://html1.mh-extra.com/html/dragino/pab2/pab2_user-manual_2527139021.webp)
4.3
Example 3: Log Data to USB flash
Introduction:
This example shows how to log data to a USB flash. The sketch used in this example is same as
http://wiki.dragino.com/index.php?title=Arduino_Yun_examples#Log_sensor_data_to_USB_flas
The Yun Shield will auto mount the USB flash to directory /mnt/sda1. And the sketch will append
the sensor data to the file /mnt/sda1/data/datalog.csv. So
make sure
there is such file in the USB
flash before running the sketch
Code:
#include <FileIO.h>
//FileIO class allow user to operate Linux file system
#include <Console.h>
//Console class provide the interactive between IDE and Yun Shield
void setup() {
// Initialize the Console
Bridge.begin();
Console.begin();
FileSystem.begin();
while(!Console);
// wait for Serial port to connect.
Console.println("Filesystem datalogger\n");
}
void loop () {
// make a string that start with a timestamp for assembling the data to log:
String dataString;
data= getTimeStamp();
data= " , ";
// read three sensors and append to the string:
for (int analogPin = 0; analogPin < 3; an+) {
int sensor = analogRead(analogPin);
data= String(sensor);
if (analogPin < 2) {
data= ",";
// separate the values with a comma
}
}
// open the file. note that only one file can be open at a time,
// so you have to close this one before opening another.
// The USB flash card is mounted at "/mnt/sda1" by default
File dataFile = FileSystem.open("/mnt/sda1/data/datalog.csv", FILE_APPEND);
// if the file is available, write to it:
if (dataFile) {
dataFile.println(dataString);
dataFile.close();
// print to the serial port too:
Console.println(dataString);
}
// if the file isn't open, pop up an error:
else {
w w w . e k t
2
. c o m
Electronics
Katrangi
Trading
Содержание PAB2
Страница 1: ...Yun Shield User Manual VERSION 1 1 w w w e k t 2 c o m Electronics Katrangi Trading...
Страница 20: ...Screen Shot Xively Dashboard w w w e k t 2 c o m Electronics Katrangi Trading...
Страница 28: ...Yun Shield Quick Start Guide VERSION 1 0 w w w e k t 2 c o m Electronics Katrangi Trading...
Страница 39: ...Screen Shot Xively Dashboard w w w e k t 2 c o m Electronics Katrangi Trading...