KEMBAR78
Imprimir Data en SD Arduino | PDF | Computer Hardware | Computer Data
0% found this document useful (0 votes)
17 views3 pages

Imprimir Data en SD Arduino

This document shows how to read and write data to and from an SD card file. It demonstrates opening a file, writing lines of text to it, then reopening and reading the file. It also shows initializing the SD card and errors that could occur.

Uploaded by

pedro nieves
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
17 views3 pages

Imprimir Data en SD Arduino

This document shows how to read and write data to and from an SD card file. It demonstrates opening a file, writing lines of text to it, then reopening and reading the file. It also shows initializing the SD card and errors that could occur.

Uploaded by

pedro nieves
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 3

/*

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>

File myFile;
const int chipSelect = 10;
String mistring;
String imprimir;
char dato[50];
char esp;
int pos;
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(chipSelect)) {
Serial.println("initialization failed!");
return;
}
Serial.println("initialization done.");

// open the file. note that only one file can be open at a time,
// so you have to close this one before opening another.
myFile = SD.open("nuevo.txt", FILE_WRITE);

// if the file opened okay, write to it:


if (myFile) {
Serial.print("Writing to test.txt...");
myFile.println("S12000M3");
myFile.println("G0X98.780Y42.780Z5.000");
myFile.println("G1Z-1.000F200.0");
myFile.println("G1X101.220F600.0");
myFile.println("G1Y44.220");
// close the file:
myFile.close();
Serial.println("done.");
} else {
// if the file didn't open, print an error:
Serial.println("error opening test.txt");
}
pos=0;
// re-open the file for reading:
myFile = SD.open("nuevo.txt", FILE_READ);
if (myFile) {
Serial.println("nuevo.txt:");

// read from the file until there's nothing else in it:


while (myFile.available()) {
int nuevo = myFile.read();
//Serial.write();
//String espw = String(myFile.read());
//
if(nuevo==10){

imprimir = String(dato);
Serial.print(dato);

for(int i=0;i<pos; i++){


dato[i]=NULL;
}
pos=0;
}
dato[pos] = char(nuevo);
//Serial.write(nuevo);
//Serial.println(nuevo);
//byte dato = myFile.peek();
//Serial.println("");
//Serial.println(dato);
//Serial.println(myFile.read());
pos++;
}
// close the file:
myFile.close();
SD.remove("nuevo.txt");
} else {
// if the file didn't open, print an error:
Serial.println("error opening test.txt");
}
}

void loop() {
// nothing happens after setup
}

You might also like