SD Data Logger with Arduino Zero

Adafruit Ethernet, Motor, Proto, Wave, Datalogger, GPS Shields - etc!

Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.
Locked
User avatar
llag
 
Posts: 7
Joined: Thu Apr 21, 2016 12:13 am

SD Data Logger with Arduino Zero

Post by llag »

I am trying to use the data logger (ID: 1141) with my arduino zero. I used the example provided in your learn section and the built in example, then just changed it for my sensor. Is there something I need to change with the board or in the code to allow the data logger to work with a zero? Do I need to amend the SD library (SD2Card.h) to reference the ICSP pins to get it to work?

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");
  }
}
I have got it to work on an uno so I know the card is formatted correctly (FAT32) and the code for the sensor is correct.
Last edited by llag on Wed Apr 27, 2016 11:10 pm, edited 1 time in total.

User avatar
Franklin97355
 
Posts: 23911
Joined: Mon Apr 21, 2008 2:33 pm

Re: SD Data Logger with Arduino Zero

Post by Franklin97355 »

I used the example provided in your learn section and the built in example, then just changed it for my sensor.
Have you tried them without modifying them but connecting the logger to the pins required?

User avatar
llag
 
Posts: 7
Joined: Thu Apr 21, 2016 12:13 am

Re: SD Data Logger with Arduino Zero

Post by llag »

Tried with the changes required for the Mega but made the changes for SPI Pins.

https://learn.adafruit.com/adafruit-dat ... me-clock-1

Tried it with the code straight from github with the only modification the RTC so that it is able to compile for the zero
https://github.com/adafruit/Light-and-T ... logger.pde

I connected data logger pins 11 to ICSP-4 on zero, 12 to ICSP-1 on zero and 13 to ICSP-3 on zero using female-female connecters.

Get "Initializing SD card...error: Card failed, or not present"

User avatar
llag
 
Posts: 7
Joined: Thu Apr 21, 2016 12:13 am

Re: SD Data Logger with Arduino Zero

Post by llag »

New day. Started fresh with new cables and everything and it worked. Swear is same as I had it yesterday but oh well works now.

Thanks for the help.

Locked
Please be positive and constructive with your questions and comments.

Return to “Arduino Shields from Adafruit”