Thanks for your responses. I will answer both request above in this reply.
First, interestingly enough, I skipped this when going through the tutorial and went right to the data logging. Coming back to it now, the CardInfo program gives me these compile errors.
Code: Select all
Arduino: 1.8.8 (Mac OS X), Board: "Adafruit ESP32 Feather, 80MHz, 921600, None"
CardInfo:27:1: error: 'Sd2Card' does not name a type
Sd2Card card;
^
CardInfo:28:1: error: 'SdVolume' does not name a type
SdVolume volume;
^
CardInfo:29:1: error: 'SdFile' does not name a type
SdFile root;
^
/var/folders/6s/fqymhk4n27l029_qtg2kcmpcv5tztk/T/arduino_modified_sketch_432499/CardInfo.ino: In function 'void setup()':
CardInfo:50:8: error: 'card' was not declared in this scope
if (!card.init(SPI_HALF_SPEED, chipSelect)) {
^
CardInfo:50:18: error: 'SPI_HALF_SPEED' was not declared in this scope
if (!card.init(SPI_HALF_SPEED, chipSelect)) {
^
CardInfo:63:11: error: 'card' was not declared in this scope
switch (card.type()) {
^
CardInfo:64:10: error: 'SD_CARD_TYPE_SD1' was not declared in this scope
case SD_CARD_TYPE_SD1:
^
CardInfo:67:10: error: 'SD_CARD_TYPE_SD2' was not declared in this scope
case SD_CARD_TYPE_SD2:
^
CardInfo:70:10: error: 'SD_CARD_TYPE_SDHC' was not declared in this scope
case SD_CARD_TYPE_SDHC:
^
CardInfo:78:8: error: 'volume' was not declared in this scope
if (!volume.init(card)) {
^
CardInfo:78:20: error: 'card' was not declared in this scope
if (!volume.init(card)) {
^
CardInfo:84:18: error: 'volume' was not declared in this scope
Serial.println(volume.clusterCount());
^
CardInfo:109:3: error: 'root' was not declared in this scope
root.openRoot(volume);
^
CardInfo:112:11: error: 'LS_R' was not declared in this scope
root.ls(LS_R | LS_DATE | LS_SIZE);
^
CardInfo:112:18: error: 'LS_DATE' was not declared in this scope
root.ls(LS_R | LS_DATE | LS_SIZE);
^
CardInfo:112:28: error: 'LS_SIZE' was not declared in this scope
root.ls(LS_R | LS_DATE | LS_SIZE);
^
Multiple libraries were found for "SD.h"
Used: /Users/username/Library/Arduino15/packages/esp32/hardware/esp32/1.0.1/libraries/SD
Not used: /Applications/Arduino.app/Contents/Java/libraries/SD
exit status 1
'Sd2Card' does not name a type
This report would have more information with
"Show verbose output during compilation"
option enabled in File -> Preferences.
I did change the chipSelect line to use 33 as stated for ESP32 in the tutorial documentation
As for the code that is writing, I tried several. First, I will include the code for the Datalogger example from the Arduino example library (with only a change to chipSelect pin# to 33 same as above).
Code: Select all
/*
SD card datalogger
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 (for MKRZero SD: SDCARD_SS_PIN)
created 24 Nov 2010
modified 9 Apr 2012
by Tom Igoe
M
This example code is in the public domain.
*/
#include <SPI.h>
#include <SD.h>
const int chipSelect = 33;
void setup() {
// Open serial communications and wait for port to open:
Serial.begin(9600);
while (!Serial) {
; // wait for serial port to connect. Needed for native USB port only
}
Serial.print("Initializing SD card...");
// 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:
while (1);
}
Serial.println("card initialized.");
}
void loop() {
// make a string for assembling the data to log:
String dataString = "";
// read three sensors and append to the string:
for (int analogPin = 0; analogPin < 3; analogPin++) {
int sensor = analogRead(analogPin);
dataString += String(sensor);
if (analogPin < 2) {
dataString += ",";
}
}
// 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(dataString);
dataFile.close();
// print to the serial port too:
Serial.println(dataString);
}
// if the file isn't open, pop up an error:
else {
Serial.println("error opening datalog.txt");
}
}
The result from running this does not yield any files on the SD Card and yields this on the serial port monitor repeatedly.
Code: Select all
...
error opening datalog.txt
error opening datalog.txt
error opening datalog.txt
...
However, if I change the line
Code: Select all
File dataFile = SD.open("datalog.txt", FILE_WRITE);
to include a forward slash before the file name like this
Code: Select all
File dataFile = SD.open("/datalog.txt", FILE_WRITE);
I now get a file written to the SD card called "datalog.txt" but it has no contents. Lines like this will also fill the serial port monitor window.
Code: Select all
...
502,0,432
3497,0,464
3491,0,468
3501,0,468
...
It would seem from this that the examples are out of date with the actual expectations of the SD library open function.
I also used the code from the tutorial posted at this link near the bottom (Example logging sketch).
https://learn.adafruit.com/adafruit-ada ... ketch-7-24
Again I change the chipSelect (or in this example cardSelect) pin# to 33. Again to get the files to actually show up on the card I had to make the changes mentioned above. The full sketch code pasted here with changes.
Code: Select all
#include <SPI.h>
#include <SD.h>
// Set the pins used
#define cardSelect 33
File logfile;
// blink out an error code
void error(uint8_t errno) {
while(1) {
uint8_t i;
for (i=0; i<errno; i++) {
digitalWrite(13, HIGH);
delay(100);
digitalWrite(13, LOW);
delay(100);
}
for (i=errno; i<10; i++) {
delay(200);
}
}
}
// This line is not needed if you have Adafruit SAMD board package 1.6.2+
// #define Serial SerialUSB
void setup() {
// connect at 115200 so we can read the GPS fast enough and echo without dropping chars
// also spit it out
Serial.begin(115200);
Serial.println("\r\nAnalog logger test");
pinMode(13, OUTPUT);
// see if the card is present and can be initialized:
if (!SD.begin(cardSelect)) {
Serial.println("Card init. failed!");
error(2);
}
char filename[15];
strcpy(filename, "/ANALOG00.TXT");
for (uint8_t i = 0; i < 100; i++) {
filename[7] = '0' + i/10;
filename[8] = '0' + i%10;
// create if does not exist, do not open existing, write, sync after write
if (! SD.exists(filename)) {
break;
}
}
logfile = SD.open(filename, FILE_WRITE);
if( ! logfile ) {
Serial.print("Couldnt create ");
Serial.println(filename);
error(3);
}
Serial.print("Writing to ");
Serial.println(filename);
pinMode(13, OUTPUT);
pinMode(8, OUTPUT);
Serial.println("Ready!");
}
uint8_t i=0;
void loop() {
digitalWrite(8, HIGH);
logfile.print("A0 = "); logfile.println(analogRead(0));
Serial.print("A0 = "); Serial.println(analogRead(0));
digitalWrite(8, LOW);
delay(100);
}
And I get this output on the serial port monitor.
Code: Select all
Analog logger test
Writing to /ANALOG01.TXT
Ready!
A0 = 3643
A0 = 3643
A0 = 3647
A0 = 3645
A0 = 3647
...
And if I hit the reset button, you can see from the output, it does see the file on the file system when I include the forward slash and uses the next increment.
Code: Select all
Analog logger test
Writing to /ANALOG02.TXT
Ready!
A0 = 3635
A0 = 3639
A0 = 3645
However, when I take the SD Card out and put it into computer and view the files, they are all empty.
Thanks again for you help with this.