I have a Dallas 1-wire simple sketch that reports the temperature from two different sensors... I am on a UNO R3 with a Ethernet shield plugged in. I just got a SD card for it and plugged it into the ethernet sheild.
I would like to learn how to record that data to the SD card, something simple so that I can graph it later..
column 1: some number value starting at 1
column 2: the internal temperature sensor
column 3: the external temperature sensor
Dallas code below:
#include <OneWire.h>
#include <DallasTemperature.h>
// Data wire is plugged into pin 2 on the Arduino
#define ONE_WIRE_BUS 2
// Setup a oneWire instance to communicate with any OneWire devices
// (not just Maxim/Dallas temperature ICs)
OneWire oneWire(ONE_WIRE_BUS);
// Pass our oneWire reference to Dallas Temperature.
DallasTemperature sensors(&oneWire);
void setup(void)
{
// start serial port
Serial.begin(9600);
// Start up the library
sensors.begin();
}
void loop(void)
{
delay(5000);
sensors.requestTemperatures();
Serial.print("External Temperature is: ");
Serial.print(sensors.getTempCByIndex(0) * 1.8 + 32.0); // Convert to F
Serial.print('\n');
Serial.print("Internal Temperature is: ");
Serial.print(sensors.getTempCByIndex(1) * 1.8 + 32.0); // Convert to F
Serial.print('\n');
}
SD card below (the temp sensors are on pin 2)... this code example I think was for like 3 different sensors... I just need to learn how to adopt it... thank you!
#include <SPI.h>
#include <SD.h>
const int chipSelect = 2;
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...");
// 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.");
}
void loop() {
// make a string for assembling the data to log:
String dataString = "";
// read three sensors and append to the string:
for (int analogPin = 0; analogPin < 3; analogPin++) {
int sensor = analogRead(analogPin);
dataString += String(sensor);
if (analogPin < 2) {
dataString += ",";
}
}
// 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.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");
}
}