Hello friends , I want to help me to solve a problem that I have , I need my arduino find specific words within a text file on an SD card , that I want to check if a word is in the list of words contains the text, thank you very much for your help.
What do you know about string-searching algorithms? Start with the Wikipedia article and follow links until you get to some code. Then write an Arduino sketch around that code.
MorganS:
What do you know about string-searching algorithms? Start with the Wikipedia article and follow links until you get to some code. Then write an Arduino sketch around that code.
Thank you very much
Nothing really , just looking for a way to libraries SD Arduino and I need to perform , in what way would help me know what you mention me ? if that's what I need I'll do
Check the boyer moore algorithm, - Boyer鈥揗oore string-search algorithm - Wikipedia -
robtillaart:
Check the boyer moore algorithm, - Boyer鈥揗oore string-search algorithm - Wikipedia -
robtillaart:
Check the boyer moore algorithm, - Boyer鈥揗oore string-search algorithm - Wikipedia -
Thank you very very much for help me. ;D
I could do what I wanted , I will continue learning about algorithms because I see very interesting also I like to fill my brain with productive knowledge , I share my sketch so they can see what I needed to do and how it succeeds.
It could also be useful for people who seek the same solution. blessings
//Se incluye la librer铆a <SD.h>
#include <SPI.h>
#include <SD.h>
#include <String.h>
File Archivo;
String readString;
char c;
void setup(){
//Se esablece comunicaci贸n con el monitor serial para la comprobaci贸n de la
//carga de datos.
Serial.begin(9600);
//Se muestra por pantalla que se va a iniciar la comunicaci贸n con la SD
Serial.print("Comenzando la comunicaci贸n con la tarjeta SD");
//Se establece como salida el pin correspondiente a SS.
pinMode(10, OUTPUT);
//Se muestra por el monitor si la comunicaci贸n se ha establecido correctamente
//o ha habido alg煤n tipo de error.
if (!SD.begin(22)){
Serial.println("Se ha producido un fallo al iniciar la comunicaci贸n");
return;
}
Serial.println("Se ha iniciado la comunicaci贸n correctamente");
/* ESCRIBIENDO DATOS EN LA MEMORIA SD DE ARDUINO */
//Se abre el documento sobre el que se va a leer y escribir.
Archivo = SD.open("Test.txt", FILE_WRITE);
//Se comprueba que el archivo se ha abierto correctamente y se procede a
//escribir en 茅l.
if (Archivo){
//Se escribe informaci贸n en el documento de texto Test.txt.
Archivo.println("Esto es lo que se est谩 escribiendo en el archivo");
Archivo.println("de esta forma sabremos si alguna palabra en especial se encuentra dentro de este texto de prueba");
Archivo.println("la palabra a buscar se asignara un poco mas abajo de este codigo");
//Se cierra el archivo para almacenar los datos.
Archivo.close();
//Se muestra por el monitor que los datos se han almacenado correctamente.
Serial.println("Todos los datos fueron almacenados");
}
//En caso de que haya habido problemas abriendo datos.txt, se muestra por pantalla.
else{
Serial.println("El archivo Texto.txt no se abri贸 correctamente");
}
/* FIN DE LA ESCRITURA DE DATOS EN LA MEMORIA SD DE ARDUINO */
/////////////////////////////////////////////////////////////////////////////////////////////////////////
/* LEYENDO DATOS EN LA MEMORIA SD DE ARDUINO */
//Se vuelve a abrir el fichero, esta vez para leer los datos escritos.
Archivo = SD.open("Test.txt");
//Si el archivo se ha abierto correctamente se muestran los datos.
if (Archivo){
//Se muestra por el monitor que la informaci贸n que va a aparecer es la del
//archivo datos.txt.
Serial.println("Informaci贸n contenida en Test.txt:");
//Se implementa un bucle que recorrer谩 el archivo hasta que no encuentre m谩s
//informaci贸n (Archivo.available()==FALSE).
while (Archivo.available()){
c = Archivo.read();
//store characters to string
readString += c;
}
Serial.println(readString);
if (readString.indexOf("especial")>0) { // Puedes cambiar las palabras que sabes que si esta o que no estan en el texto para ver como funciona este sistema
Serial.println("La palabra que buscas si se encuentra en este texto");
pinMode(13, OUTPUT);
digitalWrite(13, HIGH);
delay(3000);
digitalWrite(13, LOW);
}
else{
Serial.println("La palabra que buscas no se encuentra en este texto");
}
//Si todo ha ido bien cierra el archivo para no perder datos.
Archivo.close();
}
//En caso de que haya habido problemas abriendo Test.txt, se muestra por pantalla.
else{
Serial.println("El archivo datos.txt no se abri贸 correctamente");
}
}
void loop()
{
//En este ejemplo el bucle loop() no realiza ninguna acci贸n ya que toda la informaci贸n
//fue gestionada en el setup.
//En caso de que se desee almacenar la informaci贸n obtenida de alg煤n sensor, la escritura
//deber铆a realizarse en el loop().
}
Sorry to put my sketch comments in Spanish but this is my native language
if (readString.indexOf("especial")>0)
if (readString.indexOf('especial')>0)
I do not understand why, but if you put single quote 'especial' the code finds the word in the String.
I don't use String objects and and not familiar with the syntax for the functions. I would have thought that "especial" was correct.
The Spanish comments are no problem, but the lack of [ code ] tags is.
To answer your question where you did use code tags, look at the documentation for String:
Parameters
string: a variable of type String
val: the value to search for - char or String
The value being searched for can be a singe char or it can be a capital-s String. it can't be a lower-case-s string.
I'm not sure why the compiler doesn't complain but 'especial'
in single quotes is only a single char. It is likely to evaluate to just the char 'e', which is why it appears to find the word.
"especial"
with double-quotes is a small-s string, which is not allowed according to the documentation. You could try something like...
String buscar = String("especial");
...
if(readString.indexOf(buscar) > 0) {
...
Thank you very much for guiding me the truth I'm beginner to place code in the forum, know sounds very interesting what to put single quotes and double quotes because it was the first thing that occurred to me lol because it was also the first time to something a little more advanced with Strings, to convince me that actually worked search for the word 'especial' and arduino I indicated that if the word found in the text, then remove the consonant p and look for the word 'esecial' arduino then told me to not find that word .
The text file contains HTML of a page I made for my Arduino Ethernet.
But what you tell me about the single quotes and double quotes is very interesting ;D