Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/logging/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/arduino/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Logging 从一开始: readIndex=0; } //计算平均值: 平均值=总读数/总读数; 延迟(6000); } 否则如果(毫秒()==60000*(++i)) { logfile.print(“,”); 日志文件打印(平均); 串行打印(“超声波读取=”);_Logging_Arduino_Arduino Uno - Fatal编程技术网

Logging 从一开始: readIndex=0; } //计算平均值: 平均值=总读数/总读数; 延迟(6000); } 否则如果(毫秒()==60000*(++i)) { logfile.print(“,”); 日志文件打印(平均); 串行打印(“超声波读取=”);

Logging 从一开始: readIndex=0; } //计算平均值: 平均值=总读数/总读数; 延迟(6000); } 否则如果(毫秒()==60000*(++i)) { logfile.print(“,”); 日志文件打印(平均); 串行打印(“超声波读取=”);,logging,arduino,arduino-uno,Logging,Arduino,Arduino Uno,从一开始: readIndex=0; } //计算平均值: 平均值=总读数/总读数; 延迟(6000); } 否则如果(毫秒()==60000*(++i)) { logfile.print(“,”); 日志文件打印(平均); 串行打印(“超声波读取=”); 序列号:println(平均值); //连续打印(“时间:”); //时间=毫秒(); //打印程序启动后的时间 //Serial.println(时间); //请稍等片刻,以免发送大量数据 //现在我们将数据写入磁盘!不要太频繁地同步-需要

从一开始: readIndex=0; } //计算平均值: 平均值=总读数/总读数; 延迟(6000); } 否则如果(毫秒()==60000*(++i)) { logfile.print(“,”); 日志文件打印(平均); 串行打印(“超声波读取=”); 序列号:println(平均值); //连续打印(“时间:”); //时间=毫秒(); //打印程序启动后的时间 //Serial.println(时间); //请稍等片刻,以免发送大量数据 //现在我们将数据写入磁盘!不要太频繁地同步-需要2048字节的I/O到SD卡 //这需要大量的能量和时间 if((millis()-syncTime)你可以考虑迁移这个问题来感谢你,我很感激!你能分享一下你电路的照片吗?这是导致错误的所有必要代码吗?尽量提供最少的例子。CS引脚的数量真的是10吗?当CardInfo正常运行时,您是否更改了默认设置?
if (!SD.begin(chipSelect)) {
  error("Card failed, or not present");
}
Serial.println().
 #include <SPI.h>
#include <SD.h>
#include <Wire.h>
#include "RTClib.h"
/*
The goal of this code is to collect 10 data points a minute, average them, and store them to an SD card

*/
#define LOG_INTERVAL 6000 // mills between entries (reduce to take more/faster data)
// how many milliseconds before writing the logged data permanently to disk
// set it to the LOG_INTERVAL to write each time (safest)
// set it to 10*LOG_INTERVAL to write all data every 10 datareads, you could lose up to 
// the last 10 reads if power is lost but it uses less power and is much faster!
#define SYNC_INTERVAL 1000 // mills between calls to flush() - to write data to the card
uint32_t syncTime = 0; // time of last sync()

#define ECHO_TO_SERIAL   1 // echo data to serial port
#define WAIT_TO_START    0// Wait for serial input in setup()
RTC_DS1307 RTC; // define the Real Time Clock object
// The analog pin that connect to the sensor
const int ultrasonicPin = A0;    // declare the input pin for the ultrasonic sensor
unsigned long time;
// for the data logging shield, we use digital pin 10 for the SD cs line
const int chipSelect = 10;
const int numReadings = 10;    //define number of samples to keep track of
int readings[numReadings];    //the readings from the analog input
int readIndex = 0;            // the index of the current reading
int total = 0;                // the running total
int average = 0;              // the average
// the logging file
File logfile;

void error(char *str)
{
  Serial.print("error: ");
  Serial.println(str);

  // red LED indicates error
  //digitalWrite(redLEDpin, HIGH);

  while(1);
}

void setup() {
  Serial.begin(9600);
  Serial.println();
  //initialize all the readings to 0:
for(int thisReading = 0; thisReading < numReadings; thisReading++) {
  readings[thisReading] = 0;


#if WAIT_TO_START
  Serial.println("Type any character to start");
  while (!Serial.available());
#endif //WAIT_TO_START

  // initialize the SD card
  Serial.print("Initializing SD card...");
  // make sure that the default chip select pin is set to
  // output, even if you don't use it:
  pinMode(10, OUTPUT);

  // see if the card is present and can be initialized:
  if (!SD.begin(chipSelect)) {
    error("Card failed, or not present");
  }
  Serial.println("card initialized.");

  // create a new file
  char filename[] = "LOGGER00.CSV";
  for (uint8_t i = 0; i < 100; i++) {
    filename[6] = i/10 + '0';
    filename[7] = i%10 + '0';
    if (! SD.exists(filename)) {
      // only open a new file if it doesn't exist
      logfile = SD.open(filename, FILE_WRITE); 
      break;  // leave the loop!
    }
  }

  if (! logfile) {
    error("couldnt create file");
  }

  Serial.print("Logging to: ");
  Serial.println(filename);

  // connect to RTC
  Wire.begin();  
  if (!RTC.begin()) {
    logfile.println("RTC failed");
#if ECHO_TO_SERIAL
    Serial.println("RTC failed");
#endif  //ECHO_TO_SERIAL
  }


  logfile.println("millis,stamp,datetime,light,temp,vcc");    
#if ECHO_TO_SERIAL
  Serial.println("millis,stamp,datetime,light,temp,vcc");
#endif //ECHO_TO_SERIAL

  // If you want to set the aref to something other than 5v
  analogReference(EXTERNAL);
}
}


void loop() {
   DateTime now;

  // delay for the amount of time we want between readings
 delay((LOG_INTERVAL -1) - (millis() % LOG_INTERVAL));

  // log milliseconds since starting
  uint32_t m = millis();
  logfile.print(m);           // milliseconds since start
  logfile.print(", ");    
#if ECHO_TO_SERIAL
  Serial.print(m);         // milliseconds since start
  Serial.print(", ");  
#endif

  // fetch the time
  now = RTC.now();
  // log time
  logfile.print(now.unixtime()); // seconds since 1/1/1970
  logfile.print(", ");
  logfile.print('"');
  logfile.print(now.year(), DEC);
  logfile.print("/");
  logfile.print(now.month(), DEC);
  logfile.print("/");
  logfile.print(now.day(), DEC);
  logfile.print(" ");
  logfile.print(now.hour(), DEC);
  logfile.print(":");
  logfile.print(now.minute(), DEC);
  logfile.print(":");
  logfile.print(now.second(), DEC);
  logfile.print('"');
#if ECHO_TO_SERIAL
  Serial.print(now.unixtime()); // seconds since 1/1/1970
  Serial.print(", ");
  Serial.print('"');
  Serial.print(now.year(), DEC);
  Serial.print("/");
  Serial.print(now.month(), DEC);
  Serial.print("/");
  Serial.print(now.day(), DEC);
  Serial.print(" ");
  Serial.print(now.hour(), DEC);
  Serial.print(":");
  Serial.print(now.minute(), DEC);
  Serial.print(":");
  Serial.print(now.second(), DEC);
  Serial.print('"');
#endif //ECHO_TO_SERIAL
  analogRead(ultrasonicPin);
  delay(10);
  int value = analogRead(ultrasonicPin);
 for (int i=0; i < 50; i++){
 if (millis() < 60000*(++i))
{
  // subtract the last reading:
  total = total - readings[readIndex];
  //read from the sensor:
  readings[readIndex] = analogRead(ultrasonicPin);
  // add the reading to the total:
  total = total + readings[readIndex];
  //advance to the next position in the array:
  readIndex = readIndex + 1;

  //if we're at the end of the array
  if (readIndex >= numReadings) {
    //wrap around to the beginning:
    readIndex = 0;
   }
   //calculate the average:
   average = total / numReadings;
   delay(6000);
}

else if (millis() == 60000*(++i))
{
  logfile.print(",");
  logfile.print(average);

  Serial.print("Ultrasonic Reading = ");
  Serial.println(average);
  //Serial.print("Time: ");
  //time = millis();
  //prints time since program started
  //Serial.println(time);
  //wait a second so as not to send massive amounts of data
// Now we write data to disk! Don't sync too often - requires 2048 bytes of I/O to SD card
  // which uses a bunch of power and takes time
  if ((millis() - syncTime) < SYNC_INTERVAL) return;
  syncTime = millis();
  delay(100);  

}
 }
}
  // this reads in cm