Hi Community,
I am trying to decode the text file in my sd-card. So first 3 bytes should be converted into one hex value and the rest of bytes should be converted into 8 hex values. PLEASE NOTE: the last byte "N" is an error, so dont count it.
/*
SD card read/write
This example shows how to read and write data to and from an SD card file
The circuit:
* 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 Nov 2010
by David A. Mellis
modified 9 Apr 2012
by Tom Igoe
This example code is in the public domain.
*/
#include <SPI.h>
#include <SD.h>
int i ;
File myFile;
void setup() {
// Open serial communications and wait for port to open:
Serial.begin(115200);
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("test2.txt");
i=0;
}
void loop() {
// re-open the file for reading:
if (myFile) {
// read from the file until there's nothing else in it:
if (myFile.available() ) {
String list = myFile.readStringUntil("\n");
Serial.println(list);
}
} else {
// if the file didn't open, print an error:
Serial.println("error opening test.txt");
}
}
Above is my code and attached you can find the captured serial monitor. So the first line
"385100100000255" should be 0x181 and 0x0A 0x00 0x0A 0X00 0x00 0x00 0x00 0xFF.
So I tried to extract the first three bytes :
void loop() {
// re-open the file for reading:
if (myFile) {
// read from the file until there's nothing else in it:
if (myFile.available() ) {
String list = myFile.readStringUntil("\n");
Serial.print(list[0]);
Serial.print(list[1]);
Serial.print(list[2]);
}
But the output is just : 385
Why doesnt this code go through line by line, but stops at the first line ?