First commit

This commit is contained in:
Txus Ordorika 2019-02-12 22:49:19 +01:00
commit f402d7d20a
6 changed files with 162 additions and 0 deletions

1
.gitignore vendored Normal file
View File

@ -0,0 +1 @@
libraries

27
DHT/DHT.ino Normal file
View File

@ -0,0 +1,27 @@
#include <DHT.h>
#define DHTPIN 2
#define DHTTYPE DHT22
DHT dht(DHTPIN, DHTTYPE);
void setup() {
Serial.begin(9600);
}
void loop() {
float h = dht.readHumidity();
float t = dht.readTemperature();
if (isnan(t) || isnan(h)) {
Serial.print("Failed to read from DHT");
} else {
Serial.print("Hezetasune:");
Serial.print(h);
Serial.println("");
Serial.print("Tenperaturie:");
Serial.print(t);
Serial.println("");
delay(5000);
}
}

BIN
DHT/image.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 120 KiB

10
Helloworld/Helloworld.ino Normal file
View File

@ -0,0 +1,10 @@
void setup() {
// put your setup code here, to run once:
Serial.begin(9600);
}
void loop() {
// put your main code here, to run repeatedly:
Serial.print("Hello world");
delay(5000);
}

View File

@ -0,0 +1,39 @@
#include <DHT.h>
#define DHTPIN 2
#define DHTTYPE DHT22
float previousT = -1.0;
//float t = -1.0;
DHT dht(DHTPIN, DHTTYPE);
void setup() {
// put your setup code here, to run once:
dht.begin();
Serial.begin(9600);
}
void loop() {
float h = dht.readHumidity();
float t = dht.readTemperature();
if (isnan(t) || isnan(h)){
Serial.println("Failed to read from DHT");
return;
}
Serial.print("Hezetasuna:");
Serial.print(h);
Serial.println("");
Serial.print("Tenperatura:");
Serial.print(t);
Serial.println("");
if(previousT != -1.0) {
Serial.print("Aldaketa: ");
Serial.print(t - previousT);
Serial.println("");
}
delay(5000);
previousT = t;
}

View File

@ -0,0 +1,85 @@
#include <SD.h>
#include <SPI.h>
#include <DHT.h>
#define DHTPIN 2
#define DHTTYPE DHT22
const int chipSelect = 4;
DHT dht(DHTPIN, DHTTYPE);
void setup() {
// put your setup code here, to run once:
dht.begin();
Serial.begin(9600);
while (!Serial) {
; // wait for serial port to connect. Needed for native USB port only
}
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:
while (1);
}
Serial.println("card initialized.");
}
/* void writeSD(dataString) {
File dataFile = SD.open("datalog.txt", FILE_WRITE);
// if the file is available, write to it:
if (dataFile) {
dataFile.println(dataString);
dataFile.close();
// print to the serial port too:
Serial.println(dataString);
}
// if the file isn't open, pop up an error:
else {
Serial.println("error opening datalog.txt");
}
}
*/
void loop() {
float h = dht.readHumidity();
float t = dht.readTemperature();
if (isnan(t) || isnan(h)){
Serial.println("Failed to read from DHT");
return;
}
Serial.print("Hezetasuna:");
Serial.print(h);
Serial.println("");
Serial.print("Tenperatura:");
Serial.print(t);
Serial.println("");
String dataString = "";
dataString = String(h) + ";" + String(t) + ";";
Serial.print("dataString:");
Serial.println(dataString + "\n");
File dataFile = SD.open("datalog.txt", FILE_WRITE);
// if the file is available, write to it:
if (dataFile) {
dataFile.println(dataString);
dataFile.close();
// print to the serial port too:
Serial.println(dataString);
}
// if the file isn't open, pop up an error:
else {
Serial.println("error opening datalog.txt");
}
delay(5000);
}