OK, it looks like I've solved most of the problems

First, the power supply. As mentioned earlier, Seeedstudio's SD card shield plugs into both the digital pins (D9-D13 plus GND) and the power supply pins (3.3V, 5V, and 2xGND). Luckily, the shield can be powered either from the 3.3V pin, or from D9, you choose this with a small switch. So by switching to D9 and adding the following lines to the code, the shield doesn't really need the power supply pins.
Code:
pinMode(9, OUTPUT);
digitalWrite(9, HIGH);
Now that the shield doesn't need the power supply sockets, but my sensors do, I only pressed the digital pins into the sockets, slightly bending the pins:
It's not elegant, but it works.
Another workaround (which I may end up doing) is to use the ICSP socket to power my sensors (pin 2 = 5V, pin 6 = GND).
Next, I got the Arduino to write, then append, data onto the SD card by using the FAT16 libraries. I took one of the ready examples and hacked away.
When I was testing the data logging with two temperature sensors I started getting problems. The basic program opened a file for append, recorded both readings, closed the file, waited 1 second, 60 times. When hooked up to the computer through the USB the reading would be very jumpy - anywhere from 14°C to 19°C, but when powered by a 12V wallwart they more or less smoothed out. At least in the beginning, because when repeating the program the first sensor's readings would be around 33°C. Only the first run after uploading the sketch would be OK. I then changed the program to close then open the file every ten seconds and what I got was every tenth reading from sensor 1 was too high. So I added a 'dummy' read and delay before the real sensor read. This seems to work OK.
Now the only problem seems to be that even now and then there is a random reading. This doesn't happen every time the program is run, but when it does there is only reading which is off, for example:
Quote:
...
26: 16.89 16.89
27: 16.89 16.89
28: 16.89 16.89
29: 16.89 16.89
30: 16.89 17.38
31: 16.89 28.61
32: 16.89 16.89
33: 16.89 16.89
34: 16.89 16.89
35: 16.89 16.89
36: 16.89 16.89
37: 16.89 17.38
38: 16.89 17.38
...
|
or
Quote:
...
27: 19.82 19.82
28: 19.82 19.82
29: 19.82 19.82
30: 19.82 19.82
31: 19.82 19.82
32: 19.82 19.82
33: 48.63 19.82
34: 19.82 19.82
35: 19.82 19.82
36: 19.82 19.82
37: 19.82 19.82
38: 19.82 19.82
...
|
Below is the whole code I'm using, hopefully it'll help someone.
Code:
#include <Fat16.h>
#include <Fat16util.h> // use functions to print strings from flash memory
SdCard card;
Fat16 file;
float temp;
void setup(void) {
pinMode(9, OUTPUT);
digitalWrite(9, HIGH);
// initialize the SD card
card.init();
// initialize a FAT16 volume
Fat16::init(&card);
// create a new file
char name[] = "WRITE00.cvs";
for (uint8_t i = 0; i < 100; i++) {
name[5] = i/10 + '0';
name[6] = i%10 + '0';
// O_CREAT - create the file if it does not exist
// O_APPEND - seek to the end of the file prior to each write
// O_WRITE - open for write
if (file.open(name, O_CREAT | O_APPEND | O_WRITE)) break;
}
if (!file.isOpen()) exit;
file.close();
// clear write error
file.writeError = false;
// write data to file
for (char i=0; i<60; i++) {
if (!(i%10)) if (!file.open(name, O_CREAT | O_APPEND | O_WRITE)) break;
file.print(i,DEC);
file.print(": ");
if (!(i%10)) {
temp = analogRead(0);
delay(100);
}
temp = analogRead(0)*5/1024.0;
temp = temp - 0.5;
temp = temp / 0.01;
file.print(temp);
file.print(" ");
temp = analogRead(1)*5/1024.0;
temp = temp - 0.5;
temp = temp / 0.01;
file.println(temp);
if (!((i+1)%10)) {
if (!file.close()) break;
delay(900);}
else delay(1000);
}
// close file and force write of all data to the SD card
file.close();
}
void loop(void) {};