arduino 必须安装Java,Arduino继续执行设置

我最近写了这个代码来做一个带有 Arduino UNO 的Arduino传感器站 . 我需要从荨麻疹中恢复一些数据,以便以后有人可以分析它们 . 基本上,程序读取传感器,然后将读数存储在SD卡中 .

我对该代码有疑问 . 我不知道,也没有找到解决方法 . 代码正常执行,但它继续像循环函数一样执行设置 . 所以串口输出“设置完成”,然后arduino似乎重启等等 .

我见过这可能是因为我的arduino没有足够的RAM . IDE表示它占67%,程序库存占70%,我也尝试将arduino插入12V电源,但它也没有用 .

谢谢你的回答 .

(有些变量可能是法语,因为我说法语,我可能会留下英语错误):)

/*

SD card datalogger

This example shows how to log data from three analog sensors

to an SD card using the SD library.

The circuit:

* analog sensors on analog ins 0, 1, and 2

* 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 24 Nov 2010

modified 9 Apr 2012

by Tom Igoe

This example code is in the public domain.

*/

#include

#include

#include "RTClib.h"

#include

#include

#include

#include "DHT.h"

#include

#define DHTPIN 2

#define ONE_WIRE_BUS 3

#define DHTTYPE DHT22

OneWire oneWire(ONE_WIRE_BUS);

DallasTemperature sensors(&oneWire);

DHT dht(DHTPIN, DHTTYPE);

RTC_DS1307 rtc;

Adafruit_MPL3115A2 baro = Adafruit_MPL3115A2();

const int chipSelect = 10;

float temperatureWP;

float temperature2;

int luminosite;

float humidity;

float pascals;

float heatIndex;

void setup() {

// Open serial communications and wait for port to open:

Serial.begin(9600);

sensors.begin();

dht.begin();

if (! rtc.begin()) {

Serial.println("Couldn't find RTC");

}

// following line sets the RTC to the date & time this sketch was compiled

// This line sets the RTC with an explicit date & time, for example to set

// January 21, 2014 at 3am you would call:

//rtc.adjust(DateTime(2018, 3, 11, 14, 19, 0));

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

// see if the card is present and can be initialized:

if (!SD.begin(chipSelect)) {

Serial.println("Card failed, or not present");

// don't do anything more:

return;

}

Serial.println("card initialized.");

File dataFile = SD.open("datalog12.txt", FILE_WRITE);

dataFile.println("Date et heure \t pression \t luminosite \t temperatureWP \t temperature2 \t humidity \t heat index");

dataFile.close();

Serial.println("Date et heure \t pression \t luminosite \t temperatureWP \t temperature2 \t humidity \t heat index");

Serial.println("SETUP DONE");

}

void loop() {

DateTime now = rtc.now();

// make a string for assembling the data to log:

String dataString = "";

sensors.requestTemperatures();

// read three sensors and append to the string:

temperatureWP = sensors.getTempCByIndex(0);

temperature2 = dht.readTemperature();

humidity = dht.readHumidity();

luminosite = analogRead(A1);

pascals = baro.getPressure();

heatIndex = dht.computeHeatIndex(temperature2, humidity, false);

dataString += String(pascals);

dataString += String("\t");

dataString += String(luminosite);

dataString += String("\t");

dataString += String(temperatureWP);

dataString += String("\t");

dataString += String(temperature2);

dataString += String("\t");

dataString += String(humidity);

dataString += String("\t");

dataString += String(heatIndex);

// open the file. note that only one file can be open at a time,

// so you have to close this one before opening another.

File dataFile = SD.open("datalog.txt", FILE_WRITE);

// if the file is available, write to it:

if (dataFile) {

dataFile.print(now.day(), DEC);

dataFile.print('/');

dataFile.print(now.month(), DEC);

dataFile.print('/');

dataFile.print(now.year(), DEC);

dataFile.print(" ");

dataFile.print(now.hour(), DEC);

dataFile.print(':');

dataFile.print(now.minute(), DEC);

dataFile.print(':');

dataFile.print(now.second(), DEC);

dataFile.print("\t");

dataFile.println(dataString);

dataFile.close();

// print to the serial port too:

Serial.print(now.day(), DEC);

Serial.print('/');

Serial.print(now.month(), DEC);

Serial.print('/');

Serial.print(now.year(), DEC);

Serial.print(" ");

Serial.print(now.hour(), DEC);

Serial.print(':');

Serial.print(now.minute(), DEC);

Serial.print(':');

Serial.print(now.second(), DEC);

Serial.print("\t");

Serial.println(dataString);

}

// if the file isn't open, pop up an error:

else {

Serial.println("error opening datalog.txt");

}

delay(10000);

}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值