Why wont serial print my message after the loop is finished
Yeah for some reason after the Arduino loops through the file in my sd card it just stops it doesn't continue the code after the while loop and it doesn't start the loop method, I suspect its getting an error but im not sure where I would see that if that was even the case.
Please help me!
/*
** MOSI - pin 11
** MISO - pin 12
** CLK - pin 13
** CS - pin 4 (for MKRZero SD: SDCARD_SS_PIN)
*/
#include <SPI.h>
#include <SD.h>
#include "PATH/vector" //import vector
//inialtizes variables
File myFile;
int recNum = 0;
//set array as vector
std::vector< String > array;
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...");
if (!SD.begin(4)) {
Serial.println("initialization failed!");
while (1);
}
Serial.println("initialization done.");
myFile = SD.open("PCB.txt");
if (myFile) {
Serial.println("PCB.txt:");
while (myFile.available()){
Serial.println("In loop");
String list = myFile.readStringUntil('\n');
array.push_back(list);
recNum++; // Count the record
}
// close the file:
myFile.close();
}else {
// if the file didn't open, print an error:
Serial.println("error opening CB.schem");
}
Serial.println("This should print");
}
void loop() {
Serial.println("hi");
// nothing happens after setup
}
Terminal
Initializing SD card...initialization done.
PCB.txt:
In loop
In loop
In loop
In loop
In loop
In loop
In loop
In loop
In loop
In loop
In loop
In loop
In loop
In loop
In loop
In loop
In loop
In loop
I rejected it cause I didn't see how it would work in an if statement cause it needs to be in a loop, just wanted to see if my solution would work which is why I posted it, still willing to go back to it just trying to come up with my own solution to get a better understanding.
Im a bit confused cause I made the for loop like this
for(String list = myFile.readStringUntil('\n'); list;){
array.push_back(list);
recNum++; // Count the record
Serial.println(recNum);
}
But after 18 its spitting out letters
Initializing SD card...initialization done.
PCB.txt:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
B
C
D
E
F
G
H
I
J
I should get a more powerful Arduino or a different approach? I dont really see another way of approaching this besides an array of strings but if you have an idea please let me know
What behavior? I was simply trying out your way of doing things first by only using readStringUntil because It made more sense to me? I don't understand why your being a jerk