Author Topic: Can't write to microSD  (Read 5108 times)

nathan

  • RFduino Newbie
  • *
  • Posts: 1
  • Karma: +0/-0
    • View Profile
Can't write to microSD
« on: April 29, 2015, 05:13:50 PM »
Trying to use the following code:

Code: [Select]
/*
  SD card datalogger
 
 
 Modified by Ruben Kertesz 11-9-03
  Using temperature reading on RFDuino
   Using proper chip select (6)
    Using direct write of float value to datafile rather than converting to string
 
 This example shows how to log data from three analog sensors
 to an SD card using the SD library.
 
 The circuit:
 * analog sensors on analog ins 0, 1, and 2
 * SD card attached to SPI bus as follows:
 ** MOSI - pin 11
 ** MISO - pin 12
 ** CLK - pin 13
 ** CS - pin 4
 
 created  24 Nov 2010
 modified 9 Apr 2012
 by Tom Igoe
 
 This example code is in the public domain.
 
 */

#include <SPI.h>
#include <SD.h>
#include<stdlib.h>


// On the Ethernet Shield, CS is pin 4. Note that even if it's not
// used as the CS pin, the hardware CS pin (10 on most Arduino boards,
// 53 on the Mega) must be left as an output or the SD library
// functions will not work.
const int chipSelect = 6;

void setup()
{
 // Open serial communications and wait for port to open:
  Serial.begin(9600);
   while (!Serial) {
    ; // wait for serial port to connect. Needed for Leonardo only
  }


  Serial.print("Initializing SD card...");
  // make sure that the default chip select pin is set to
  // output, even if you don't use it:
  pinMode(10, OUTPUT);
 
  // 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()
{

  // sample once every 5 second, otherwise set to ultra low power(?)
  RFduino_ULPDelay( SECONDS(5) ); //cribbed from the temperature example
 
  // make a string for assembling the data to log:
  String dataString = "";
  dataString += "Temperature (celsius) = ";

  // read the temp sensor and append to the string:
   float temp = RFduino_temperature(CELSIUS);
   // dataString += String(temp); //we can't use this because we would either need
   // a header file to convert float to string or we would need to use AVR code
   // e.g. http://forum.arduino.cc/index.php/topic,37391.0.html
   // which I don't think can be used (I mean AVR) on the RF duino, right?
 
  // 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(); // go to next line
    dataFile.print(dataString);
    dataFile.print(temp); // separate from dataSrting because this is a float that I
    // don't want to convert to string
    dataFile.close();
    // print to the serial port too:
    Serial.println();
    Serial.print(dataString);
    Serial.print(temp);
   
  } 
  // if the file isn't open, pop up an error:
  else {
    Serial.println("error opening datalog.txt");
  }
}


and am getting this error:

Quote
Arduino: 1.6.3 (Mac OS X), Board: "RFduino"

Build options changed, rebuilding all
/Applications/Arduino.app/Contents/Java/libraries/SD/src/utility/Sd2Card.cpp:27:8: error: 'SPISettings' does not name a type
 static SPISettings settings;
        ^
/Applications/Arduino.app/Contents/Java/libraries/SD/src/utility/Sd2Card.cpp: In member function 'void Sd2Card::chipSelectHigh()':
/Applications/Arduino.app/Contents/Java/libraries/SD/src/utility/Sd2Card.cpp:167:9: error: 'class SPIClass' has no member named 'endTransaction'
     SPI.endTransaction();
         ^
/Applications/Arduino.app/Contents/Java/libraries/SD/src/utility/Sd2Card.cpp: In member function 'void Sd2Card::chipSelectLow()':
/Applications/Arduino.app/Contents/Java/libraries/SD/src/utility/Sd2Card.cpp:176:9: error: 'class SPIClass' has no member named 'beginTransaction'
     SPI.beginTransaction(settings);
         ^
/Applications/Arduino.app/Contents/Java/libraries/SD/src/utility/Sd2Card.cpp:176:26: error: 'settings' was not declared in this scope
     SPI.beginTransaction(settings);
                          ^
/Applications/Arduino.app/Contents/Java/libraries/SD/src/utility/Sd2Card.cpp: In member function 'uint8_t Sd2Card::init(uint8_t, uint8_t)':
/Applications/Arduino.app/Contents/Java/libraries/SD/src/utility/Sd2Card.cpp:269:3: error: 'settings' was not declared in this scope
   settings = SPISettings(250000, MSBFIRST, SPI_MODE0);
   ^
/Applications/Arduino.app/Contents/Java/libraries/SD/src/utility/Sd2Card.cpp:269:53: error: 'SPISettings' was not declared in this scope
   settings = SPISettings(250000, MSBFIRST, SPI_MODE0);
                                                     ^
/Applications/Arduino.app/Contents/Java/libraries/SD/src/utility/Sd2Card.cpp:275:7: error: 'class SPIClass' has no member named 'beginTransaction'
   SPI.beginTransaction(settings);
       ^
/Applications/Arduino.app/Contents/Java/libraries/SD/src/utility/Sd2Card.cpp:279:7: error: 'class SPIClass' has no member named 'endTransaction'
   SPI.endTransaction();
       ^
/Applications/Arduino.app/Contents/Java/libraries/SD/src/utility/Sd2Card.cpp: In member function 'uint8_t Sd2Card::setSckRate(uint8_t)':
/Applications/Arduino.app/Contents/Java/libraries/SD/src/utility/Sd2Card.cpp:518:14: error: 'settings' was not declared in this scope
     case 0:  settings = SPISettings(25000000, MSBFIRST, SPI_MODE0); break;
              ^
/Applications/Arduino.app/Contents/Java/libraries/SD/src/utility/Sd2Card.cpp:518:66: error: 'SPISettings' was not declared in this scope
     case 0:  settings = SPISettings(25000000, MSBFIRST, SPI_MODE0); break;
                                                                  ^
Error compiling.

  This report would have more information with
  "Show verbose output during compilation"
  enabled in File > Preferences.

Using Arduino 1.6.3.

tolson

  • Global Moderator
  • *****
  • Posts: 870
  • Karma: +20/-0
    • View Profile
    • Thomas Olson Consulting
Re: Can't write to microSD
« Reply #1 on: April 29, 2015, 07:25:30 PM »
You also have to change
pinMode(10,OUTPUT);
to
pinMode(6,OUTPUT);

TomWS

  • RFduino Jr. Member
  • **
  • Posts: 26
  • Karma: +0/-0
    • View Profile
Re: Can't write to microSD
« Reply #2 on: May 08, 2015, 04:58:15 PM »
@nathan,
Did you ever get this resolved?   I don't believe the 'standard' Arduino SD library (after IDE version 1.5.7) can be used with RFduino since there was the addition of SPI transactions and that code was VERY AVR oriented.  The older library works fine.  I can help if you're still looking for a solution...

Tom

SuperJonotron

  • RFduino Newbie
  • *
  • Posts: 9
  • Karma: +0/-0
    • View Profile
Re: Can't write to microSD
« Reply #3 on: May 30, 2015, 02:29:46 PM »
In an attempt to get some third party libraries to show up I upgraded from 1.5.8 to 1.6.4 (was RFDuino documentation says) and upgraded to the latest RFDUino release through usage of board manager (2.3.1).

Running the standard SD example (pick any one) it throws that long list of Sd2Card errors.  Is it safe to assume that SD card support for the RFDuino is no longer available on the latest releases? Has anyone had any luck resolving the SD library issuess? 

TomWS

  • RFduino Jr. Member
  • **
  • Posts: 26
  • Karma: +0/-0
    • View Profile
Re: Can't write to microSD
« Reply #4 on: June 01, 2015, 04:57:38 AM »
Install this to Arduino/hardware/arduino/RFduino/libraries.
This works under 1.6.0, I don't know if it works under 1.6.4 but may.

SuperJonotron

  • RFduino Newbie
  • *
  • Posts: 9
  • Karma: +0/-0
    • View Profile
Re: Can't write to microSD
« Reply #5 on: June 07, 2015, 01:50:01 PM »
Quote
Install this to Arduino/hardware/arduino/RFduino/libraries.
This works under 1.6.0, I don't know if it works under 1.6.4 but may.

Not sure if 1.6.0 was using the board manager to get the RFDuino library yet but since 1.6.4 does, the path to the libraries is a little different. I can't seem to find the original link that showed me where they install but for me on windows it was:

%APPDATA%\Roaming\Arduino15\packages\RFduino\hardware\RFduino\2.3.1\libraries

Once I put old SD library there my SD sketches compiled and uploaded just fine again.

Thanks.

marcomauro

  • RFduino Newbie
  • *
  • Posts: 3
  • Karma: +0/-0
    • View Profile
Re: Can't write to microSD
« Reply #6 on: July 08, 2015, 12:18:13 PM »
Install this to Arduino/hardware/arduino/RFduino/libraries.
This works under 1.6.0, I don't know if it works under 1.6.4 but may.

It works thank you a lot !
Tested under Arduino 1.6.5-r2 using this procedure
- Install RFduino via arduino boards manager
- Replace TomWS SD libary in arduino IDE ...\arduino-1.6.5-r2\libraries

I have tested CardInfo example and it works

cizaro

  • Guest
Re: Can't write to microSD
« Reply #7 on: January 21, 2016, 04:23:39 AM »
It work for me without via arduino boards manager installation of RFduino.