Please please advise

Hi ,I am using Sim 800l and a sd card to store phone number i have a sketch that compiles with no errors.
I can see the number in Serial monitor, but i dont get a sms, if i hard code the number in the sketch, i get an sms. any help would be appreciated

.

#include <Sim800l.h>
#include <SoftwareSerial.h> //is necesary for the library!! 
Sim800l Sim800l;  //to declare the library
char* text;
char* number;
bool error; //to catch the response of sendSms


#include <SPI.h>
#include <SD.h>

File myFile;

void setup() {

  Sim800l.begin(); // initializate the library. 
  
  Serial.begin(9600);
  


  Serial.print("Initializing SD card...");

  if (!SD.begin(10)) {
    Serial.println("initialization failed!");
    return;
  }
  Serial.println("initialization done.");

 // re-open the file for reading:
  myFile = SD.open("test.txt");
  

    // read from the file until there's nothing else in it:
    while (myFile.available()) {
      
      Serial.write(myFile.read());
  

    }
    
  
}

void loop() {

 myFile = SD.open("test.txt");
  // read from the file until there's nothing else in it:
    while (myFile.available()) {
  
   text="ivan";  //text for the message. 
   number= myFile.read(); //change to a valid number.
   error=Sim800l.sendSms(number,text);
  Serial.flush();
  
   
delay(5500);
    }
}

Put in some Serial.print() statements so you can see the values that are being retrieved from the SD Card before being used to send the SMS.

My suspicion is that you are only reading a single character from the file and not the entire phone number.

...R

Thanks Robin2. You hit the nail on the head. It only see's the first digit in the loop but it setup it displays the whole number. The question is now why and what am i doing wrong.

Thanks

Ivanfd1:
The question is now why and what am i doing wrong.

The WHY is simple. myFile.read() just gets one charcter.

You need to collect all the characters that make up the number. Without knowing how you have the data in the file I can't give specific advice. Maybe there is a character that identifies the end of the number. Then you could do something like this

const byte maxChars = 16;  // assumes no number will be more than 15 chars change if needed
char number[maxChars];
char endMaarker = '\n'; // set this to match your data
byte numCount;
for (numCount = 0; numCount < maxChars - 1) {
   char nextChar = myFile.read();
   if (nextChar != -1) { // nothing to read gives -1
      if (nextChar == endMarker) {
        break;
      }
      else {
        number[numCount] = nextChar;
      }
   }
}
number[numCount] = '\0' // add the cstring terminator

Serial.println(number); // see what we got

(By the way, not tested so may contain silly errors)

...R

Thank you Robin2, Im using the SDfat libary example Readwite, The example say write " Test,1,2,3", I complied the example then removed the sd card open it on the pc Opened, in notepad, edited to cell number "0123456789"[eg]. I have been searching the forums for a clue, found many trends that leads to dead ends. im going to try you example now, and post replay when finished,
Once thank you for assisting

Regards

Hi Robin2 .I tried your suggestion, the code compiles and on serial monitor i get [0] repeated on every line.

#include <EEPROM.h>

#include <Sim800l.h>
#include <SoftwareSerial.h> //is necesary for the library!! 
Sim800l Sim800l;  //to declare the library
char* text;
char* number;
bool error; //to catch the response of sendSms
int addr = 0;
byte val;
#include <SPI.h>
#include <SD.h>

File myFile;

void setup() {

  Sim800l.begin(); 
   Serial.begin(9600);
 if (!SD.begin(10)) {
 // Serial.println("initialization failed!");
    return;
  }
 myFile = SD.open("Test.TXT");
 while (myFile.available()) {
 Serial.write(myFile.read());
 
   const byte maxChars = 16;  // assumes no number will be more than 15 chars change if needed
    char number[maxChars];
    char endMarker = '\n'; // set this to match your data
    byte numCount;
    for (numCount = 0; numCount < maxChars - 1;) {
    char nextChar = myFile.read();
    if (nextChar != -1) { // nothing to read gives -1
    if (nextChar == endMarker) {
    break;
      }
      else {
        number[numCount] = nextChar;
      }
   }
}
number[numCount] = '\0'; // add the cstring terminator

Serial.println(number); // see what we go
 
 }
 }
 
 

  

 void loop() {
 }

You have put my code inside your WHILE loop which is also reading the data. It's not surprising that it does not work.

And I have no idea what is on the SD Card or whether '\n' is the appropriate end-marker.

...R

hi Robin2, on sd card 1234567899/n file in note pad
thanks

Hi Robin2
changed after that get nothing
any advise
thanks

[code
#include <EEPROM.h>

#include <Sim800l.h>
#include <SoftwareSerial.h> //is necesary for the library!! 
Sim800l Sim800l;  //to declare the library
char* text;
char* number;
bool error; //to catch the response of sendSms
int addr = 0;
byte val;
#include <SPI.h>
#include <SD.h>

File myFile;

void setup() {

  Sim800l.begin(); 
   Serial.begin(9600);
 if (!SD.begin(10)) {
 // Serial.println("initialization failed!");
    return;
  }
 myFile = SD.open("Test.TXT");
 while (myFile.available()) {
// Serial.write(myFile.read());
  }
const byte maxChars = 16;  // assumes no number will be more than 15 chars change if needed
char number[maxChars];
char endMarker = '\n'; // set this to match your data
byte numCount;
for (numCount = 0; numCount < maxChars - 1;) {
   char nextChar = myFile.read();
   if (nextChar != -1) { // nothing to read gives -1
      if (nextChar == endMarker) {
        break;
      }
      else {
        number[numCount] = nextChar;
      }
   }
}
number[numCount] = '\0'; // add the cstring terminator

Serial.println(number); // see what we got


  
 }
  
 void loop() {
 }


]

Try this version. I have marked 2 lines with CHANGED. If you have while(myFile.available() ) but no code in the WHILE loop it will never terminate. If you use the WHILE to read the data in the file you will be at the end of the file before my code gets a look in.

Also note how I have tidied up the layout to make it much easier to see the different blocks of code. Use the AutoFormat tool.

#include <EEPROM.h>

#include <Sim800l.h>
#include <SoftwareSerial.h> //is necesary for the library!!
Sim800l Sim800l;  //to declare the library
char* text;
char* number;
bool error; //to catch the response of sendSms
int addr = 0;
byte val;
#include <SPI.h>
#include <SD.h>

File myFile;

void setup() {

    Sim800l.begin();
    Serial.begin(9600);
     if (!SD.begin(10)) {
        // Serial.println("initialization failed!");
        return;
    }
    myFile = SD.open("Test.TXT");
    // while (myFile.available()) {  // CHANGED
    // Serial.write(myFile.read());
    // }  // CHANGED
    
    const byte maxChars = 16;  // assumes no number will be more than 15 chars change if needed
    char number[maxChars];
    char endMarker = '\n'; // set this to match your data
    byte numCount;
    for (numCount = 0; numCount < maxChars - 1;) {
        char nextChar = myFile.read();
        if (nextChar != -1) { // nothing to read gives -1
            if (nextChar == endMarker) {
                break;
            }
            else {
                number[numCount] = nextChar;
            }
        }
    }
    number[numCount] = '\0'; // add the cstring terminator

    Serial.println(number); // see what we got

 }
 
 void loop() {
 }

...R

Hi Robin2, Sorry for being a pain, This is what i got with my original code see attavment. now reviesed code i get nothing, i copied you code exactly into sketch book.
advice pleace
Thank you

sketch_apr03a.ino (2 Bytes)

Always post the latest version of your program - without that we are blind.

I just noticed that the program in your Original Post uses the SD Card library but the program in your Reply #8 uses the EEPROM library - why the change? The EEPROM library does not work like the SD Card library

This is just an unnecessary confusion when you are trying to sort out a problem.

...R

Hi Robin2 , Sorry, Used the wrong file. I was tested with different libary to see if there is any change from serial monitor. My appoligies

Im going to rectify now/

Thanks

Hi Robin2 The eeprom libary i add to see if i could write the number to eeprom and the use the "eeprom get " to get number to use as the number the gsm uses to send, but then reliased that what is on the monitor is not getting saved any way.

Regards

Hi Robin2, I have tried different ways to try and get your solution to work. May be it the way the number is writen in the file? But then what i dont understand is with original code the number displays on Serial monitor, With your solution i dont get any read out except a ? in Serial monotor. Any advise please

Regards

Ivanfd1:
Hi Robin2, I have tried different ways

There is no point telling me that without also posting the latest versions of the programs that represent the different ways. I can't see your workbench from here.

...R