UNO/MEGA SD library for logger

For other supported Arduino products from Adafruit: Shields, accessories, etc.

Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.
Locked
User avatar
spiney
 
Posts: 214
Joined: Mon Jul 09, 2012 6:35 am

UNO/MEGA SD library for logger

Post by spiney »

I am having trouble with the SD libraries. I am working with both a UNO r3 and a Mega 2560.
It is a real pain having to change between the new and old SD libraries. I have renamed the old SD library as "OldSDBackup" as suggested and left it in the Arduino library file in Documents. The Arduino program still saw the renamed file so I moved it into a "Temp" file, leaving, what I belive is the new SD file where it should be. I get this error

Code: Select all

PTWind1502.ino: In function 'void setup()':
PTWind1502:130: error: no matching function for call to 'SDClass::begin(int, int, int, int)'
C:\Program Files\Arduino\libraries\SD/SD.h:69: note: candidates are: boolean SDClass::begin(uint8_t)
Does this mean that the old SD library is being addressed?
Cannot separate named libraries be provided so that both UNO and Mega coild be used without editing the Library file?

User avatar
adafruit_support_bill
 
Posts: 88142
Joined: Sat Feb 07, 2009 10:11 am

Re: UNO/MEGA SD library for logger

Post by adafruit_support_bill »

There is no need to switch libraries. The Adafruit library is a superset of the old one.

User avatar
spiney
 
Posts: 214
Joined: Mon Jul 09, 2012 6:35 am

Re: UNO/MEGA SD library for logger

Post by spiney »

OK. Thank you.
I was confused about whether to use

Code: Select all

pinMode(53, OUTPUT); 
or

Code: Select all

pinMode(10,11,12,13, OUTPUT);
I found that adding

Code: Select all

#include <SPI.h>
and the "53"allowed the code to verify. As you can see, I don't understand just what I am doing here! For completeness here is the setup.

Code: Select all

#include <avr/wdt.h>
#include <SPI.h>
#include <SD.h>
#include <Wire.h>
#include <Adafruit_MCP23017.h>
#include <Adafruit_BMP085.h>
#include <RTClib.h>
#include <Time.h>
#include <TimeAlarms.h>
#include <Adafruit_RGBLCDShield.h>
#include <PinChangeInt.h>
#include <PinChangeIntConfig.h>
#define PIN 3  // the pin for button/ rain gauge
#define STOP_SWITCH 2
 bool stopped = false;
RTC_DS1307 RTC;
time_t syncProvider()     //this does the same thing as RTC_DS1307::get() but it is only a definition.
//. Copied the next line from an Alarm example.
//setSyncProvider(syncProvider);     //reference our syncProvider function instead of RTC_DS1307::get()
                                           //This tells the Time library to sync the Arduino time to the RTC. 

{
  return RTC.now().unixtime();
}

uint32_t syncTime = 0; // time of last sync()  

// for the data logging shield, we use digital pin 10 for the SD cs line
const int chipSelect = 10;

// the logging files
File logfile;
File rainfile;
void error(char *str)
{
  Serial.print("error: ");
  Serial.println(str);
  while(1);
}
 long mon=0;
 int dy=0;
 int hr=0;
 int mn=0;
 int sec=0;
volatile int flag=0;
int nflag;
int Run = 0;
int test = 1;
int nutim = 0;
int oldtim = 0;
Adafruit_RGBLCDShield lcd = Adafruit_RGBLCDShield();

byte fetch_humidity_temperature(unsigned int *p_Humidity, unsigned int *p_Temperature);
float maxT;
float minT = 90;
float maxTy;
float minTy;
byte _status;
unsigned int H_dat, T_dat;
float RH, T_C;
Adafruit_BMP085 bmp;
long zerosec = millis();

const int ledPin = 13; //LED connected to digital pin 13
const int clockPin = 7; //output to clock
const int CSnPin = 6; //output to chip select
const int inputPin = 5; //read AS5040


int inputstream = 0; //one bit read from pin
long packeddata = 0; //two bytes concatenated from inputstream
long angle = 0; //holds processed angle value
long anglemask = 262080; // 0x111111111111000000: mask to obtain first 12 digits with position info
long statusmask = 63; //0x000000000111111; mask to obtain last 6 digits containing status info
long statusbits; //holds status/error information
int DECn; //bit holding decreasing magnet field error data
int INCn; //bit holding increasing magnet field error data
int OCF; //bit holding startup-valid bit
int COF; //bit holding cordic DSP processing error data
int LIN; //bit holding magnet field displacement error data
int debug = 1; //SET THIS TO 0 TO DISABLE PRINTING OF ERROR CODES
int shortdelay = 100; // this is the microseconds of delay in the data clock
//int longdelay = 2000; // this is the milliseconds between readings
int w, x, y, z;
int a, b, c, d;



void setup()
{
  Serial.begin(9600);
  
  pinMode(ledPin, OUTPUT); // visual signal of I/O to chip
  pinMode(clockPin, OUTPUT); // SCK
  pinMode(CSnPin, OUTPUT); // CSn -- has to toggle high and low to signal chip to start data transfer
  pinMode(inputPin, INPUT); // SDA
  pinMode(3, OUTPUT);
  pinMode(4, OUTPUT);
  pinMode(8, OUTPUT);
  pinMode(9, OUTPUT);
  
  
   if (!bmp.begin()) {
   Serial.println("Could not find a valid BMP085 sensor, check wiring!");
   while (1) {}
  }
  
  // set up the LCD's number of columns and rows: 
  lcd.begin(16, 2);
  Wire.begin();
  RTC.begin();
  if (! RTC.isrunning()) {
  // following line sets the RTC to the date & time this sketch was compiled so if it is used other than
  //on load time, the RTC time will be set back to whatever time and date compilation occured. 
  // this can be improved by issuing warning if RTC time is behind arduino time using an If.
  RTC.adjust(DateTime(__DATE__, __TIME__));
  }
 //RTC.adjust(DateTime(__DATE__, __TIME__));
  setSyncProvider(syncProvider);     //reference our syncProvider function instead of RTC_DS1307::get()

  //configure pin2 as an input and enable the internal pull-up resistor
      pinMode(STOP_SWITCH, INPUT_PULLUP);
      
  // initialize the SD card
  Serial.print("InitSD");
  // make sure that the default chip select pin is set to
  // output, even if you don't use it:
  pinMode(53, OUTPUT);

  // see if the card is present and can be initialized:
  if (!SD.begin(10, 11, 12, 13)) 
  {
    error("Cd fail");
  }
  Serial.println("cdinit.");
  // create a new file
  char filename[] = "LOGGER00.CSV";
  for (uint8_t i = 0; i < 100; i++) 
  {
    filename[6] = i/10 + '0';
    filename[7] = i%10 + '0';
    if (! SD.exists(filename)) {
      // only open a new file if it doesn't exist
      logfile = SD.open(filename, FILE_WRITE); 
      break;  // leave the loop!    
    }
  }

  if (! logfile) {
    error("No lgfile");
  }

  Serial.print("Log to ");
  Serial.println(filename);
  Serial.println();

  // create a new file
  char filename2[] = "RAINEY00.CSV";
  for (uint8_t i = 0; i < 100; i++) 
  {
    filename2[6] = i/10 + '0';
    filename2[7] = i%10 + '0';
    if (! SD.exists(filename2)) {
      // only open a new file if it doesn't exist
      rainfile = SD.open(filename2, FILE_WRITE); 
      break;  // leave the loop!
    }
  }
//This should work but does not - why?
 /*  if (! rainfile) {
   error("couldnt create rnfile");
   }
  */ 
  Serial.print("Log to ");
  Serial.println(filename2);
  Serial.println();

  pinMode(PIN, INPUT);     //set the pin to input
  digitalWrite(PIN, LOW); //use the internal pullup resistor
  PCintPort::attachInterrupt(PIN, burpcount,RISING); // attach a PinChange Interrupt to our pin on the rising edge
  // (RISING, FALLING and CHANGE all work with this library)
  // and execute the function burpcount when that pin changes 

 Repeats();
  while (minute() != 0) //Prog holds here until the hour.
  {
    delay(1000);
  }
 
  Alarm.timerRepeat(1800, Repeats);
  Alarm.timerRepeat(14, Repeat2);
  Alarm.alarmRepeat(0,1,0, Repeat3);
  Alarm.timerRepeat(10, Wind);
  
  wdt_enable(WDTO_8S);
}

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

Return to “Other Arduino products from Adafruit”