Go Down

Topic: Check data from SD card and display it if same (Read 496 times) previous topic - next topic

riandanualdy

i have .csv file or .txt file in SD card and data in .csv file or .txt file is barcode and name of item, example...

12345678     box
23456789     pencil
34567890     pen

if i read the barcode and the output is 23456789, the output in serial monitor is " 23456789 pencil".

can you suggest me, what should i do first and can you give me a reference for the code?

thx

PaulS

Quote
if i read the barcode and the output is 23456789, the output in serial monitor is " 23456789 pencil".
"is" implies that you have some code that produces the desired output. So, what is the problem, and where is the code?
The art of getting good answers lies in asking good questions.

riandanualdy

"is" implies that you have some code that produces the desired output. So, what is the problem, and where is the code?
actually i have a lolo.txt in my sd card
and this is data in lolo.txt...
Code: [Select]

4547648730754  PLC   
4548583108066  HMI   
4548123456789 BOXS 
4546234567790 GALON   
4545345678901 TISSUE 


and i use this code for finding data in lolo.txt
Code: [Select]


/*
 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

created   Nov 2010
by David A. Mellis
modified 9 Apr 2012
by Tom Igoe

This example code is in the public domain.
   
*/

#include <SD.h>

File myFile;
char buf[20]; //tergantung lebar datanya   

void setup()
{
// Open serial communications and wait for port to open:
 Serial.begin(9600);
   pinMode(10,OUTPUT);
  pinMode(4,OUTPUT);
  digitalWrite(10,HIGH);
  digitalWrite(4,LOW);
  while (!Serial) {
   ; // wait for serial port to connect. Needed for Leonardo only
 }


 Serial.print("Initializing SD card...");
 // On the Ethernet Shield, CS is pin 4. It's set as an output by default.
 // Note that even if it's not used as the CS pin, the hardware SS pin
 // (10 on most Arduino boards, 53 on the Mega) must be left as an output
 // or the SD library functions will not work.
  pinMode(10, OUTPUT);
 
 if (!SD.begin(4)) {
   Serial.println("initialization failed!");
   return;
 }
 Serial.println("initialization done."); 
   
 // re-open the file for reading:
 myFile = SD.open("lolo.txt");
 if (myFile) {
   Serial.println("lolo.txt:");
   
   // read from the file until there's nothing else in it:
   
   while (myFile.available()) {
       myFile.read(buf,20); //tergantung lebar datanya       
       if(strncmp(buf,"4546",4)==0)
       {
          for (int i = 0; i < 20; i = i + 1) {
  Serial.print(buf[i]);     
       }
   
break;
       }
   }
   // close the file:
   myFile.close();
 } else {
  // if the file didn't open, print an error:
   Serial.println("error opening test.txt");
 }
}

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


but if i change "4546" to 4545 for finding 4545345678901 TISSUE cant display to serial monitor
but if i change to the others, display can output the number and the item like PLC,HMI and the others

George_Cs

This is not an SD card-related problem at all..
If you use a 20 char length buffer, you should set all database entry to 20 char too; you must correct the length of the items.

riandanualdy

This is not an SD card-related problem at all..
If you use a 20 char length buffer, you should set all database entry to 20 char too; you must correct the length of the items.
i try to change size buffer from 20 to 25 but still the output can't get the TISSUE item

Go Up