用arduino编写txt

时间:2016-10-19 03:35:07

标签: arduino

所以,我一直在使用带Arduino的DHT11传感器。我必须在txt上写下温度和湿度数据,到目前为止我发现的最好的软件是Coolterm。不幸的是,输出是ASC fils,而不是txt。软件上的所有读数都与串行监视器相同。我应该怎么做呢?

2 个答案:

答案 0 :(得分:0)

This是arduino.cc人员制作数据记录器的一个很好的教程。它可能对您有用。

如果您想直接访问计算机,请尝试执行in Python。查看instrumentduino,firmata等。

答案 1 :(得分:0)

您可以直接在sc卡上创建.txt文件,直接在代码中执行此操作。

正如我们在Arduino - Files中所做的那样,你可以使用:

/*
  SD card basic file example

 This example shows how to create and destroy an SD card file
 The circuit:
 * SD card attached to SPI bus as follows:
 ** MOSI - pin 11
 ** MISO - pin 12
 ** CLK - pin 13
 ** CS - pin 4 (for MKRZero SD: SDCARD_SS_PIN)

 created   Nov 2010
 by David A. Mellis
 modified 9 Apr 2012
 by Tom Igoe

 This example code is in the public domain.

 */
#include <SPI.h>
#include <SD.h>

File myFile;

void setup() {
  // Open serial communications and wait for port to open:
  Serial.begin(9600);
  while (!Serial) {
    ; // wait for serial port to connect. Needed for native USB port only
  }


  Serial.print("Initializing SD card...");

  if (!SD.begin(4)) {
    Serial.println("initialization failed!");
    while (1);
  }
  Serial.println("initialization done.");

  if (SD.exists("example.txt")) {
    Serial.println("example.txt exists.");
  } else {
    Serial.println("example.txt doesn't exist.");
  }

  // open a new file and immediately close it:
  Serial.println("Creating example.txt...");
  myFile = SD.open("example.txt", FILE_WRITE);
  myFile.close();

  // Check to see if the file exists:
  if (SD.exists("example.txt")) {
    Serial.println("example.txt exists.");
  } else {
    Serial.println("example.txt doesn't exist.");
  }

  // delete the file:
  Serial.println("Removing example.txt...");
  SD.remove("example.txt");

  if (SD.exists("example.txt")) {
    Serial.println("example.txt exists.");
  } else {
    Serial.println("example.txt doesn't exist.");
  }
}

void loop() {
  // nothing happens after setup finishes.
}

请务必查看文档。