Hi All,
I'm stumped. I have a program that is supposed to read a configuration file from the SD card and then validate and store the values into EEPROM. It should do this when a mechanical switch is activated at boot time. The problem I have is that if I use a mechanical switch on any pin (I've tried A0, A1, 1) then the SD card fails. If I put in a programmatic switch, everything works properly.
Here is the pertinent bits of code...
#define RECONFIG 0 // force a reconfig if '1', '0' for normal run
#include <NewSoftSerial.h>
#include <TinyGPS.h>
#include <PWMServo.h>
#include <EEPROM.h>
#include <EEPROMAnything.h>
#include <LiquidCrystal.h>
#include <SdFat.h>
/* Pin assignments */
static const int SD_ss = 10; // SD card select
static const int reconfig_pin = 1;
/* File name and directory assignments */
static const char* GameConfigName = "Game.cfg";
/* *********************************************************************
* function to parse the configuration file into its component parts of
* the configuration struct
*/
int readGameSettings(struct config_t *gameSettings) {
char *myinput;
char bigstring[151]="";
Msg(lcd, "Reading", "Settings", 2000);
// open the Game.cfg file.
SdFile myFile(GameConfigName, O_READ);
if (!myFile.isOpen()) { // Open failed
Msg(lcd, "Cfg File", "Failure2", 2000);
// return 1;
}
}
void setup() {
// Initialize the SD card
pinMode(SD_ss, OUTPUT);
if (!sd.init(SPI_HALF_SPEED, SD_ss)) {
Msg(lcd, "SD card", "failed!", 2000);
badSD = 1;
}
// Do we need to reconfigure the system
if ((digitalRead(reconfig_pin) == HIGH) || (RECONFIG == 1)){ // time to reconfigure --- Config switch set to "Config"
if (badSD) { // We need to reconfigure but can't read the SD card
Msg(lcd, "SD card", "failure", 5000);
PowerOff();
}
// Read game settings from SD card
if (readGameSettings(&gameSettings) == 1) { // failure during setup
Msg(lcd, "Settings", "incorrect", 2000);
PowerOff();
}
So I obviously cut out most of the program but those are the bits that are failing.
Scenario, if I use the programatic switch and "#define RECONFIG 1" then everything works no matter the state of the physical switch. If I "#define RECONFIG 0" and leave the physical switch "off" then the SD card and other files can be read/written to without problem. But if I turn on the physical switch then the program can no longer access the SD card and I get the error message "Cfg File Failure2".
For the mechanical switch to be "on" I've tried using internal pull-up resister with the switch-pin going to ground; I've tried external pull-up resistors (10K and 22K); I've tried external pull-down resistors with the switch-pin going to 5v. Same symptoms on every attempt.
Does anyone have any ideas what might be going on? BTW, I've tried a different Arduino and I've used this SD card and card-reader in other programs and they all work fine.
IDE 0022. Arduino Uno.
Thanks in advance for any help anyone might give!!
Greg