I tried connecting 11, 12 and 13 directly to the SPI on the zero but I still can't get it to work.
Code: Select all
#include <SPI.h>
#include <SD.h>
#include "IRTemp.h"
static const byte PIN_DATA = 1; // Choose any pins you like for these
static const byte PIN_CLOCK = 2;
static const byte PIN_ACQUIRE = 3;
static const TempUnit SCALE=CELSIUS; // Options are CELSIUS, FAHRENHEIT
IRTemp irTemp(PIN_ACQUIRE, PIN_CLOCK, PIN_DATA);
const int chipSelect = 10;
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...");
pinMode(10, OUTPUT);
digitalWrite(10, HIGH);
// 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 = "";
float irTemperature = irTemp.getIRTemperature(SCALE);
float ambientTemperature = irTemp.getAmbientTemperature(SCALE);
// 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("IR ");
dataFile.print(irTemperature);
dataFile.print("Ambient ");
dataFile.print(ambientTemperature);
dataFile.print("Time ");
dataFile.println(millis()/1000.0);
dataFile.close();
// print to the serial port too:
Serial.print(irTemperature);
Serial.println(millis()/1000.0);
}
// if the file isn't open, pop up an error:
else {
Serial.println("error opening datalog.txt");
}
}