Show Posts
Pages: 1 2 [3] 4 5 ... 10
31  Forum 2005-2010 (read only) / Development / Re: Arduino SD Card Reading Problem on: August 16, 2010, 05:38:01 am
So is it not possible to swap the SD Card without resetting the Arduino? If it isnt then I will probably tie the sync button to the RESET and GND pins so that when a user presses the button it will reset the Arduino.
32  Forum 2005-2010 (read only) / Development / Arduino SD Card Reading Problem on: August 15, 2010, 07:57:16 pm
Hey I am using the SD Card Library from here: http://code.google.com/p/sdfatlib/

I am having a problem when reading the SD Card more than once. What I want to happen is when I click a "Sync Button", it should sync with the SD Card, and store values into an array. However, what happens is I power on my Arduino, Put SD Card in, Hit Sync Button, it shows me the proper values that is on the SD Card, and then it continues with the program. However, when I remove the SD Card, change one of the values on my computer, stick it back into the SD slot on the Arduino, click the sync button again, it gives me these random values. I have to reset the Arduino for it to read the changed values.

I used the error handler that was given and whenever I run it the second time it prompts "error: openRoot failed".

This is the Code that I used:
Code:
#include <SdFat.h>
#include <SdFatUtil.h>
#include <LiquidCrystal.h>
LiquidCrystal lcd (2, 3, 4, 5, 6, 7);

Sd2Card card;
SdVolume volume;
SdFile root;
SdFile file;

#define error(s) error_P(PSTR(s))

void error_P(const char* str) {
  PgmPrint("error: ");
  SerialPrintln_P(str);
  if (card.errorCode()) {
    PgmPrint("SD error: ");
    Serial.print(card.errorCode(), HEX);
    Serial.print(',');
    Serial.println(card.errorData(), HEX);
  }
  while(1);
}

int current_setpoint;
int cool_setpoint_values[7];
int heat_setpoint_values[7];

void setup()
{
  Serial.begin(9600);
  lcd.begin(20, 4);
}
    
void SDRead()
{
  if (!card.init(SPI_HALF_SPEED)) error("card.init failed");
  if (!volume.init(&card)) error("volume.init failed");
  if (!root.openRoot(&volume)) error("openRoot failed");
  
  if (file.open(&root, "VALUE00.TXT", O_READ)) {
  
  int val[14];
  int index = 0;
  int16_t n;
  uint8_t buf[14];
  while ((n = file.read(buf, sizeof(buf))) > 0) {
    for (int i = 0; i < n; i++){
      if ((int)buf[i] - 48 != -35 && (int)buf[i] - 48 != -38) {
        val[index] = (int)buf[i] - 48;
        index++;
      }
    }
  }
  for(int i = 0, index = 8; i <= 7; i += 2, index += 2) {
    cool_setpoint_values[i] = val[i] * 10 + val[i+1];
    heat_setpoint_values[index] = val[index] * 10 + val[index+1];
    lcd.clear();
    lcd.print(heat_setpoint_values[index]);
    delay(2000);
    lcd.clear();
  }
  }
   else
     error("file.open failed");
}

void sync_sd_card_data()
{
  const int sync_button = 14;
  pinMode(sync_button, INPUT);
  int sync_state = digitalRead(sync_button);
  
  if(sync_state == 1) {
    lcd.clear();
    lcd.print("Syncing...");
    delay(1000);
    SDRead();
    lcd.clear();
    lcd.print("You may now remove the SD Card.");
    delay(1000);
    lcd.clear();
  }
}

void loop()
{
  sync_sd_card_data();
}
  

33  Forum 2005-2010 (read only) / Development / Re: Arduino temperature SD logger on: August 27, 2010, 04:07:40 pm
The problem (I think) is that the SD Card library uses pins 13, 12, 11, and 10. Pins 13, 12, 11 are the SPI pins on the Arduino so those are needed for the SD Card. Connect the SD Card reader/writer to these pins. Also, make sure pin 10 is an output otherwise the SD interface will not work.
34  Forum 2005-2010 (read only) / Development / Re: Arduino temperature SD logger on: August 27, 2010, 06:38:51 am
To be able to determine what to do next, I need to see your code.
35  Forum 2005-2010 (read only) / Development / Re: Arduino temperature SD logger on: August 26, 2010, 11:16:11 pm
What do you mean by shut down? Is it not displaying? Are you using an LCD by any chance? I would think so because you said shut down... Please clarify the problem... Maybe even take a picture...
36  Forum 2005-2010 (read only) / Development / Re: Arduino temperature SD logger on: August 25, 2010, 10:56:58 pm
Look at this tutorial:

http://www.ladyada.net/make/logshield/index.html

It uses a data logging shield but you can just use the SD libraries that are included. They have an example project where they read the temperature of a fridge and store in the SD Card. Just follow the tutorial.
37  Forum 2005-2010 (read only) / Development / Practical Embedded Hacks - My New Blog on: August 22, 2010, 07:09:51 pm
Please follow and spread the word of my new blog:

http://practical-embedded-hacks.blogspot.com/
38  Forum 2005-2010 (read only) / Development / Re: How do people share Arduino code? on: August 19, 2010, 09:41:41 am
Why dont you just post it here on the Arduino Forum where everyone can see the code? You could probably link it to google.code or wherever you have uploaded your code.
39  Forum 2005-2010 (read only) / Development / Re: Arduino SD Card Read on: August 15, 2010, 11:47:09 am
Oh okay I'll do that... Thanks!
40  Forum 2005-2010 (read only) / Development / Re: Arduino SD Card Read on: August 15, 2010, 09:41:35 am
Oh... Ill remember that... Thanks for the links! They are really helpful!
41  Forum 2005-2010 (read only) / Development / Re: Arduino SD Card Read on: August 15, 2010, 06:09:17 am
Hey Paul... I figured it out. Seems that there was a character that was extra apart from the numbers from the SD Card. After every number from the SD Card, it displayed "1310". So I read all values and store into an integer array except when I read "1310" value.

Thanks for hinting me in the right direction!
42  Forum 2005-2010 (read only) / Development / Re: Arduino SD Card Read on: August 14, 2010, 12:39:25 pm
Ill try that... but it does not seem to be an EOF character...
43  Forum 2005-2010 (read only) / Development / Arduino SD Card Read on: August 14, 2010, 11:40:33 am
I got a library for the SD Card for the Arduino : http://code.google.com/p/sdfatlib/

From the examples folder, I used the program SDCard Read...
This program prints the text from the SDCard .txt file to the Serial Port.
However I want to store those numbers into an array of type int so that I can access them whenever I want. How do I do this?

The .txt file that I want to read is: 60
                                                  70
                                                  68
                                                  90

It is always going to be 8 2-digit numbers...
44  Forum 2005-2010 (read only) / Development / Re: Arduino Error Handler on: August 14, 2010, 10:44:54 am
Awesome! That is exactly what I wanted! Thanks again!! Ill ask you again if I have a problem...
45  Forum 2005-2010 (read only) / Development / Re: Arduino Error Handler on: August 14, 2010, 08:28:20 am
Wait what is char* err?
Pages: 1 2 [3] 4 5 ... 10